Skip to content

Commit d03e8c0

Browse files
Merge pull request #38488 from aireilly/fix-footer-overlap
fix footer overlap of sidebar and toc
2 parents 650204b + 057c2c1 commit d03e8c0

File tree

1 file changed

+86
-45
lines changed

1 file changed

+86
-45
lines changed

_templates/_page_openshift.html.erb

Lines changed: 86 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -339,48 +339,54 @@
339339

340340
<!-- update active toc class when mouse scrolls -->
341341
<script type="text/javascript">
342-
window.addEventListener("wheel", () => {
343-
344-
const ioConfiguration = {
345-
"rootMargin": "-120px 0px -400px 0px",
346-
"threshold": 0
347-
};
342+
window.addEventListener('DOMContentLoaded', () => {
343+
window.addEventListener("wheel", () => {
344+
345+
const ioConfiguration = {
346+
"rootMargin": "-120px 0px -400px 0px",
347+
"threshold": 0
348+
};
348349

349-
const observer = new IntersectionObserver(setCurrent, ioConfiguration, entries => {
350-
entries.forEach(entry => {
351-
var id = entry.target.getAttribute('id');
352-
//fight with js
353-
document.querySelector(`#toc li a[href="#${id}"]`).classList.remove('toc-active');
350+
const observer = new IntersectionObserver(setCurrent, ioConfiguration, entries => {
351+
entries.forEach(entry => {
352+
var id = entry.target.getAttribute('id');
353+
//fight with js
354+
document.querySelector(`#toc li a[href="#${id}"]`).classList.remove('toc-active');
355+
});
354356
});
355-
});
356-
357-
//track all h1-4 headings that have an id
358-
document.querySelectorAll('.main h2[id], .main h3[id]').forEach((h) => {
359-
observer.observe(h);
360-
});
361-
362-
//runs when the IntersectionObserver fires
363-
function setCurrent(e) {
364-
var allTocLinks = document.querySelectorAll("#toc li a");
365-
e.map(i => {
366-
if (i.isIntersecting && i.intersectionRatio >= 1) {
367-
allTocLinks.forEach(link => link.classList.remove("toc-active"));
368-
document.querySelector(`#toc li a[href="#${i.target.id}"]`).classList.add('toc-active');
369-
}
370-
});
371-
};
372357

373-
//make clicked toc item active and stop IntersectionObserver
374-
$("#toc a").click(function() {
375-
//stop tracking all h1-4 headings that have an id
358+
//track all h1-4 headings that have an id
376359
document.querySelectorAll('.main h2[id], .main h3[id]').forEach((h) => {
377-
observer.unobserve(h);
360+
observer.observe(h);
378361
});
379-
var tocItems = $("#toc a");
380-
for (let i = 0; i < tocItems.length; i++) {
381-
tocItems[i].classList.remove("toc-active");
382-
}
383-
this.classList.add("toc-active");
362+
363+
//runs when the IntersectionObserver fires
364+
function setCurrent(e) {
365+
var allTocLinks = document.querySelectorAll("#toc li a");
366+
if (allTocLinks !== undefined) {
367+
e.map(i => {
368+
if (i.isIntersecting && i.intersectionRatio >= 1) {
369+
allTocLinks.forEach(link => link.classList.remove("toc-active"));
370+
document.querySelector(`#toc li a[href="#${i.target.id}"]`).classList.add('toc-active')
371+
}
372+
})
373+
}
374+
};
375+
376+
//make clicked toc item active and stop IntersectionObserver
377+
$("#toc a").click(function() {
378+
//stop tracking all h1-4 headings that have an id
379+
document.querySelectorAll('.main h2[id], .main h3[id]').forEach((h) => {
380+
observer.unobserve(h);
381+
});
382+
var tocItems = $("#toc a");
383+
if (tocItems !== undefined) {
384+
for (let i = 0; i < tocItems.length; i++) {
385+
tocItems[i].classList.remove("toc-active");
386+
};
387+
this.classList.add("toc-active");
388+
}
389+
})
384390
})
385391
})
386392
</script>
@@ -407,25 +413,60 @@
407413
})
408414
</script>
409415

416+
<!--adjust sidebar and toc when footer is displayed -->
417+
<script type="text/javascript">
418+
sidebar = document.querySelector('.sidebar')
419+
toc = document.querySelector('#toc')
420+
main = document.querySelector('.main')
421+
okd_footer = document.querySelector('.footer-origin-docs')
422+
document.addEventListener('scroll', () => {
423+
//scroll to bottom
424+
if (window.innerWidth >= 1425) {
425+
if(sidebar !== null && toc !== null) {
426+
if(document.documentElement.scrollHeight === window.pageYOffset + window.innerHeight) {
427+
sidebar.style.marginBottom = "38px";
428+
toc.style.bottom = "35px";
429+
main.style.marginBottom = "35px";
430+
//okd footer
431+
if(okd_footer !== null) {
432+
sidebar.style.marginBottom = "176px";
433+
toc.style.bottom = "175px";
434+
main.style.marginBottom = "135px";
435+
};
436+
};
437+
if(document.documentElement.scrollHeight != window.pageYOffset + window.innerHeight) {
438+
sidebar.style.marginBottom = "0px";
439+
toc.style.bottom = "0px";
440+
}
441+
}
442+
}
443+
})
444+
</script>
445+
410446
<!-- adjust alerts on mobile -->
411447
<script type="text/javascript">
448+
alert = document.querySelector('#support-alert')
412449
window.addEventListener("wheel", () => {
413450
if (window.innerWidth < 1425) {
414451
//adjust alert
415452
if(window.pageYOffset > 0) {
416-
document.querySelector('#support-alert').style.position = "fixed";
417-
document.querySelector('#support-alert').style.bottom = "0px";
418-
document.querySelector('#support-alert').style.margin = "5px";
419-
document.querySelector('#support-alert').style.zIndex = "9999999";
453+
if(alert !== null) {
454+
document.querySelector('#support-alert').style.position = "fixed";
455+
document.querySelector('#support-alert').style.bottom = "0px";
456+
document.querySelector('#support-alert').style.margin = "5px";
457+
document.querySelector('#support-alert').style.zIndex = "9999999";
458+
}
420459
}
421460
}
422461
});
423462
window.addEventListener('resize', () => {
424463
if (window.innerWidth >= 1425) {
425-
document.querySelector('#support-alert').style.removeProperty('position');
426-
document.querySelector('#support-alert').style.removeProperty('bottom');
427-
document.querySelector('#support-alert').style.removeProperty('margin');
428-
document.querySelector('#support-alert').style.removeProperty('zIndex');
464+
if(alert !== null) {
465+
document.querySelector('#support-alert').style.removeProperty('position');
466+
document.querySelector('#support-alert').style.removeProperty('bottom');
467+
document.querySelector('#support-alert').style.removeProperty('margin');
468+
document.querySelector('#support-alert').style.removeProperty('zIndex');
469+
}
429470
}
430471
})
431472
</script>

0 commit comments

Comments
 (0)