BlueGit

timfa 66wiki

fix slinks in detail pages

timfa Tim · pushed by timfa

Authored 2025-12-20 · 11 months ago

Hash
fcd8e9d200380836953a7730eedad5125cea70d8
Parent
eeea1289
1 file changed +31 −28
web/chapterScroll.js +31 −28
@@ -3,39 +3,42 @@
3 3 const btn = document.getElementById('chapterMenuBtn');
4 4 const dropdown = document.getElementById('chapterDropdown');
5 5
6 function closeDropdown ()
6 if (btn && dropdown)
7 7 {
8 dropdown.classList.remove('open');
9 btn.setAttribute('aria-expanded', 'false');
10 }
11
12 btn.addEventListener('click', () =>
13 {
14 const isOpen = dropdown.classList.toggle('open');
15 btn.setAttribute('aria-expanded', isOpen ? 'true' : 'false');
16 });
8 function closeDropdown ()
9 {
10 dropdown.classList.remove('open');
11 btn.setAttribute('aria-expanded', 'false');
12 }
17 13
18 // Click outside closes it
19 document.addEventListener('click', (e) =>
20 {
21 if (!e.target.closest('.chapterPicker')) closeDropdown();
22 });
14 btn.addEventListener('click', () =>
15 {
16 const isOpen = dropdown.classList.toggle('open');
17 btn.setAttribute('aria-expanded', isOpen ? 'true' : 'false');
18 });
23 19
24 // Smooth scroll when selecting a chapter
25 dropdown.addEventListener('click', (e) =>
26 {
27 const target = e.target.closest('button[data-target]');
28 if (!target) return;
20 // Click outside closes it
21 document.addEventListener('click', (e) =>
22 {
23 if (!e.target.closest('.chapterPicker')) closeDropdown();
24 });
29 25
30 const id = target.getAttribute('data-target');
31 const el = document.getElementById(id);
32 if (el)
26 // Smooth scroll when selecting a chapter
27 dropdown.addEventListener('click', (e) =>
33 28 {
34 el.scrollIntoView({ behavior: 'smooth', block: 'start' });
35 closeDropdown();
36 history.replaceState(null, '', '#' + id); // optional: update URL fragment
37 }
38 });
29 const target = e.target.closest('button[data-target]');
30 if (!target) return;
31
32 const id = target.getAttribute('data-target');
33 const el = document.getElementById(id);
34 if (el)
35 {
36 el.scrollIntoView({ behavior: 'smooth', block: 'start' });
37 closeDropdown();
38 history.replaceState(null, '', '#' + id); // optional: update URL fragment
39 }
40 });
41 }
39 42
40 43 const scrollLinks = document.getElementsByClassName('scrollLink');
41 44 for (let i = 0; i < scrollLinks.length; i++)
@@ -3,39 +3,42 @@
3 const btn = document.getElementById('chapterMenuBtn');
3 const btn = document.getElementById('chapterMenuBtn');
4 const dropdown = document.getElementById('chapterDropdown');
4 const dropdown = document.getElementById('chapterDropdown');
5
5
6 function closeDropdown ()
6 if (btn && dropdown)
7 {
7 {
8 dropdown.classList.remove('open');
8 function closeDropdown ()
9 btn.setAttribute('aria-expanded', 'false');
9 {
10 }
10 dropdown.classList.remove('open');
11
11 btn.setAttribute('aria-expanded', 'false');
12 btn.addEventListener('click', () =>
12 }
13 {
14 const isOpen = dropdown.classList.toggle('open');
15 btn.setAttribute('aria-expanded', isOpen ? 'true' : 'false');
16 });
17
13
18 // Click outside closes it
14 btn.addEventListener('click', () =>
19 document.addEventListener('click', (e) =>
15 {
20 {
16 const isOpen = dropdown.classList.toggle('open');
21 if (!e.target.closest('.chapterPicker')) closeDropdown();
17 btn.setAttribute('aria-expanded', isOpen ? 'true' : 'false');
22 });
18 });
23
19
24 // Smooth scroll when selecting a chapter
20 // Click outside closes it
25 dropdown.addEventListener('click', (e) =>
21 document.addEventListener('click', (e) =>
26 {
22 {
27 const target = e.target.closest('button[data-target]');
23 if (!e.target.closest('.chapterPicker')) closeDropdown();
28 if (!target) return;
24 });
29
25
30 const id = target.getAttribute('data-target');
26 // Smooth scroll when selecting a chapter
31 const el = document.getElementById(id);
27 dropdown.addEventListener('click', (e) =>
32 if (el)
33 {
28 {
34 el.scrollIntoView({ behavior: 'smooth', block: 'start' });
29 const target = e.target.closest('button[data-target]');
35 closeDropdown();
30 if (!target) return;
36 history.replaceState(null, '', '#' + id); // optional: update URL fragment
31
37 }
32 const id = target.getAttribute('data-target');
38 });
33 const el = document.getElementById(id);
34 if (el)
35 {
36 el.scrollIntoView({ behavior: 'smooth', block: 'start' });
37 closeDropdown();
38 history.replaceState(null, '', '#' + id); // optional: update URL fragment
39 }
40 });
41 }
39
42
40 const scrollLinks = document.getElementsByClassName('scrollLink');
43 const scrollLinks = document.getElementsByClassName('scrollLink');
41 for (let i = 0; i < scrollLinks.length; i++)
44 for (let i = 0; i < scrollLinks.length; i++)