git.y1.nz

gbdk-2020

GameBoy Development Kit
download: https://git.y1.nz/archives/gbdk.tar.gz
README | Files | Log | Refs | LICENSE

docs/config/doxygen-awesome-theme/doxygen-awesome-interactive-toc.js

      1 // SPDX-License-Identifier: MIT
      2 /**
      3 
      4 Doxygen Awesome
      5 https://github.com/jothepro/doxygen-awesome-css
      6 
      7 Copyright (c) 2022 - 2025 jothepro
      8 
      9 */
     10 
     11 class DoxygenAwesomeInteractiveToc {
     12     static topOffset = 38
     13     static hideMobileMenu = true
     14     static headers = []
     15 
     16     static init() {
     17         window.addEventListener("load", () => {
     18             let toc = document.querySelector(".contents > .toc")
     19             if(toc) {
     20                 toc.classList.add("interactive")
     21                 if(!DoxygenAwesomeInteractiveToc.hideMobileMenu) {
     22                     toc.classList.add("open")
     23                 }
     24                 document.querySelector(".contents > .toc > h3")?.addEventListener("click", () => {
     25                     if(toc.classList.contains("open")) {
     26                         toc.classList.remove("open")
     27                     } else {
     28                         toc.classList.add("open")
     29                     }
     30                 })
     31 
     32                 document.querySelectorAll(".contents > .toc > ul a").forEach((node) => {
     33                     let id = node.getAttribute("href").substring(1)
     34                     DoxygenAwesomeInteractiveToc.headers.push({
     35                         node: node,
     36                         headerNode: document.getElementById(id)
     37                     })
     38 
     39                     document.getElementById("doc-content")?.addEventListener("scroll",this.throttle(DoxygenAwesomeInteractiveToc.update, 100))
     40                 })
     41                 DoxygenAwesomeInteractiveToc.update()
     42             }
     43         })
     44     }
     45 
     46     static update() {
     47         let active = DoxygenAwesomeInteractiveToc.headers[0]?.node
     48         DoxygenAwesomeInteractiveToc.headers.forEach((header) => {
     49             let position = header.headerNode.getBoundingClientRect().top
     50             header.node.classList.remove("active")
     51             header.node.classList.remove("aboveActive")
     52             if(position < DoxygenAwesomeInteractiveToc.topOffset) {
     53                 active = header.node
     54                 active?.classList.add("aboveActive")
     55             }
     56         })
     57         active?.classList.add("active")
     58         active?.classList.remove("aboveActive")
     59     }
     60 
     61     static throttle(func, delay) {
     62         let lastCall = 0;
     63         return function (...args) {
     64             const now = new Date().getTime();
     65             if (now - lastCall < delay) {
     66                 return;
     67             }
     68             lastCall = now;
     69             return setTimeout(() => {func(...args)}, delay);
     70         };
     71     }
     72 }

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.