blob: 31cd64eb73c51ac97b84aa3bfba7d25e8cec0c7a [file] [log] [blame]
function N(){let t=document.querySelector(".js-header");document.querySelectorAll(".js-desktop-menu-hover").forEach(a=>{a.addEventListener("mouseenter",c=>{let m=c.target,s=document.querySelector(".forced-open");s&&s!==a&&(s.blur(),s.classList.remove("forced-open")),m.focus(),m.blur()});let r=c=>{var u,v;let m=c.target,s=m==null?void 0:m.classList.contains("forced-open"),o=c.currentTarget;s?(o.removeEventListener("blur",()=>o.classList.remove("forced-open")),o.classList.remove("forced-open"),o.classList.add("forced-closed"),o.blur(),(u=o==null?void 0:o.parentNode)==null||u.addEventListener("mouseout",()=>{o.classList.remove("forced-closed")})):(o.classList.remove("forced-closed"),o.classList.add("forced-open"),o.focus(),o.addEventListener("blur",()=>o.classList.remove("forced-open")),(v=o==null?void 0:o.parentNode)==null||v.removeEventListener("mouseout",()=>{o.classList.remove("forced-closed")}))};a.addEventListener("click",r)}),document.querySelectorAll(".Header-menuItem").forEach(a=>{a.addEventListener("keyup",r=>{var m;let c=r;c.key==="Escape"&&((m=c.target)==null||m.blur())})});let i=document.querySelectorAll(".js-headerMenuButton");i.forEach(a=>{a.addEventListener("click",r=>{r.preventDefault();let c=t==null?void 0:t.classList.contains("is-active");c?h(t):y(t),a.setAttribute("aria-expanded",c?"true":"false")})});let l=document.querySelector(".js-scrim");l==null||l.addEventListener("click",a=>{a.preventDefault(),document.querySelectorAll(".go-NavigationDrawer-submenuItem.is-active").forEach(c=>h(c)),h(t),i.forEach(c=>{c.setAttribute("aria-expanded",t!=null&&t.classList.contains("is-active")?"true":"false")})});let d=a=>{if(!a)return[];let r=Array.from(a.querySelectorAll(":scope > .go-NavigationDrawer-nav > .go-NavigationDrawer-list > .go-NavigationDrawer-listItem > a, :scope > .go-NavigationDrawer-nav > .go-NavigationDrawer-list > .go-NavigationDrawer-listItem > .go-Header-socialIcons > a")||[]),c=a.querySelector(".go-NavigationDrawer-header > a");return c&&r.unshift(c),r},g=a=>{if(!!a)return a.classList.contains("go-NavigationDrawer-submenuItem")},h=a=>{var m,s;if(!a)return;let r=d(a);a.classList.remove("is-active");let c=(m=a.closest(".go-NavigationDrawer-listItem"))==null?void 0:m.querySelector(":scope > a");c==null||c.focus(),r==null||r.forEach(o=>o==null?void 0:o.setAttribute("tabindex","-1")),r&&r[0]&&(r[0].removeEventListener("keydown",p(a)),r[r.length-1].removeEventListener("keydown",L(a))),a===t&&i&&((s=i[0])==null||s.focus())},y=a=>{let r=d(a);a.classList.add("is-active"),r.forEach(c=>c.setAttribute("tabindex","0")),r[0].focus(),r[0].addEventListener("keydown",p(a)),r[r.length-1].addEventListener("keydown",L(a))},p=a=>r=>{r.key==="Tab"&&r.shiftKey&&(r.preventDefault(),h(a))},L=a=>r=>{r.key==="Tab"&&!r.shiftKey&&(r.preventDefault(),h(a))},T=a=>{var m;let r=g(a),c=d(a);a.addEventListener("keyup",s=>{s.key==="Escape"&&h(a)}),c.forEach(s=>{let o=s.closest("li");if(o&&o.classList.contains("js-mobile-subnav-trigger")){let u=o.querySelector(".go-NavigationDrawer-submenuItem");s.addEventListener("click",()=>{y(u)})}}),r&&(h(a),(m=a==null?void 0:a.querySelector(".go-NavigationDrawer-header"))==null||m.addEventListener("click",s=>{s.preventDefault(),h(a)}))};document.querySelectorAll(".go-NavigationDrawer").forEach(a=>T(a)),h(t)}function R(){let t=document.querySelector(".js-searchForm"),e=document.querySelector(".js-expandSearch"),n=t==null?void 0:t.querySelector("input"),i=document.querySelector(".js-headerLogo"),l=document.querySelector(".js-headerMenuButton");e==null||e.addEventListener("click",()=>{t==null||t.classList.add("go-SearchForm--expanded"),i==null||i.classList.add("go-Header-logo--hidden"),l==null||l.classList.add("go-Header-navOpen--hidden"),n==null||n.focus()}),document==null||document.addEventListener("click",d=>{t!=null&&t.contains(d.target)||(t==null||t.classList.remove("go-SearchForm--expanded"),i==null||i.classList.remove("go-Header-logo--hidden"),l==null||l.classList.remove("go-Header-navOpen--hidden"))})}var S=class{constructor(e){this.el=e;this.setActive=e=>{this.activeIndex=(e+this.slides.length)%this.slides.length,this.el.setAttribute("data-slide-index",String(this.activeIndex));for(let n of this.dots)n.classList.remove("go-Carousel-dot--active");this.dots[this.activeIndex].classList.add("go-Carousel-dot--active");for(let n of this.slides)n.setAttribute("aria-hidden","true");this.slides[this.activeIndex].removeAttribute("aria-hidden"),this.liveRegion.textContent="Slide "+(this.activeIndex+1)+" of "+this.slides.length};var n;this.slides=Array.from(e.querySelectorAll(".go-Carousel-slide")),this.dots=[],this.liveRegion=document.createElement("div"),this.activeIndex=Number((n=e.getAttribute("data-slide-index"))!=null?n:0),this.initSlides(),this.initArrows(),this.initDots(),this.initLiveRegion()}initSlides(){for(let[e,n]of this.slides.entries())e!==this.activeIndex&&n.setAttribute("aria-hidden","true")}initArrows(){var n,i;let e=document.createElement("ul");e.classList.add("go-Carousel-arrows"),e.innerHTML=`
<li>
<button class="go-Carousel-prevSlide" aria-label="Go to previous slide">
<img class="go-Icon" height="24" width="24" src="/static/shared/icon/arrow_left_gm_grey_24dp.svg" alt="">
</button>
</li>
<li>
<button class="go-Carousel-nextSlide" aria-label="Go to next slide">
<img class="go-Icon" height="24" width="24" src="/static/shared/icon/arrow_right_gm_grey_24dp.svg" alt="">
</button>
</li>
`,(n=e.querySelector(".go-Carousel-prevSlide"))==null||n.addEventListener("click",()=>this.setActive(this.activeIndex-1)),(i=e.querySelector(".go-Carousel-nextSlide"))==null||i.addEventListener("click",()=>this.setActive(this.activeIndex+1)),this.el.append(e)}initDots(){let e=document.createElement("ul");e.classList.add("go-Carousel-dots");for(let n=0;n<this.slides.length;n++){let i=document.createElement("li"),l=document.createElement("button");l.classList.add("go-Carousel-dot"),n===this.activeIndex&&l.classList.add("go-Carousel-dot--active"),l.innerHTML=`<span class="go-Carousel-obscured">Slide ${n+1}</span>`,l.addEventListener("click",()=>this.setActive(n)),i.append(l),e.append(i),this.dots.push(l)}this.el.append(e)}initLiveRegion(){this.liveRegion.setAttribute("aria-live","polite"),this.liveRegion.setAttribute("aria-atomic","true"),this.liveRegion.setAttribute("class","go-Carousel-obscured"),this.liveRegion.textContent=`Slide ${this.activeIndex+1} of ${this.slides.length}`,this.el.appendChild(this.liveRegion)}};var H=class{constructor(e){this.el=e;var n,i,l,d,g;this.data=(n=e.dataset.toCopy)!=null?n:e.innerText,!this.data&&((i=e.parentElement)==null?void 0:i.classList.contains("go-InputGroup"))&&(this.data=(g=this.data||((d=(l=e.parentElement)==null?void 0:l.querySelector("input"))==null?void 0:d.value))!=null?g:""),e.addEventListener("click",h=>this.handleCopyClick(h))}handleCopyClick(e){e.preventDefault();let n=1e3;if(!navigator.clipboard){this.showTooltipText("Unable to copy",n);return}navigator.clipboard.writeText(this.data).then(()=>{this.showTooltipText("Copied!",n)}).catch(()=>{this.showTooltipText("Unable to copy",n)})}showTooltipText(e,n){this.el.setAttribute("data-tooltip",e),setTimeout(()=>this.el.setAttribute("data-tooltip",""),n)}};var k=class{constructor(e){this.el=e;document.addEventListener("click",n=>{this.el.contains(n.target)||this.el.removeAttribute("open")})}};var A=class{constructor(e){this.el=e;this.el.addEventListener("change",n=>{let i=n.target,l=i.value;i.value.startsWith("/")||(l="/"+l),window.location.href=l})}};var x=class{constructor(e){this.el=e;window.dialogPolyfill&&window.dialogPolyfill.registerDialog(e),this.init()}init(){let e=document.querySelector(`[aria-controls="${this.el.id}"]`);e&&e.addEventListener("click",()=>{var n;this.el.showModal?this.el.showModal():this.el.setAttribute("opened","true"),(n=this.el.querySelector("input"))==null||n.focus()});for(let n of this.el.querySelectorAll("[data-modal-close]"))n.addEventListener("click",()=>{this.el.close?this.el.close():this.el.removeAttribute("opened")})}};function C(t,e,n,i){var l;(l=window.dataLayer)!=null||(window.dataLayer=[]),typeof t=="string"?window.dataLayer.push({event:t,event_category:e,event_action:n,event_label:i}):window.dataLayer.push(t)}function _(t){var e;(e=window.dataLayer)!=null||(window.dataLayer=[]),window.dataLayer.push(t)}var q=class{constructor(){this.handlers={},document.addEventListener("keydown",e=>this.handleKeyPress(e))}on(e,n,i,l){var d,g;return(g=(d=this.handlers)[e])!=null||(d[e]=new Set),this.handlers[e].add({description:n,callback:i,...l}),this}handleKeyPress(e){var n;for(let i of(n=this.handlers[e.key.toLowerCase()])!=null?n:new Set){if(i.target&&i.target!==e.target)return;let l=e.target;if(!i.target&&((l==null?void 0:l.tagName)==="INPUT"||(l==null?void 0:l.tagName)==="SELECT"||(l==null?void 0:l.tagName)==="TEXTAREA")||l!=null&&l.isContentEditable||i.withMeta&&!(e.ctrlKey||e.metaKey)||!i.withMeta&&(e.ctrlKey||e.metaKey))return;C("keypress","hotkeys",`${e.key} pressed`,i.description),i.callback(e)}}},M=new q;function O(){var m;let t=document.querySelector(".JumpDialog"),e=t==null?void 0:t.querySelector(".JumpDialog-body"),n=t==null?void 0:t.querySelector(".JumpDialog-list"),i=t==null?void 0:t.querySelector(".JumpDialog-input"),l=document.querySelector(".js-documentation"),d;function g(){let s=[];if(!!l){for(let o of l.querySelectorAll("[data-kind]"))s.push(h(o));for(let o of s)o.link.addEventListener("click",function(){t==null||t.close()});return s.sort(function(o,u){return o.lower.localeCompare(u.lower)}),s}}function h(s){var w;let o=document.createElement("a"),u=s.getAttribute("id");o.setAttribute("href","#"+u),o.setAttribute("tabindex","-1"),o.setAttribute("data-gtmc","jump to link");let v=s.getAttribute("data-kind");return{link:o,name:u!=null?u:"",kind:v!=null?v:"",lower:(w=u==null?void 0:u.toLowerCase())!=null?w:""}}let y,p=-1;function L(s){for(y=s,d||(d=g()),T(-1);n!=null&&n.firstChild;)n.firstChild.remove();if(s){let o=s.toLowerCase(),u=[],v=[],w=[],I=(f,E,b)=>f.name.substring(0,E)+"<b>"+f.name.substring(E,b)+"</b>"+f.name.substring(b);for(let f of d!=null?d:[]){let E=f.name.toLowerCase();if(E===o)f.link.innerHTML=I(f,0,f.name.length),u.push(f);else if(E.startsWith(o))f.link.innerHTML=I(f,0,s.length),v.push(f);else{let b=E.indexOf(o);b>-1&&(f.link.innerHTML=I(f,b,b+s.length),w.push(f))}}for(let f of u.concat(v).concat(w))n==null||n.appendChild(f.link)}else{if(!d||d.length===0){let o=document.createElement("i");o.innerHTML="There are no symbols on this page.",n==null||n.appendChild(o)}for(let o of d!=null?d:[])o.link.innerHTML=o.name+" <i>"+o.kind+"</i>",n==null||n.appendChild(o.link)}e&&(e.scrollTop=0),(d==null?void 0:d.length)&&n&&n.children.length>0&&T(0)}function T(s){let o=n==null?void 0:n.children;if(!(!o||!e)){if(p>=0&&o[p].classList.remove("JumpDialog-active"),s>=o.length&&(s=o.length-1),s>=0){o[s].classList.add("JumpDialog-active");let u=o[s].offsetTop-o[0].offsetTop,v=u+o[s].clientHeight;u<e.scrollTop?e.scrollTop=u:v>e.scrollTop+e.clientHeight&&(e.scrollTop=v-e.clientHeight)}p=s}}function a(s){if(p<0)return;let o=p+s;o<0&&(o=0),T(o)}i==null||i.addEventListener("keyup",function(){i.value.toUpperCase()!=y.toUpperCase()&&L(i.value)}),i==null||i.addEventListener("keydown",function(s){switch(s.which){case 38:a(-1),s.preventDefault();break;case 40:a(1),s.preventDefault();break;case 13:p>=0&&n&&(n.children[p].click(),s.preventDefault());break}});let r=document.querySelector(".ShortcutsDialog");M.on("f","open jump to modal",s=>{var o;(t==null?void 0:t.open)||(r==null?void 0:r.open)||(s.preventDefault(),i&&(i.value=""),(o=t==null?void 0:t.showModal)==null||o.call(t),i==null||i.focus(),L(""))}).on("?","open shortcuts modal",()=>{var s;(t==null?void 0:t.open)||(r==null?void 0:r.open)||(s=r==null?void 0:r.showModal)==null||s.call(r)});let c=document.querySelector(".js-jumpToInput");c&&c.addEventListener("click",()=>{var s;i&&(i.value=""),L(""),!((t==null?void 0:t.open)||(r==null?void 0:r.open))&&((s=t==null?void 0:t.showModal)==null||s.call(t),i==null||i.focus())}),(m=document.querySelector(".js-openShortcuts"))==null||m.addEventListener("click",()=>{var s;(s=r==null?void 0:r.showModal)==null||s.call(r)})}window.addEventListener("load",()=>{var t;for(let e of document.querySelectorAll(".js-clipboard"))new H(e);for(let e of document.querySelectorAll(".js-modal"))new x(e);for(let e of document.querySelectorAll(".js-tooltip"))new k(e);for(let e of document.querySelectorAll(".js-selectNav"))new A(e);for(let e of document.querySelectorAll(".js-carousel"))new S(e);for(let e of document.querySelectorAll(".js-toggleTheme"))e.addEventListener("click",()=>{U()});((t=document.querySelector(".js-gtmID"))==null?void 0:t.dataset.gtmid)&&window.dataLayer?_(function(){K()}):K(),N(),R(),O()});M.on("/","focus search",t=>{let e=Array.from(document.querySelectorAll(".js-searchFocus")).pop();e&&!window.navigator.userAgent.includes("Firefox")&&(t.preventDefault(),e.focus())});M.on("y","set canonical url",()=>{var e;let t=(e=document.querySelector(".js-canonicalURLPath"))==null?void 0:e.dataset.canonicalUrlPath;if(t&&t!==""){let n=window.location.hash;n&&(t+=n),window.history.replaceState(null,"",t)}});(function(){C({"gtm.start":new Date().getTime(),event:"gtm.js"})})();function K(){let t=new URLSearchParams(window.location.search),e=t.get("utm_source");if(e!=="gopls"&&e!=="godoc"&&e!=="pkggodev")return;let n=new URL(window.location.href);t.delete("utm_source"),n.search=t.toString(),window.history.replaceState(null,"",n.toString())}function U(){let t="dark",e=document.documentElement.getAttribute("data-theme");e==="dark"?t="light":e==="light"&&(t="auto");let n="";location.hostname.endsWith("go.dev")&&(n="domain=.go.dev;"),document.documentElement.setAttribute("data-theme",t),document.cookie=`prefers-color-scheme=${t};${n}path=/;max-age=31536000;`}
/*!
* @license
* Copyright 2019-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 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=frontend.js.map