diff --git a/public/noscript.css b/public/noscript.css index 8b24e2a..31f3090 100644 --- a/public/noscript.css +++ b/public/noscript.css @@ -15,3 +15,12 @@ div.pager { .savecomment input[type=file] { display: inline-block; } +#sidetoggle button { + visibility: unset !important; +} +#sidetoggle button::before { + content: "" !important; +} +#sidetoggle { + bottom: 4px; +} diff --git a/public/style.css b/public/style.css index 25c7730..021fcbe 100644 --- a/public/style.css +++ b/public/style.css @@ -509,6 +509,9 @@ form.blockpost { .hidechildren span { pointer-events: none; } +.hide { + display: none !important; +} .expando { display: none; max-width: 900px; @@ -607,8 +610,36 @@ form.blockpost { white-space: nowrap; } -#sideToggle { - text-align: right; +#sidetoggle button::before { + content: '[+]'; + visibility: visible; + cursor: pointer; + position: relative; + top: 12px; +} +#sidetoggle.o button::before { + content: '[-]'; + visibility: visible; + cursor: pointer; + position: relative; + top: 12px; +} +#sidetoggle button { + visibility: hidden; + width: 10px; + margin-right: 16px; + background: unset; + border: unset; +} +#sidetoggle { + position: absolute; + cursor: pointer; + right: 0; + display: inline-flex; + align-items: end; + height: 20px; + font-size: 12px; + cursor: pointer; } .side { display: none; @@ -625,7 +656,22 @@ main { position: relative; margin: 0px 10px; } +.wide .side { + display: block !important; +} @media (min-width: 900px) { + .wide { + padding-right: 15px; + } + .wide .side { + display: none !important; + } + #sidetoggle button::before { + content: '[-]'; + } + #sidetoggle.o button::before { + content: '[+]'; + } .expando { text-align: left; } @@ -810,7 +856,7 @@ nav .host { } nav div.spacer { - height: 32px; + height: 34px; position: relative; } nav span.spacer { diff --git a/public/utils.js b/public/utils.js index c82db03..0b70ca8 100644 --- a/public/utils.js +++ b/public/utils.js @@ -513,6 +513,38 @@ function setup() { links[i].addEventListener("click", xhrLink) } } + var st = document.getElementById("sidetoggle") + if (st) { + st.addEventListener("click", sideToggle) + } +} +function sideToggle(e) { + e.preventDefault(); + var side = document.getElementsByClassName("side")[0] + var main = document.getElementsByTagName("main")[0] + if (!side) return; + var form = e.target + if (form.tagName != "FORM") { + form = uptil(e.target, function(el){ return el.tagName == "FORM" }) + } + var data = new FormData(form) + data.append("xhr", "1") + request(form.target, data) +console.log(e) + if (side.className == "side") { + side.className = "side hide" + form.classList.add("o") + if (main) { + main.className = "wide" + } + } else { + side.className = "side" + form.classList.remove("o") + if (main) { + main.className = "" + } + } + } function xhrLink(e) { e = e || window.event; diff --git a/routes.go b/routes.go index 1dfaca9..6a9900c 100644 --- a/routes.go +++ b/routes.go @@ -323,6 +323,9 @@ func Initialize(Host string, r *http.Request) (State, error) { state.Listing = getCookie(r, "DefaultListingType") state.Sort = getCookie(r, "DefaultSortType") state.CommentSort = getCookie(r, "DefaultCommentSortType") + if hideSidebar := getCookie(r, "HideSidebar"); hideSidebar == "1" { + state.HideSidebar = true + } if dark := getCookie(r, "Dark"); dark != "" { state.Dark = new(bool) *state.Dark = dark != "0" @@ -492,7 +495,7 @@ func GetIcon(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { } u := resp.SiteView.Site.Icon.String() if pictrs.MatchString(u) { - u += "?format=jpg&thumbnail=60" + u += "?format=png&thumbnail=60" } iresp, err := state.HTTPClient.Get(u) if err != nil { @@ -1073,6 +1076,15 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { w.Write([]byte{}) return } + case "sidetoggle": + if state.HideSidebar { + deleteCookie(w, state.Host, "HideSidebar") + } else { + setCookie(w, state.Host, "HideSidebar", "1") + } + if r.FormValue("xhr") != "" { + return + } case "logout": deleteCookie(w, state.Host, "jwt") deleteCookie(w, state.Host, "user") diff --git a/state.go b/state.go index fd2bdc1..68f1b8c 100644 --- a/state.go +++ b/state.go @@ -106,6 +106,7 @@ type State struct { ShowNSFW bool HideInstanceNames bool HideThumbnails bool + HideSidebar bool LinksInNewWindow bool SubmitURL string SubmitTitle string diff --git a/templates/frontpage.html b/templates/frontpage.html index 5797cda..a2729f5 100644 --- a/templates/frontpage.html +++ b/templates/frontpage.html @@ -16,7 +16,8 @@ {{- if and (not .ShowNSFW) .Community .Community.CommunityView.Community.NSFW }} {{ template "nsfw.html" }} {{- else }} -
+ + {{ template "sidebar.html" . }} {{- if and (not .Community) .Tagline }}

{{ markdown .Host .Tagline }} @@ -46,7 +47,6 @@ {{ end }} - {{ template "sidebar.html" . }}

{{ end }} diff --git a/templates/main.html b/templates/main.html index 8774116..967e21b 100644 --- a/templates/main.html +++ b/templates/main.html @@ -16,7 +16,8 @@ {{- if and (not .ShowNSFW) .Community .Community.CommunityView.Community.NSFW }} {{ template "nsfw.html" }} {{- else }} -
+ + {{- template "sidebar.html" . }} {{- if or (.Query) (.SearchType) (and (not .PostID) (not .User) (not .Activities) (eq .Op ""))}} {{ template "menu.html" . }} {{- end}} @@ -137,7 +138,6 @@ {{- if .Watch }} {{- end }} - {{- template "sidebar.html" . }}
{{- end }} diff --git a/templates/nav.html b/templates/nav.html index 41177e7..408ea73 100644 --- a/templates/nav.html +++ b/templates/nav.html @@ -87,6 +87,10 @@ {{- if and .PostID }}{{ $post := (index .Posts 0) }}{{ if $post.CrossPosts }}
  • other discussions ({{ $post.CrossPosts }})
  • {{- end }}{{ end }} + {{- end }} diff --git a/templates/sidebar.html b/templates/sidebar.html index e415f57..930e2a1 100644 --- a/templates/sidebar.html +++ b/templates/sidebar.html @@ -1,5 +1,5 @@ {{- $host := .Host }} -
    +
    {{- if eq .Listing "Local" }}