Compare commits
2 Commits
dbd1e14e4e
...
5b615a6999
| Author | SHA1 | Date | |
|---|---|---|---|
| 5b615a6999 | |||
| 99cf0947da |
@@ -1478,6 +1478,33 @@ const WHOAMI_FORCE_LOCALHOST = (import.meta.env.PUBLIC_WHOAMI_FORCE_LOCALHOST ??
|
||||
|
||||
const h1 = reading.querySelector("h1");
|
||||
|
||||
const topChapterLabel =
|
||||
isGlossaryEntryMode
|
||||
? "Haut de la fiche"
|
||||
: isGlossaryEdition
|
||||
? "Haut de la page"
|
||||
: "Haut du chapitre";
|
||||
|
||||
if (btnTopChapter) {
|
||||
btnTopChapter.setAttribute("aria-label", topChapterLabel);
|
||||
btnTopChapter.setAttribute("title", topChapterLabel);
|
||||
}
|
||||
|
||||
function scrollToTopChapter(behavior = "smooth") {
|
||||
if (isGlossaryEdition) {
|
||||
window.scrollTo({ top: 0, behavior });
|
||||
return;
|
||||
}
|
||||
|
||||
if (h1) {
|
||||
scrollToElWithOffset(h1, 12, behavior);
|
||||
}
|
||||
}
|
||||
|
||||
function getH2ScrollTarget(item) {
|
||||
return item?.h2 || item?.anchor || item?.marker || null;
|
||||
}
|
||||
|
||||
const h2Anchors = Array.from(reading.querySelectorAll(".details-anchor[id]"))
|
||||
.map((s) => {
|
||||
const d = (s.nextElementSibling && s.nextElementSibling.tagName === "DETAILS")
|
||||
@@ -1701,7 +1728,12 @@ const WHOAMI_FORCE_LOCALHOST = (import.meta.env.PUBLIC_WHOAMI_FORCE_LOCALHOST ??
|
||||
syncGlossaryFollowState(followEl.classList.contains("is-on") && followH > 0);
|
||||
|
||||
if (btnTopChapter) {
|
||||
btnTopChapter.hidden = !(rfH1 && !rfH1.hidden);
|
||||
const showTopChapter =
|
||||
isGlossaryEdition
|
||||
? Boolean(followEl.classList.contains("is-on"))
|
||||
: Boolean(rfH1 && !rfH1.hidden);
|
||||
|
||||
btnTopChapter.hidden = !showTopChapter;
|
||||
}
|
||||
|
||||
if (btnTopSection) {
|
||||
@@ -1737,8 +1769,11 @@ const WHOAMI_FORCE_LOCALHOST = (import.meta.env.PUBLIC_WHOAMI_FORCE_LOCALHOST ??
|
||||
if (rfH2) {
|
||||
rfH2.addEventListener("click", () => {
|
||||
if (!curH2) return;
|
||||
openDetailsIfNeeded(curH2.anchor || curH2.h2 || curH2.marker);
|
||||
scrollToElWithOffset(curH2.marker, 12, "smooth");
|
||||
const target = getH2ScrollTarget(curH2);
|
||||
if (!target) return;
|
||||
|
||||
openDetailsIfNeeded(target);
|
||||
scrollToElWithOffset(target, 12, "smooth");
|
||||
history.replaceState(null, "", `${window.location.pathname}#${curH2.id}`);
|
||||
});
|
||||
}
|
||||
@@ -1754,15 +1789,18 @@ const WHOAMI_FORCE_LOCALHOST = (import.meta.env.PUBLIC_WHOAMI_FORCE_LOCALHOST ??
|
||||
|
||||
if (btnTopChapter) {
|
||||
btnTopChapter.addEventListener("click", () => {
|
||||
if (h1) scrollToElWithOffset(h1, 12, "smooth");
|
||||
scrollToTopChapter("smooth");
|
||||
});
|
||||
}
|
||||
|
||||
if (btnTopSection) {
|
||||
btnTopSection.addEventListener("click", () => {
|
||||
if (!curH2) return;
|
||||
openDetailsIfNeeded(curH2.anchor || curH2.h2 || curH2.marker);
|
||||
scrollToElWithOffset(curH2.marker, 12, "smooth");
|
||||
const target = getH2ScrollTarget(curH2);
|
||||
if (!target) return;
|
||||
|
||||
openDetailsIfNeeded(target);
|
||||
scrollToElWithOffset(target, 12, "smooth");
|
||||
history.replaceState(null, "", `${window.location.pathname}#${curH2.id}`);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user