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