blob: 4c6f1a06e8dac389229b8551e1bbc92a13ee01b6 [file] [log] [blame]
var O=async function(){if(!["/about"].includes(window.location.pathname))return;let d="h2, h3, h4",u=".LeftNav a",i=document.querySelector(".LeftNav"),c=document.querySelector(".go-Content"),h=!1;function a(t="",r={},...o){if(!t)throw new Error("Provide `type` to create document element.");let n=Object.assign(document.createElement(t),r);return o.forEach(s=>{typeof s=="string"?n.appendChild(document.createTextNode(s)):Array.isArray(s)?s.forEach(l=>n.appendChild(l)):s instanceof HTMLElement&&n.appendChild(s)}),n}function T(){return new Promise((t,r)=>{var s,l,f,L,v,E,p,y,H,A;let o=[],n=[];if(!c||!i)return r(".SiteContent not found.");if(i instanceof HTMLElement&&!((s=i==null?void 0:i.dataset)!=null&&s.hydrate))return t(!0);for(let e of c.querySelectorAll(d))if(e instanceof HTMLElement&&!((l=e==null?void 0:e.dataset)!=null&&l.ignore))switch(e.tagName){case"H2":o=[...o,{id:e.id,label:(f=e==null?void 0:e.dataset)!=null&&f.title?e.dataset.title:(L=e.textContent)!=null?L:""}];break;case"H3":case"H4":(v=o[o.length-1])!=null&&v.subnav?o[o.length-1].subnav&&((A=o[o.length-1].subnav)==null||A.push({id:e.id,label:(y=e==null?void 0:e.dataset)!=null&&y.title?e.dataset.title:(H=e.textContent)!=null?H:""})):o[o.length-1].subnav=[{id:e.id,label:(E=e==null?void 0:e.dataset)!=null&&E.title?e.dataset.title:(p=e.textContent)!=null?p:""}];break}for(let e of o){let C=a("a",{href:"#"+e.id},a("span",{},e.label));if(n=[...n,C],e!=null&&e.subnav){let b=[];for(let M of e.subnav){let x=a("li",{},a("a",{href:"#"+M.id},a("img",{src:"/static/frontend/about/dot.svg",width:"5",height:"5"}),a("span",{},M.label)));b=[...b,x]}let N=a("ul",{className:"LeftSubnav"},b);n=[...n,N]}}return n.forEach(e=>i.appendChild(e)),t(!0)})}function S(){return new Promise(t=>{if(!document.querySelectorAll(u))return t(!0);for(let r of document.querySelectorAll(u))if(r instanceof HTMLAnchorElement&&r.href===location.href){m(r);break}t(!0)})}function k(){return new Promise(t=>{if(!document.querySelectorAll(u))return t(!0);for(let r of document.querySelectorAll(u))r.classList.remove("active");t(!0)})}function m(t){t instanceof HTMLAnchorElement&&k().then(()=>{var o,n,s;t.classList.add("active");let r=(o=t==null?void 0:t.parentNode)==null?void 0:o.parentNode;r instanceof HTMLElement&&((n=r==null?void 0:r.classList)!=null&&n.contains("LeftSubnav"))&&((s=r.previousElementSibling)==null||s.classList.add("active"))})}function w(){g();let t=document.querySelector('[href="'+location.hash+'"]');t instanceof HTMLAnchorElement&&m(t)}function g(){h=!0,setTimeout(()=>{h=!1},200)}function q(){var t;if(window.addEventListener("hashchange",w),c!=null&&c.querySelectorAll(d)){let r=n=>{if(!h&&Array.isArray(n)&&n.length>0){for(let s of n)if(s.isIntersecting&&s.target instanceof HTMLElement){let{id:l}=s.target,f=document.querySelector('[href="#'+l+'"]');f instanceof HTMLAnchorElement&&m(f);break}}},o=new IntersectionObserver(r,{threshold:0,rootMargin:"0px 0px -50% 0px"});for(let n of c.querySelectorAll(d))n instanceof HTMLElement&&!((t=n==null?void 0:n.dataset)!=null&&t.ignore)&&o.observe(n)}}try{await T(),await S(),location.hash&&g(),q()}catch(t){t instanceof Error?console.error(t.message):console.error(t)}};export{O 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