Compare commits
2 Commits
6f6f6f75ff
...
2a75dd5d00
| Author | SHA1 | Date | |
|---|---|---|---|
| 2a75dd5d00 | |||
| 8cbf873df0 |
|
|
@ -2,6 +2,25 @@ export default function observeChapterProgression() {
|
||||||
const hasChapterIndex = document.querySelector('.chapter_index__list');
|
const hasChapterIndex = document.querySelector('.chapter_index__list');
|
||||||
if (!hasChapterIndex) return;
|
if (!hasChapterIndex) return;
|
||||||
|
|
||||||
|
// Debug function to visualize rootMargin
|
||||||
|
// function createDebugOverlay() {
|
||||||
|
// const overlay = document.createElement('div');
|
||||||
|
// overlay.style.position = 'fixed';
|
||||||
|
// overlay.style.top = '10%';
|
||||||
|
// overlay.style.bottom = '70%';
|
||||||
|
// overlay.style.left = '0';
|
||||||
|
// overlay.style.right = '0';
|
||||||
|
// overlay.style.border = '2px solid red';
|
||||||
|
// overlay.style.pointerEvents = 'none';
|
||||||
|
// overlay.style.zIndex = '9999';
|
||||||
|
// overlay.style.opacity = '0.3';
|
||||||
|
// overlay.style.backgroundColor = 'rgba(255, 0, 0, 0.1)';
|
||||||
|
// document.body.appendChild(overlay);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Uncomment the line below to see the detection zone
|
||||||
|
// createDebugOverlay();
|
||||||
|
|
||||||
function handleLinkScrollToTarget(e) {
|
function handleLinkScrollToTarget(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
let target = e.target.getAttribute('href');
|
let target = e.target.getAttribute('href');
|
||||||
|
|
@ -21,12 +40,22 @@ export default function observeChapterProgression() {
|
||||||
chapterIndicator.style.height = targetHeight + 'px';
|
chapterIndicator.style.height = targetHeight + 'px';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleSetLinkActive(targetLink) {
|
||||||
|
const allLinks = document.querySelectorAll('.chapter_index__link');
|
||||||
|
allLinks.forEach((link) => {
|
||||||
|
link.classList.remove('active');
|
||||||
|
});
|
||||||
|
|
||||||
|
// targetLink.classList.add('active');
|
||||||
|
}
|
||||||
|
|
||||||
let chapterLinks = document.querySelectorAll('.chapter_index__link');
|
let chapterLinks = document.querySelectorAll('.chapter_index__link');
|
||||||
|
|
||||||
chapterLinks.forEach((link) => {
|
chapterLinks.forEach((link) => {
|
||||||
link.addEventListener('click', (e) => {
|
link.addEventListener('click', (e) => {
|
||||||
handleLinkScrollToTarget(e);
|
handleLinkScrollToTarget(e);
|
||||||
handleChapterIndicatorPosition(e.target.offsetTop);
|
handleChapterIndicatorPosition(e.target);
|
||||||
|
handleSetLinkActive(e.target);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -41,6 +70,7 @@ export default function observeChapterProgression() {
|
||||||
if (entry.isIntersecting) {
|
if (entry.isIntersecting) {
|
||||||
// Add 'active' class if observation target is inside viewport
|
// Add 'active' class if observation target is inside viewport
|
||||||
handleChapterIndicatorPosition(relatedChapterLink);
|
handleChapterIndicatorPosition(relatedChapterLink);
|
||||||
|
|
||||||
entry.target.classList.add('active');
|
entry.target.classList.add('active');
|
||||||
relatedChapterLink.classList.add('active');
|
relatedChapterLink.classList.add('active');
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -62,7 +92,7 @@ export default function observeChapterProgression() {
|
||||||
const plusLoinBlock = document.querySelector('#aller-plus-loin');
|
const plusLoinBlock = document.querySelector('#aller-plus-loin');
|
||||||
const helpHomegradeBlock = document.querySelector('#homegrade-vous-aide');
|
const helpHomegradeBlock = document.querySelector('#homegrade-vous-aide');
|
||||||
const partnersOtherServices = document.querySelector('#partenaires-autres-services');
|
const partnersOtherServices = document.querySelector('#partenaires-autres-services');
|
||||||
|
const customTitles = document.querySelectorAll('.homegrade-blocks-custom-heading[id]');
|
||||||
let allBlocks = [];
|
let allBlocks = [];
|
||||||
|
|
||||||
if (vocabulaireSummaryBlock) allBlocks.push(vocabulaireSummaryBlock);
|
if (vocabulaireSummaryBlock) allBlocks.push(vocabulaireSummaryBlock);
|
||||||
|
|
@ -73,7 +103,7 @@ export default function observeChapterProgression() {
|
||||||
allBlocks = [...allBlocks, ...questionsContainerBlocks];
|
allBlocks = [...allBlocks, ...questionsContainerBlocks];
|
||||||
if (postsContainerBlocks.length > 0) allBlocks = [...allBlocks, ...postsContainerBlocks];
|
if (postsContainerBlocks.length > 0) allBlocks = [...allBlocks, ...postsContainerBlocks];
|
||||||
if (chapitresThematiques.length > 0) allBlocks = [...allBlocks, ...chapitresThematiques];
|
if (chapitresThematiques.length > 0) allBlocks = [...allBlocks, ...chapitresThematiques];
|
||||||
|
if (customTitles.length > 0) allBlocks = [...allBlocks, ...customTitles];
|
||||||
return allBlocks;
|
return allBlocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user