blob: 8f7ee152a43ccb6d938a506b2dfd716de6318396 [file] [log] [blame]
var n=class{constructor(t,e,d){this.mainHeader=t;this.mainNav=e;this.mainAside=d;this.handleDoubleClick=t=>{t.target===this.mainHeader?.lastElementChild&&(window.getSelection()?.removeAllRanges(),window.scrollTo({top:0,behavior:"smooth"}))};this.handleResize=()=>{let t=(e,d)=>document.documentElement.style.setProperty(e,d);t("--js-unit-header-height","0"),setTimeout(()=>{let e=(this.mainHeader?.getBoundingClientRect().height??0)/16;t("--js-unit-header-height",`${e}rem`),t("--js-sticky-header-height",`${3.5}rem`),t("--js-unit-header-top",`${(e-3.5)*-1}rem`)})};this.headerObserver=new IntersectionObserver(([i])=>{if(i.intersectionRatio<1)for(let r of document.querySelectorAll('[class^="go-Main-header"'))r.setAttribute("data-fixed","true");else{for(let r of document.querySelectorAll('[class^="go-Main-header"'))r.removeAttribute("data-fixed");this.handleResize()}},{threshold:1,rootMargin:`${3.5*16}px`}),this.navObserver=new IntersectionObserver(([i])=>{i.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:`-${3.5*16+10}px`}),this.asideObserver=new IntersectionObserver(([i])=>{i.intersectionRatio<1?this.mainHeader?.setAttribute("data-raised","true"):this.mainHeader?.removeAttribute("data-raised")},{threshold:1,rootMargin:`-${3.5*16+20}px 0px 0px 0px`}),this.init()}init(){this.handleResize(),window.addEventListener("resize",this.handleResize),this.mainHeader?.addEventListener("dblclick",this.handleDoubleClick);let t=document.querySelector(".js-siteHeader");if(this.mainHeader?.hasChildNodes()&&t){let e=document.createElement("div");t.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)}}},s=a=>document.querySelector(a);new n(s(".js-mainHeader"),s(".js-mainNav"),s(".js-mainAside"));export{n as MainLayoutController};
/**
* @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