From 253469fe6d77bc3fa2145e40f4186b6be1310f40 Mon Sep 17 00:00:00 2001 From: Ryan Stafford Date: Fri, 21 Jun 2024 17:21:42 -0400 Subject: [PATCH] collapse inline media setting --- public/dark.css | 3 +++ public/style.css | 32 +++++++++++++++++++++++++++----- public/utils.js | 10 ++++++++++ routes.go | 16 ++++++++++++++++ state.go | 1 + templates/comment.html | 8 ++++++-- templates/post.html | 20 +++++++++++++------- templates/settings.html | 6 ++++++ 8 files changed, 82 insertions(+), 14 deletions(-) diff --git a/public/dark.css b/public/dark.css index 100f070..b80590a 100644 --- a/public/dark.css +++ b/public/dark.css @@ -77,6 +77,9 @@ input[type=text], input[type=password], textarea { color: #ddd; border-color: #666; } +.expando > div > details { + color: white; +} .side .stats { background-color: #393939; border-color: #666; diff --git a/public/style.css b/public/style.css index db495c3..0fe1509 100644 --- a/public/style.css +++ b/public/style.css @@ -83,6 +83,12 @@ summary { .expando > div { text-align: center; } +.comment .content details img { + display: none; +} +.comment .content details[open] img { + display: unset; +} .comment.hidden { padding-bottom:5px; padding-left: 4px; @@ -526,7 +532,7 @@ form.blockpost { cursor: pointer; float:left; } -.expando-button::before{ +.expando-button::before,.collapse .expando-button::before{ content: "+"; float: left; position: relative; @@ -534,11 +540,17 @@ form.blockpost { font-size: 12px; left: 12px; top: 7px; + line-height: normal; + font-weight: normal; + font-family: unset; } -.open.expando-button { +.open.expando-button, .collapse .open.expando-button { border-radius: 30px; } -.open.expando-button::before { +.collapse .expando-button { + border-radius: 4px; +} +.open.expando-button::before, .collapse .open.expando-button::before { content: "✖"; color: #fff; font-weight: bold; @@ -614,10 +626,16 @@ form.blockpost { #settingspopup.open, #mycommunities.open { display: inline-block; } -.expando.open{ +.expando.open, .collapse .expando.text{ display: block; clear: left; } +.collapse .expando .image { + display: none; +} +.collapse .expando.open .image { + display: block; +} .expando .image { max-width: 100%; cursor: nwse-resize; @@ -735,7 +753,11 @@ main { } } @media (min-width: 800px) { - .expando .thumb, .expando .score, .expando .rank { + .collapse .open.expando .thumb, .collapse .open.expando .score, .collapse .open.expando .rank { + display: none; + } + .collapse.post .text.expando .thumb, .collapse.post .text.expando .score, .collapse.post .text.expando .rank, + .post .expando.open .thumb, .post .expando.open .score, .post .expando.open .rank { display: block; } .expando .image { diff --git a/public/utils.js b/public/utils.js index 561e9a8..5d7fb39 100644 --- a/public/utils.js +++ b/public/utils.js @@ -521,6 +521,16 @@ function setup() { if (st) { st.addEventListener("click", sideToggle) } +var collapseMedia = document.querySelectorAll(".content summary a, .expando > div > details summary a") + for (var i = 0; i < collapseMedia.length; i++) { + collapseMedia[i].onclick = toggleDetails + } +} +function toggleDetails(e) { + if (e.target.parentNode.tagName == 'SUMMARY') { + e.target.parentNode.click(); + } + return false } function sideToggle(e) { e.preventDefault(); diff --git a/routes.go b/routes.go index 7d4ddb8..df11f2b 100644 --- a/routes.go +++ b/routes.go @@ -190,6 +190,10 @@ var funcMap = template.FuncMap{ body = RegReplace(body, `::: ?spoiler (.*?)\n([\S\s]*?):::`, "
$1$2
") return template.HTML(body) }, + "collapsemedia": func(h template.HTML) template.HTML { + body := string(h) + return template.HTML(RegReplace(body, ``, `
collapsed inline media
`)) + }, "rmmarkdown": func(body string) string { var buf bytes.Buffer if err := md.Convert([]byte(body), &buf); err != nil { @@ -328,6 +332,11 @@ func Initialize(Host string, r *http.Request) (State, error) { } else { state.HideThumbnails = os.Getenv("HIDE_THUMBNAILS") != "" } + if collapse := getCookie(r, "CollapseMedia"); collapse != "" { + state.CollapseMedia = collapse != "0" + } else { + state.CollapseMedia = os.Getenv("COLLAPSE_MEDIA") != "" + } state.ParseQuery(r.URL.RawQuery) if state.Sort == "" { state.Sort = getenv("SORT", "Hot") @@ -849,6 +858,13 @@ func Settings(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { setCookie(w, "", "HideThumbnails", "0") state.HideInstanceNames = false } + if r.FormValue("collapseMedia") != "" { + setCookie(w, "", "CollapseMedia", "1") + state.CollapseMedia = true + } else { + setCookie(w, "", "CollapseMedia", "0") + state.CollapseMedia = false + } if r.FormValue("linksInNewWindow") != "" { setCookie(w, "", "LinksInNewWindow", "1") state.LinksInNewWindow = true diff --git a/state.go b/state.go index 68f1b8c..d612230 100644 --- a/state.go +++ b/state.go @@ -107,6 +107,7 @@ type State struct { HideInstanceNames bool HideThumbnails bool HideSidebar bool + CollapseMedia bool LinksInNewWindow bool SubmitURL string SubmitTitle string diff --git a/templates/comment.html b/templates/comment.html index b7d4ea8..1c2f6bd 100644 --- a/templates/comment.html +++ b/templates/comment.html @@ -1,4 +1,4 @@ -
+
{{- if .State.Session }}