blob: 102256d1e19e9f3b04fa7b1d1ec2c1558e5ad6ad [file] [log] [blame]
/*!
* @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.
*/import{CopyToClipboardController as p}from"./clipboard.js";import"./toggle-tip.js";import{ExpandableRowsTableController as y}from"./table.js";document.querySelectorAll(".js-expandableTable").forEach(e=>new y(e,document.querySelector(".js-expandAllDirectories"))),document.querySelectorAll(".js-copyToClipboard").forEach(e=>{new p(e)});const t=document.querySelector(".js-readme"),l=document.querySelector(".js-readmeContent"),s=document.querySelector(".js-readmeOutline"),o=document.querySelectorAll(".js-readmeExpand"),i=document.querySelector(".js-readmeCollapse"),E=document.querySelector(".DocNavMobile-select");t&&l&&s&&o.length&&i&&(window.location.hash.includes("readme")&&t.classList.add("UnitReadme--expanded"),E?.addEventListener("change",e=>{e.target.value.startsWith("readme-")&&t.classList.add("UnitReadme--expanded")}),o.forEach(e=>e.addEventListener("click",n=>{n.preventDefault(),t.classList.add("UnitReadme--expanded"),t.scrollIntoView()})),i.addEventListener("click",e=>{e.preventDefault(),t.classList.remove("UnitReadme--expanded"),o[1]&&o[1].scrollIntoView({block:"center"})}),l.addEventListener("keyup",()=>{t.classList.add("UnitReadme--expanded")}),l.addEventListener("click",()=>{t.classList.add("UnitReadme--expanded")}),s.addEventListener("click",()=>{t.classList.add("UnitReadme--expanded")}),document.addEventListener("keydown",e=>{(e.ctrlKey||e.metaKey)&&e.key==="f"&&t.classList.add("UnitReadme--expanded")}));for(const e of document.querySelectorAll(".js-deprecatedTagLink")){const n=new URL(e.href).hash,d=document.querySelector(n)?.parentElement?.parentElement;d&&(e.addEventListener("click",()=>{d.open=!0}),location.hash===n&&(d.open=!0))}const m=document.querySelector(".js-readmeOption");m&&!t&&m.setAttribute("disabled","true");const L=document.querySelector(".js-unitDirectories"),u=document.querySelector(".js-directoriesOption");!L&&u&&u.setAttribute("disabled","true"),document.querySelectorAll(".js-buildContextSelect").forEach(e=>{e.addEventListener("change",n=>{window.location.search=`?GOOS=${n.target.value}`})});const r=document.querySelector(".js-unitHeader");r?.addEventListener("dblclick",e=>{e.target===r.firstElementChild&&r.classList.contains("UnitHeader--sticky")&&(window.getSelection()?.removeAllRanges(),window.scrollTo({top:0}))});const c=document.querySelector(".UnitHeader"),f=c?.querySelector(".UnitHeader-breadcrumbs"),g=c?.querySelector(".UnitHeader-content"),a=()=>{document.documentElement.style.removeProperty("--full-header-height"),document.documentElement.style.setProperty("--full-header-height",`${(c?.getBoundingClientRect().height??0)/16}rem`),document.documentElement.style.setProperty("--banner-height","0rem"),document.documentElement.style.setProperty("--breadcrumbs-height",`${(f?.getBoundingClientRect().height??0)/16}rem`),document.documentElement.style.setProperty("--content-height",`${(g?.getBoundingClientRect().height??0)/16}rem`)};a(),window.addEventListener("resize",function(){a()});const S=new IntersectionObserver(([e])=>{e.intersectionRatio<1?(r?.classList.add("UnitHeader--sticky"),r?.classList.remove("UnitHeader--full")):(r?.classList.remove("UnitHeader--sticky"),r?.classList.add("UnitHeader--full"),a())},{threshold:1,rootMargin:"40px"}),h=document.querySelector(".js-headerSentinel");h&&S.observe(h);
//# sourceMappingURL=unit.js.map