blob: 435141a0265950456982ce32aa2fd74c860b89f6 [file] [log] [blame]
(()=>{var n=class{constructor(e,t){this.table=e;this.toggleAll=t;this.expandAllItems=()=>{this.toggles.map(e=>e.setAttribute("aria-expanded","true")),this.update()};this.collapseAllItems=()=>{this.toggles.map(e=>e.setAttribute("aria-expanded","false")),this.update()};this.update=()=>{this.updateVisibleItems(),setTimeout(()=>this.updateGlobalToggle())};this.rows=Array.from(e.querySelectorAll("[data-aria-controls]")),this.toggles=Array.from(this.table.querySelectorAll("[aria-expanded]")),this.setAttributes(),this.attachEventListeners(),this.update()}setAttributes(){for(let e of["data-aria-controls","data-aria-labelledby","data-id"])this.table.querySelectorAll(`[${e}]`).forEach(t=>{t.setAttribute(e.replace("data-",""),t.getAttribute(e)??""),t.removeAttribute(e)})}attachEventListeners(){this.rows.forEach(e=>{e.addEventListener("click",t=>{this.handleToggleClick(t)})}),this.toggleAll?.addEventListener("click",()=>{this.expandAllItems()}),document.addEventListener("keydown",e=>{(e.ctrlKey||e.metaKey)&&e.key==="f"&&this.expandAllItems()})}handleToggleClick(e){let t=e.currentTarget;t?.hasAttribute("aria-expanded")||(t=this.table.querySelector(`button[aria-controls="${t?.getAttribute("aria-controls")}"]`));let r=t?.getAttribute("aria-expanded")==="true";t?.setAttribute("aria-expanded",r?"false":"true"),e.stopPropagation(),this.update()}updateVisibleItems(){this.rows.map(e=>{let t=e?.getAttribute("aria-expanded")==="true";e?.getAttribute("aria-controls")?.trimEnd().split(" ")?.map(a=>{let i=document.getElementById(`${a}`);t?(i?.classList.add("visible"),i?.classList.remove("hidden")):(i?.classList.add("hidden"),i?.classList.remove("visible"))})})}updateGlobalToggle(){if(!this.toggleAll)return;this.rows.some(t=>t.hasAttribute("aria-expanded"))&&(this.toggleAll.style.display="block"),this.toggles.some(t=>t.getAttribute("aria-expanded")==="false")?(this.toggleAll.innerText="Expand all",this.toggleAll.onclick=this.expandAllItems):(this.toggleAll.innerText="Collapse all",this.toggleAll.onclick=this.collapseAllItems)}};document.querySelectorAll(".js-expandableTable").forEach(s=>new n(s,document.querySelector(".js-expandAllDirectories")));var l=3.5,h=2.5,d=class{constructor(e,t,r){this.mainHeader=e;this.mainNav=t;this.mainAside=r;this.handleDoubleClick=e=>{e.target===this.mainHeader?.lastElementChild&&(window.getSelection()?.removeAllRanges(),window.scrollTo({top:0,behavior:"smooth"}))};this.handleResize=()=>{let e=(t,r)=>document.documentElement.style.setProperty(t,r);e("--js-unit-header-height","0"),setTimeout(()=>{let t=(this.mainHeader?.getBoundingClientRect().height??0)/16;e("--js-unit-header-height",`${t}rem`),e("--js-sticky-header-height",`${l}rem`),e("--js-unit-header-top",`${(t-l)*-1}rem`)})};this.headerObserver=new IntersectionObserver(([a])=>{if(a.intersectionRatio<1)for(let i of document.querySelectorAll('[class^="go-Main-header"'))i.setAttribute("data-fixed","true");else{for(let i of document.querySelectorAll('[class^="go-Main-header"'))i.removeAttribute("data-fixed");this.handleResize()}},{threshold:1,rootMargin:`${h*16}px`}),this.navObserver=new IntersectionObserver(([a])=>{a.intersectionRatio<1?(this.mainNav?.classList.add("go-Main-nav--fixed"),this.mainNav?.setAttribute("data-fixed","true")):(this.mainNav?.classList.remove("go-Main-nav--fixed"),this.mainNav?.removeAttribute("data-fixed"))},{threshold:1,rootMargin:`-${l*16+10}px`}),this.asideObserver=new IntersectionObserver(([a])=>{a.intersectionRatio<1?this.mainHeader?.setAttribute("data-raised","true"):this.mainHeader?.removeAttribute("data-raised")},{threshold:1,rootMargin:`-${l*16+20}px 0px 0px 0px`}),this.init()}init(){if(this.handleResize(),window.addEventListener("resize",this.handleResize),this.mainHeader?.addEventListener("dblclick",this.handleDoubleClick),this.mainHeader?.hasChildNodes()){let e=document.createElement("div");this.mainHeader.prepend(e),this.headerObserver.observe(e)}if(this.mainNav?.hasChildNodes()){let e=document.createElement("div");this.mainNav.prepend(e),this.navObserver.observe(e)}if(this.mainAside){let e=document.createElement("div");this.mainAside.prepend(e),this.asideObserver.observe(e)}}},o=s=>document.querySelector(s);new d(o(".js-mainHeader"),o(".js-mainNav"),o(".js-mainAside"));})();
/*!
* @license
* Copyright 2020 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.
*/
/**
* @license
* Copyright 2021 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=unit.js.map