blob: b9f0c8a82d1ded6d894b430603b2608808ed8b00 [file] [log] [blame]
function q(){let t=document.querySelector(".js-header");document.querySelectorAll(".js-desktop-menu-hover").forEach(l=>{l.addEventListener("mouseenter",c=>{let m=c.target,s=document.querySelector(".forced-open");s&&s!==l&&(s.blur(),s.classList.remove("forced-open")),m.focus(),m.blur()});let r=c=>{var u,h;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")),(h=o==null?void 0:o.parentNode)==null||h.removeEventListener("mouseout",()=>{o.classList.remove("forced-closed")}))};l.addEventListener("click",r)}),document.querySelectorAll(".Header-menuItem").forEach(l=>{l.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(l=>{l.addEventListener("click",r=>{r.preventDefault();let c=t==null?void 0:t.classList.contains("is-active");c?v(t):T(t),l.setAttribute("aria-expanded",c?"true":"false")})});let a=document.querySelector(".js-scrim");a==null||a.addEventListener("click",l=>{l.preventDefault(),document.querySelectorAll(".go-NavigationDrawer-submenuItem.is-active").forEach(c=>v(c)),v(t),i.forEach(c=>{c.setAttribute("aria-expanded",(t==null?void 0:t.classList.contains("is-active"))?"true":"false")})});let d=l=>{if(!l)return[];let r=Array.from(l.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=l.querySelector(".go-NavigationDrawer-header > a");return c&&r.unshift(c),r},g=l=>{if(!!l)return l.classList.contains("go-NavigationDrawer-submenuItem")},v=l=>{var m,s;if(!l)return;let r=d(l);l.classList.remove("is-active");let c=(m=l.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(l)),r[r.length-1].removeEventListener("keydown",L(l))),l===t&&i&&((s=i[0])==null||s.focus())},T=l=>{let r=d(l);l.classList.add("is-active"),r.forEach(c=>c.setAttribute("tabindex","0")),r[0].focus(),r[0].addEventListener("keydown",p(l)),r[r.length-1].addEventListener("keydown",L(l))},p=l=>r=>{r.key==="Tab"&&r.shiftKey&&(r.preventDefault(),v(l))},L=l=>r=>{r.key==="Tab"&&!r.shiftKey&&(r.preventDefault(),v(l))},y=l=>{var m;let r=g(l),c=d(l);l.addEventListener("keyup",s=>{s.key==="Escape"&&v(l)}),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",()=>{T(u)})}}),r&&(v(l),(m=l==null?void 0:l.querySelector(".go-NavigationDrawer-header"))==null||m.addEventListener("click",s=>{s.preventDefault(),v(l)}))};document.querySelectorAll(".go-NavigationDrawer").forEach(l=>y(l)),v(t)}function N(){let t=document.querySelector(".js-searchForm"),e=document.querySelector(".js-expandSearch"),n=t==null?void 0:t.querySelector("input"),i=document.querySelector(".js-headerLogo"),a=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"),a==null||a.classList.add("go-Header-navOpen--hidden"),n==null||n.focus()}),document==null||document.addEventListener("click",d=>{(t==null?void 0:t.contains(d.target))||(t==null||t.classList.remove("go-SearchForm--expanded"),i==null||i.classList.remove("go-Header-logo--hidden"),a==null||a.classList.remove("go-Header-navOpen--hidden"))})}var k=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"),a=document.createElement("button");a.classList.add("go-Carousel-dot"),n===this.activeIndex&&a.classList.add("go-Carousel-dot--active"),a.innerHTML=`<span class="go-Carousel-obscured">Slide ${n+1}</span>`,a.addEventListener("click",()=>this.setActive(n)),i.append(a),e.append(i),this.dots.push(a)}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 A=class{constructor(e){this.el=e;var n,i,a,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=(a=e.parentElement)==null?void 0:a.querySelector("input"))==null?void 0:d.value))!=null?g:""),e.addEventListener("click",v=>this.handleCopyClick(v))}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 x=class{constructor(e){this.el=e;document.addEventListener("click",n=>{this.el.contains(n.target)||this.el.removeAttribute("open")})}};var C=class{constructor(e){this.el=e;this.el.addEventListener("change",n=>{let i=n.target,a=i.value;i.value.startsWith("/")||(a="/"+a),window.location.href=a})}};var I=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 S(t,e,n,i){var a;(a=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 R(t){var e;(e=window.dataLayer)!=null||(window.dataLayer=[]),window.dataLayer.push(t)}var _=class{constructor(){this.handlers={},document.addEventListener("keydown",e=>this.handleKeyPress(e))}on(e,n,i,a){var d,g;return(g=(d=this.handlers)[e])!=null||(d[e]=new Set),this.handlers[e].add({description:n,callback:i,...a}),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 a=e.target;if(!i.target&&((a==null?void 0:a.tagName)==="INPUT"||(a==null?void 0:a.tagName)==="SELECT"||(a==null?void 0:a.tagName)==="TEXTAREA")||(a==null?void 0:a.isContentEditable)||i.withMeta&&!(e.ctrlKey||e.metaKey)||!i.withMeta&&(e.ctrlKey||e.metaKey))return;S("keypress","hotkeys",`${e.key} pressed`,i.description),i.callback(e)}}},M=new _;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"),a=document.querySelector(".js-documentation"),d;function g(){let s=[];if(!!a){for(let o of a.querySelectorAll("[data-kind]"))s.push(v(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 v(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 h=s.getAttribute("data-kind");return{link:o,name:u!=null?u:"",kind:h!=null?h:"",lower:(w=u==null?void 0:u.toLowerCase())!=null?w:""}}let T,p=-1;function L(s){for(T=s,d||(d=g()),y(-1);n==null?void 0:n.firstChild;)n.firstChild.remove();if(s){let o=s.toLowerCase(),u=[],h=[],w=[],H=(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=H(f,0,f.name.length),u.push(f);else if(E.startsWith(o))f.link.innerHTML=H(f,0,s.length),h.push(f);else{let b=E.indexOf(o);b>-1&&(f.link.innerHTML=H(f,b,b+s.length),w.push(f))}}for(let f of u.concat(h).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&&y(0)}function y(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,h=u+o[s].clientHeight;u<e.scrollTop?e.scrollTop=u:h>e.scrollTop+e.clientHeight&&(e.scrollTop=h-e.clientHeight)}p=s}}function l(s){if(p<0)return;let o=p+s;o<0&&(o=0),y(o)}i==null||i.addEventListener("keyup",function(){i.value.toUpperCase()!=T.toUpperCase()&&L(i.value)}),i==null||i.addEventListener("keydown",function(s){let o=38,u=40,h=13;switch(s.which){case o:l(-1),s.preventDefault();break;case u:l(1),s.preventDefault();break;case h: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 A(e);for(let e of document.querySelectorAll(".js-modal"))new I(e);for(let e of document.querySelectorAll(".js-tooltip"))new x(e);for(let e of document.querySelectorAll(".js-selectNav"))new C(e);for(let e of document.querySelectorAll(".js-carousel"))new k(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?R(function(){K()}):K(),q(),N(),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(){S({"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