blob: d1aeba17e79636f5f37b55ca30ec4c313cb35a6d [file] [log] [blame]
function I(){let e=document.querySelector(".js-header"),t=document.querySelectorAll(".js-headerMenuButton");t.forEach(o=>{o.addEventListener("click",i=>{i.preventDefault(),e==null||e.classList.toggle("is-active"),o.setAttribute("aria-expanded",String(e==null?void 0:e.classList.contains("is-active")))})});let n=document.querySelector(".js-scrim");n==null||n.addEventListener("click",o=>{o.preventDefault(),e==null||e.classList.remove("is-active"),t.forEach(i=>{i.setAttribute("aria-expanded",String(e==null?void 0:e.classList.contains("is-active")))})})}function R(){let e=document.querySelector(".js-searchForm"),t=document.querySelector(".js-expandSearch"),n=e==null?void 0:e.querySelector("input"),o=document.querySelector(".js-headerLogo"),i=document.querySelector(".js-headerMenuButton");t==null||t.addEventListener("click",()=>{e==null||e.classList.add("go-SearchForm--expanded"),o==null||o.classList.add("go-Header-logo--hidden"),i==null||i.classList.add("go-Header-navOpen--hidden"),n==null||n.focus()}),document==null||document.addEventListener("click",l=>{(e==null?void 0:e.contains(l.target))||(e==null||e.classList.remove("go-SearchForm--expanded"),o==null||o.classList.remove("go-Header-logo--hidden"),i==null||i.classList.remove("go-Header-navOpen--hidden"))})}var y=class{constructor(t){this.el=t;this.setActive=t=>{this.activeIndex=(t+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(t.querySelectorAll(".go-Carousel-slide")),this.dots=[],this.liveRegion=document.createElement("div"),this.activeIndex=Number((n=t.getAttribute("data-slide-index"))!=null?n:0),this.initSlides(),this.initArrows(),this.initDots(),this.initLiveRegion()}initSlides(){for(let[t,n]of this.slides.entries())t!==this.activeIndex&&n.setAttribute("aria-hidden","true")}initArrows(){var n,o;let t=document.createElement("ul");t.classList.add("go-Carousel-arrows"),t.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=t.querySelector(".go-Carousel-prevSlide"))==null||n.addEventListener("click",()=>this.setActive(this.activeIndex-1)),(o=t.querySelector(".go-Carousel-nextSlide"))==null||o.addEventListener("click",()=>this.setActive(this.activeIndex+1)),this.el.append(t)}initDots(){let t=document.createElement("ul");t.classList.add("go-Carousel-dots");for(let n=0;n<this.slides.length;n++){let o=document.createElement("li"),i=document.createElement("button");i.classList.add("go-Carousel-dot"),n===this.activeIndex&&i.classList.add("go-Carousel-dot--active"),i.innerHTML=`<span class="go-Carousel-obscured">Slide ${n+1}</span>`,i.addEventListener("click",()=>this.setActive(n)),o.append(i),t.append(o),this.dots.push(i)}this.el.append(t)}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 S=class{constructor(t){this.el=t;var n,o,i,l,h;this.data=(n=t.dataset.toCopy)!=null?n:t.innerText,!this.data&&((o=t.parentElement)==null?void 0:o.classList.contains("go-InputGroup"))&&(this.data=(h=this.data||((l=(i=t.parentElement)==null?void 0:i.querySelector("input"))==null?void 0:l.value))!=null?h:""),t.addEventListener("click",w=>this.handleCopyClick(w))}handleCopyClick(t){t.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(t,n){this.el.setAttribute("data-tooltip",t),setTimeout(()=>this.el.setAttribute("data-tooltip",""),n)}};var M=class{constructor(t){this.el=t;document.addEventListener("click",n=>{this.el.contains(n.target)||this.el.removeAttribute("open")})}};var H=class{constructor(t){this.el=t;this.el.addEventListener("change",n=>{let o=n.target,i=o.value;o.value.startsWith("/")||(i="/"+i),window.location.href=i})}};var k=class{constructor(t){this.el=t;window.dialogPolyfill&&window.dialogPolyfill.registerDialog(t),this.init()}init(){let t=document.querySelector(`[aria-controls="${this.el.id}"]`);t&&t.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 L(e,t,n,o){var i;(i=window.dataLayer)!=null||(window.dataLayer=[]),typeof e=="string"?window.dataLayer.push({event:e,event_category:t,event_action:n,event_label:o}):window.dataLayer.push(e)}function _(e){var t;(t=window.dataLayer)!=null||(window.dataLayer=[]),window.dataLayer.push(e)}var O=class{constructor(){this.handlers={},document.addEventListener("keydown",t=>this.handleKeyPress(t))}on(t,n,o,i){var l,h;return(h=(l=this.handlers)[t])!=null||(l[t]=new Set),this.handlers[t].add({description:n,callback:o,...i}),this}handleKeyPress(t){var n;for(let o of(n=this.handlers[t.key.toLowerCase()])!=null?n:new Set){if(o.target&&o.target!==t.target)return;let i=t.target;if(!o.target&&((i==null?void 0:i.tagName)==="INPUT"||(i==null?void 0:i.tagName)==="SELECT"||(i==null?void 0:i.tagName)==="TEXTAREA")||(i==null?void 0:i.isContentEditable)||o.withMeta&&!(t.ctrlKey||t.metaKey)||!o.withMeta&&(t.ctrlKey||t.metaKey))return;L("keypress","hotkeys",`${t.key} pressed`,o.description),o.callback(t)}}},g=new O;function J(){var q;let e=document.querySelector(".JumpDialog"),t=e==null?void 0:e.querySelector(".JumpDialog-body"),n=e==null?void 0:e.querySelector(".JumpDialog-list"),o=e==null?void 0:e.querySelector(".JumpDialog-input"),i=document.querySelector(".js-documentation"),l;function h(){let s=[];if(!!i){for(let r of i.querySelectorAll("[data-kind]"))s.push(w(r));for(let r of s)r.link.addEventListener("click",function(){e==null||e.close()});return s.sort(function(r,c){return r.lower.localeCompare(c.lower)}),s}}function w(s){var v;let r=document.createElement("a"),c=s.getAttribute("id");r.setAttribute("href","#"+c),r.setAttribute("tabindex","-1"),r.setAttribute("data-gtmc","jump to link");let u=s.getAttribute("data-kind");return{link:r,name:c!=null?c:"",kind:u!=null?u:"",lower:(v=c==null?void 0:c.toLowerCase())!=null?v:""}}let A,m=-1;function T(s){for(A=s,l||(l=h()),E(-1);n==null?void 0:n.firstChild;)n.firstChild.remove();if(s){let r=s.toLowerCase(),c=[],u=[],v=[],b=(d,p,f)=>d.name.substring(0,p)+"<b>"+d.name.substring(p,f)+"</b>"+d.name.substring(f);for(let d of l!=null?l:[]){let p=d.name.toLowerCase();if(p===r)d.link.innerHTML=b(d,0,d.name.length),c.push(d);else if(p.startsWith(r))d.link.innerHTML=b(d,0,s.length),u.push(d);else{let f=p.indexOf(r);f>-1&&(d.link.innerHTML=b(d,f,f+s.length),v.push(d))}}for(let d of c.concat(u).concat(v))n==null||n.appendChild(d.link)}else{if(!l||l.length===0){let r=document.createElement("i");r.innerHTML="There are no symbols on this page.",n==null||n.appendChild(r)}for(let r of l!=null?l:[])r.link.innerHTML=r.name+" <i>"+r.kind+"</i>",n==null||n.appendChild(r.link)}t&&(t.scrollTop=0),(l==null?void 0:l.length)&&n&&n.children.length>0&&E(0)}function E(s){let r=n==null?void 0:n.children;if(!(!r||!t)){if(m>=0&&r[m].classList.remove("JumpDialog-active"),s>=r.length&&(s=r.length-1),s>=0){r[s].classList.add("JumpDialog-active");let c=r[s].offsetTop-r[0].offsetTop,u=c+r[s].clientHeight;c<t.scrollTop?t.scrollTop=c:u>t.scrollTop+t.clientHeight&&(t.scrollTop=u-t.clientHeight)}m=s}}function C(s){if(m<0)return;let r=m+s;r<0&&(r=0),E(r)}o==null||o.addEventListener("keyup",function(){o.value.toUpperCase()!=A.toUpperCase()&&T(o.value)}),o==null||o.addEventListener("keydown",function(s){let r=38,c=40,u=13;switch(s.which){case r:C(-1),s.preventDefault();break;case c:C(1),s.preventDefault();break;case u:m>=0&&n&&(n.children[m].click(),s.preventDefault());break}});let a=document.querySelector(".ShortcutsDialog");g.on("f","open jump to modal",s=>{var r;(e==null?void 0:e.open)||(a==null?void 0:a.open)||(s.preventDefault(),o&&(o.value=""),(r=e==null?void 0:e.showModal)==null||r.call(e),o==null||o.focus(),T(""))}).on("?","open shortcuts modal",()=>{var s;(e==null?void 0:e.open)||(a==null?void 0:a.open)||(s=a==null?void 0:a.showModal)==null||s.call(a)});let x=document.querySelector(".js-jumpToInput");x&&x.addEventListener("click",()=>{var s;o&&(o.value=""),T(""),!((e==null?void 0:e.open)||(a==null?void 0:a.open))&&((s=e==null?void 0:e.showModal)==null||s.call(e),o==null||o.focus())}),(q=document.querySelector(".js-openShortcuts"))==null||q.addEventListener("click",()=>{var s;(s=a==null?void 0:a.showModal)==null||s.call(a)})}for(let e of document.querySelectorAll(".js-clipboard"))new S(e);for(let e of document.querySelectorAll(".js-modal"))new k(e);for(let e of document.querySelectorAll(".js-tooltip"))new M(e);for(let e of document.querySelectorAll(".js-selectNav"))new H(e);for(let e of document.querySelectorAll(".js-carousel"))new y(e);I();R();window.addEventListener("load",()=>{J()});g.on("/","focus search",e=>{let t=Array.from(document.querySelectorAll(".js-searchFocus")).pop();t&&!window.navigator.userAgent.includes("Firefox")&&(e.preventDefault(),t.focus())});g.on("y","set canonical url",()=>{var t;let e=(t=document.querySelector(".js-canonicalURLPath"))==null?void 0:t.dataset.canonicalUrlPath;if(e&&e!==""){let n=window.location.hash;n&&(e+=n),window.history.replaceState(null,"",e)}});(function(){L({"gtm.start":new Date().getTime(),event:"gtm.js"})})();function N(){let e=new URLSearchParams(window.location.search),t=e.get("utm_source");if(t!=="gopls"&&t!=="godoc"&&t!=="pkggodev")return;let n=new URL(window.location.href);e.delete("utm_source"),n.search=e.toString(),window.history.replaceState(null,"",n.toString())}var U;((U=document.querySelector(".js-gtmID"))==null?void 0:U.dataset.gtmid)&&window.dataLayer?_(function(){N()}):N();for(let e of document.querySelectorAll(".js-toggleTheme"))e.addEventListener("click",()=>{P()});function P(){let e="dark",t=document.documentElement.getAttribute("data-theme");t==="dark"?e="light":t==="light"&&(e="auto");let n="";location.hostname.endsWith("go.dev")&&(n="domain=.go.dev;"),document.documentElement.setAttribute("data-theme",e),document.cookie=`prefers-color-scheme=${e};${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