blob: 45021ffcad3254e3af0f4538a5259fe1b9215078 [file] [log] [blame]
var d=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",`${3.5}rem`),r("--js-unit-header-top",`${(s-3.5)*-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:`${3.5*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:`-${3.5*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:`-${3.5*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&&i.hasChildNodes()&&r){let e=document.createElement("div");r.prepend(e),this.headerObserver.observe(e)}if((t=this.mainNav)!=null&&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)}}},a=o=>document.querySelector(o);new d(a(".js-mainHeader"),a(".js-mainNav"),a(".js-mainAside"));export{d 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