xref: /plugin/combo/resources/snippet/js/menubar-fixed-top.js (revision 4cadd4f8c541149bdda95f080e38a6d4e3a640ca)
1window.addEventListener("DOMContentLoaded",function(){
2    let fixedNavbar = document.querySelector(".navbar.fixed-top")
3    // correct body padding
4    let offsetHeight = fixedNavbar.offsetHeight;
5    let marginTop = offsetHeight - 16; // give more space at the top (ie 1rem)
6    document.body.style.setProperty("padding-top",offsetHeight+"px");
7    // correct direct navigation via fragment to heading
8    let style = document.createElement("style");
9    style.classList.add("menubar-fixed-top")
10    // no main > h1, we never jump on h1 and it would add a space with the main header
11    style.innerText = `main > h2, main > h3, main > h4, main > h5, #dokuwiki__top, .fn_top {
12    padding-top: ${offsetHeight}px;
13    margin-top: -${marginTop}px;
14    z-index: -1;
15}`;
16    document.head.appendChild(style);
17});
18