UNPKG

spectaql

Version:

A powerful library for autogenerating static GraphQL API documentation

1 lines 1.84 kB
"use strict";function scrollSpy(){var l="nav-scroll-active",r="nav-scroll-expand",i=null,s=[];function e(){i=null;var e=document.querySelectorAll("[data-traverse-target]");Array.prototype.forEach.call(e,function(e){s.push({id:e.id,top:e.offsetTop})})}var t=debounce(function(){e(),n()},500),n=debounce(function(){var e,t,n,o,c=function(e){for(var t=e+5,n=0;n<s.length;n++){var o=s[n],c=s[n+1];if(t>=o.top&&(!c||t<c.top))return n}return-1}(document.documentElement.scrollTop||document.body.scrollTop);c!==i&&(c=s[i=c],o=function(e){return e&&e.closest?e.closest(".nav-group-section"):null},e=document.querySelector("."+l),t=o(c=c?document.querySelector("a[href*="+c.id+"]"):null),n=(o=o(e))!==t,o&&n&&o.classList.remove(r),t&&n&&t.classList.add(r),c&&(c.classList.add(l),c.scrollIntoViewIfNeeded?c.scrollIntoViewIfNeeded():!c.scrollIntoView||0<=(o=(o=c).getBoundingClientRect()).top&&0<=o.left&&o.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&o.right<=(window.innerWidth||document.documentElement.clientWidth)||c.scrollIntoView({block:"center",inline:"start"})),e&&e.classList.remove(l))},100);setTimeout(function(){e(),n(),window.addEventListener("scroll",n),window.addEventListener("resize",t)},300)}function toggleMenu(){var t="drawer-open",e=document.querySelector("#spectaql .sidebar-open-button"),n=document.querySelector("#spectaql #sidebar .close-button"),o=document.querySelector("#spectaql .drawer-overlay");function c(){var e=document.querySelector("#spectaql #page");e.classList.contains(t)?e.classList.remove(t):e.classList.add(t)}e.addEventListener("click",c),n.addEventListener("click",c),o.addEventListener("click",c)}function debounce(e,t){var n=null;return function(){clearTimeout(n),n=setTimeout(function(){e.apply(null)},t)}}window.addEventListener("DOMContentLoaded",e=>{toggleMenu(),scrollSpy()});