mirror of
https://github.com/imfing/hextra.git
synced 2025-05-14 13:46:26 -04:00
Compare commits
6 Commits
9d350812f2
...
d129f7caca
Author | SHA1 | Date | |
---|---|---|---|
![]() |
d129f7caca | ||
![]() |
bc778ee243 | ||
![]() |
06eb8a66a1 | ||
![]() |
081ad8b84f | ||
![]() |
7593ef4ae4 | ||
![]() |
b70d729283 |
@ -1,8 +1,43 @@
|
|||||||
document.addEventListener("DOMContentLoaded", function () {
|
document.addEventListener("DOMContentLoaded", function () {
|
||||||
scrollToActiveItem();
|
initializeSidebar();
|
||||||
enableCollapsibles();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function initializeSidebar() {
|
||||||
|
const sidebarScrollbar = document.querySelector("aside.sidebar-container > .hextra-scrollbar");
|
||||||
|
if (!sidebarScrollbar) return;
|
||||||
|
|
||||||
|
enableCollapsibles();
|
||||||
|
restoreSidebarPosition(sidebarScrollbar);
|
||||||
|
|
||||||
|
const debouncedSave = debounce((position) => {
|
||||||
|
saveSidebarPosition(position);
|
||||||
|
}, 150);
|
||||||
|
|
||||||
|
sidebarScrollbar.addEventListener('scroll', function() {
|
||||||
|
debouncedSave(this.scrollTop);
|
||||||
|
});
|
||||||
|
|
||||||
|
document.querySelectorAll('a').forEach(link => {
|
||||||
|
if (link.hostname === window.location.hostname) {
|
||||||
|
link.addEventListener('click', function(e) {
|
||||||
|
saveSidebarPosition(sidebarScrollbar.scrollTop);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function debounce(func, wait) {
|
||||||
|
let timeout;
|
||||||
|
return function executedFunction(...args) {
|
||||||
|
const later = () => {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
func(...args);
|
||||||
|
};
|
||||||
|
clearTimeout(timeout);
|
||||||
|
timeout = setTimeout(later, wait);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function enableCollapsibles() {
|
function enableCollapsibles() {
|
||||||
const buttons = document.querySelectorAll(".hextra-sidebar-collapsible-button");
|
const buttons = document.querySelectorAll(".hextra-sidebar-collapsible-button");
|
||||||
buttons.forEach(function (button) {
|
buttons.forEach(function (button) {
|
||||||
@ -16,21 +51,16 @@ function enableCollapsibles() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function scrollToActiveItem() {
|
function saveSidebarPosition(scrollPosition) {
|
||||||
const sidebarScrollbar = document.querySelector("aside.sidebar-container > .hextra-scrollbar");
|
localStorage.setItem('sidebarScrollPosition', scrollPosition);
|
||||||
const activeItems = document.querySelectorAll(".sidebar-active-item");
|
}
|
||||||
const visibleActiveItem = Array.from(activeItems).find(function (activeItem) {
|
|
||||||
return activeItem.getBoundingClientRect().height > 0;
|
function restoreSidebarPosition(sidebarScrollbar) {
|
||||||
});
|
const savedPosition = localStorage.getItem('sidebarScrollPosition');
|
||||||
|
|
||||||
if (!visibleActiveItem) {
|
if (savedPosition !== null) {
|
||||||
return;
|
requestAnimationFrame(() => {
|
||||||
}
|
sidebarScrollbar.scrollTop = parseInt(savedPosition);
|
||||||
|
});
|
||||||
const yOffset = visibleActiveItem.clientHeight;
|
}
|
||||||
const yDistance = visibleActiveItem.getBoundingClientRect().top - sidebarScrollbar.getBoundingClientRect().top;
|
|
||||||
sidebarScrollbar.scrollTo({
|
|
||||||
behavior: "instant",
|
|
||||||
top: yDistance - yOffset
|
|
||||||
});
|
|
||||||
}
|
}
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
|
|
||||||
<footer class="hextra-footer hx-bg-gray-100 hx-pb-[env(safe-area-inset-bottom)] dark:hx-bg-neutral-900 print:hx-bg-transparent">
|
<footer class="hextra-footer hx-bg-gray-100 hx-pb-[env(safe-area-inset-bottom)] dark:hx-bg-neutral-900 print:hx-bg-transparent">
|
||||||
{{- if $enableFooterSwitches -}}
|
{{- if and $enableFooterSwitches (or hugo.IsMultilingual $displayThemeToggle) -}}
|
||||||
<div class="hx-mx-auto hx-flex hx-gap-2 hx-py-2 hx-px-4 {{ $footerWidth }}">
|
<div class="hx-mx-auto hx-flex hx-gap-2 hx-py-2 hx-px-4 {{ $footerWidth }}">
|
||||||
{{- partial "language-switch.html" (dict "context" .) -}}
|
{{- partial "language-switch.html" (dict "context" .) -}}
|
||||||
{{- with $displayThemeToggle }}{{ partial "theme-toggle.html" }}{{ end -}}
|
{{- with $displayThemeToggle }}{{ partial "theme-toggle.html" }}{{ end -}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user