blob: b888a9896319165c8ea72a91768dd3ae0458009b [file] [log] [blame]
var M=async function(){if(!["/about"].includes(window.location.pathname))return;let f="h2, h3, h4",i=".LeftNav a",l=document.querySelector(".LeftNav"),c=document.querySelector(".go-Content"),u=!1;function r(t="",o={},...n){if(!t)throw new Error("Provide `type` to create document element.");let a=Object.assign(document.createElement(t),o);return n.forEach(e=>{typeof e=="string"?a.appendChild(document.createTextNode(e)):Array.isArray(e)?e.forEach(s=>a.appendChild(s)):e instanceof HTMLElement&&a.appendChild(e)}),a}function v(){return new Promise((t,o)=>{let n=[],a=[];if(!c||!l)return o(".SiteContent not found.");if(l instanceof HTMLElement&&!l?.dataset?.hydrate)return t(!0);for(let e of c.querySelectorAll(f))if(e instanceof HTMLElement&&!e?.dataset?.ignore)switch(e.tagName){case"H2":n=[...n,{id:e.id,label:e?.dataset?.title?e.dataset.title:e.textContent??""}];break;case"H3":case"H4":n[n.length-1]?.subnav?n[n.length-1].subnav&&n[n.length-1].subnav?.push({id:e.id,label:e?.dataset?.title?e.dataset.title:e.textContent??""}):n[n.length-1].subnav=[{id:e.id,label:e?.dataset?.title?e.dataset.title:e.textContent??""}];break}for(let e of n){let s=r("a",{href:"#"+e.id},r("span",{},e.label));if(a=[...a,s],e?.subnav){let m=[];for(let b of e.subnav){let H=r("li",{},r("a",{href:"#"+b.id},r("img",{src:"/static/frontend/about/dot.svg",width:"5",height:"5"}),r("span",{},b.label)));m=[...m,H]}let y=r("ul",{className:"LeftSubnav"},m);a=[...a,y]}}return a.forEach(e=>l.appendChild(e)),t(!0)})}function g(){return new Promise(t=>{if(!document.querySelectorAll(i))return t(!0);for(let o of document.querySelectorAll(i))if(o instanceof HTMLAnchorElement&&o.href===location.href){d(o);break}t(!0)})}function L(){return new Promise(t=>{if(!document.querySelectorAll(i))return t(!0);for(let o of document.querySelectorAll(i))o.classList.remove("active");t(!0)})}function d(t){t instanceof HTMLAnchorElement&&L().then(()=>{t.classList.add("active");let o=t?.parentNode?.parentNode;o instanceof HTMLElement&&o?.classList?.contains("LeftSubnav")&&o.previousElementSibling?.classList.add("active")})}function p(){h();let t=document.querySelector('[href="'+location.hash+'"]');t instanceof HTMLAnchorElement&&d(t)}function h(){u=!0,setTimeout(()=>{u=!1},200)}function E(){if(window.addEventListener("hashchange",p),c?.querySelectorAll(f)){let t=n=>{if(!u&&Array.isArray(n)&&n.length>0){for(let a of n)if(a.isIntersecting&&a.target instanceof HTMLElement){let{id:e}=a.target,s=document.querySelector('[href="#'+e+'"]');s instanceof HTMLAnchorElement&&d(s);break}}},o=new IntersectionObserver(t,{threshold:0,rootMargin:"0px 0px -50% 0px"});for(let n of c.querySelectorAll(f))n instanceof HTMLElement&&!n?.dataset?.ignore&&o.observe(n)}}try{await v(),await g(),location.hash&&h(),E()}catch(t){t instanceof Error?console.error(t.message):console.error(t)}};export{M as initJumpLinks};
/**
* @license
* Copyright 2022 The Go Authors. All rights reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/
//# sourceMappingURL=index.js.map