-
Notifications
You must be signed in to change notification settings - Fork 183
feat(ux): add resizable side panels with local storage preference #1053
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,62 @@ | ||||||
|
|
||||||
| document.addEventListener("DOMContentLoaded", function () { | ||||||
| const resizer = document.getElementById("left-resizer"); | ||||||
| const sidebar = document.getElementById("left-sidebar"); | ||||||
|
|
||||||
| if (!resizer || !sidebar) return; | ||||||
| if (window.innerWidth < 768) return; | ||||||
|
|
||||||
|
|
||||||
| let isResizing = false; | ||||||
|
|
||||||
|
|
||||||
| const savedWidth = localStorage.getItem("leftSidebarWidth"); | ||||||
| if (savedWidth) { | ||||||
| sidebar.style.width = savedWidth; | ||||||
| sidebar.style.flex = "none"; | ||||||
| sidebar.style.maxWidth = "35vw"; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
| } | ||||||
|
|
||||||
|
|
||||||
| resizer.addEventListener("mousedown", function (e) { | ||||||
| isResizing = true; | ||||||
| document.body.style.cursor = "col-resize"; | ||||||
| document.body.style.userSelect = "none"; | ||||||
| }); | ||||||
|
|
||||||
|
|
||||||
| document.addEventListener("mousemove", function (e) { | ||||||
| if (!isResizing) return; | ||||||
|
|
||||||
|
|
||||||
| const newWidth = e.clientX + "px"; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The width calculation using
Suggested change
|
||||||
| sidebar.style.width = newWidth; | ||||||
| sidebar.style.flex = "none"; // Override bootstrap grid flex | ||||||
| }); | ||||||
|
|
||||||
|
|
||||||
| document.addEventListener("mouseup", function () { | ||||||
| if (isResizing) { | ||||||
| isResizing = false; | ||||||
| document.body.style.cursor = ""; | ||||||
| document.body.style.userSelect = ""; | ||||||
|
|
||||||
| // Save the final width | ||||||
| localStorage.setItem("leftSidebarWidth", sidebar.style.width); | ||||||
| } | ||||||
| }); | ||||||
|
|
||||||
|
|
||||||
| resizer.addEventListener("dblclick", function () { | ||||||
| sidebar.classList.add("is-resetting"); // Add transition class | ||||||
|
|
||||||
| sidebar.style.width = ""; | ||||||
| sidebar.style.flex = ""; | ||||||
| localStorage.removeItem("leftSidebarWidth"); | ||||||
|
|
||||||
|
|
||||||
| setTimeout(() => sidebar.classList.remove("is-resetting"), 300); | ||||||
| }); | ||||||
|
|
||||||
| }); | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,8 +10,10 @@ | |
| <div class="container-fluid td-outer"> | ||
| <div class="td-main"> | ||
| <div class="row flex-xl-nowrap"> | ||
| <aside class="col-12 col-md-3 col-xl-2 td-sidebar d-print-none"> | ||
| <aside class="col-12 col-md-3 col-xl-2 td-sidebar d-print-none" id="left-sidebar"> | ||
| {{ partial "sidebar.html" . }} | ||
| <!-- Add the resizer handle here! --> | ||
| <div class="sidebar-resizer" id="left-resizer"></div> | ||
| </aside> | ||
| <aside class="d-none d-xl-block col-xl-2 td-sidebar-toc d-print-none"> | ||
| {{ partial "page-meta-links.html" . }} | ||
|
|
@@ -38,6 +40,13 @@ | |
| </div> | ||
| {{ partial "scripts.html" . }} | ||
| {{ partial "image-modal.html" . }} | ||
|
|
||
| {{ with resources.Get "js/sidebar-resizer.js" }} | ||
| <script src="{{ .RelPermalink }}" defer></script> | ||
| {{ end }} | ||
| </body> | ||
|
|
||
|
Comment on lines
+47
to
+48
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| </body> | ||
|
|
||
|
|
||
| </html> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Directly accessing
localStoragecan throw aSecurityErrorin certain browser configurations (e.g., private browsing mode, blocked cookies, or specific security policies). It is recommended to wrap these calls in atry...catchblock or check for availability to prevent the script from crashing.