blob: 6d285e2d69001a08dae3cdeb6f2af5d03886d820 [file] [log] [blame]
function P(){let t=document.querySelector(".js-header");document.querySelectorAll(".js-desktop-menu-hover").forEach(a=>{a.addEventListener("mouseenter",c=>{let l=c.target,s=document.querySelector(".forced-open");s&&s!==a&&(s.blur(),s.classList.remove("forced-open")),l.classList.remove("forced-closed"),l.classList.add("forced-open")});let u=c=>{var f,p;let l=c.target,s=l==null?void 0:l.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(),(f=o==null?void 0:o.parentNode)==null||f.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")),(p=o==null?void 0:o.parentNode)==null||p.removeEventListener("mouseout",()=>{o.classList.remove("forced-closed")})),o.focus()};a.addEventListener("click",u),a.addEventListener("focus",c=>{let l=c.target;l.classList.add("forced-closed"),l.classList.remove("forced-open")});let d=c=>{let l=c,s=c.target;if(l.key==="Escape"){let o=document.querySelector(".forced-open");o&&(o.classList.remove("forced-open"),o.blur(),o.classList.add("forced-closed"),s==null||s.focus())}};document.addEventListener("keydown",d)});let n=document.querySelectorAll(".js-headerMenuButton");n.forEach(a=>{a.addEventListener("click",u=>{u.preventDefault();let d=t==null?void 0:t.classList.contains("is-active");d?v(t):w(t),a.setAttribute("aria-expanded",d?"true":"false")})});let i=document.querySelector(".js-scrim");i==null||i.addEventListener("click",a=>{a.preventDefault(),document.querySelectorAll(".go-NavigationDrawer-submenuItem.is-active").forEach(d=>v(d)),v(t),n.forEach(d=>{d.setAttribute("aria-expanded",t!=null&&t.classList.contains("is-active")?"true":"false")})});let r=a=>{if(!a)return[];let u=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")||[]),d=a.querySelector(".go-NavigationDrawer-header > a");return d&&u.unshift(d),u},h=a=>{if(a)return a.classList.contains("go-NavigationDrawer-submenuItem")},v=a=>{var c,l;if(!a)return;let u=r(a);a.classList.remove("is-active");let d=(c=a.closest(".go-NavigationDrawer-listItem"))==null?void 0:c.querySelector(":scope > a");d==null||d.focus(),u==null||u.forEach(s=>s==null?void 0:s.setAttribute("tabindex","-1")),u&&u[0]&&(u[0].removeEventListener("keydown",M(a)),u[u.length-1].removeEventListener("keydown",L(a))),a===t&&n&&((l=n[0])==null||l.focus())},w=a=>{let u=r(a);a.classList.add("is-active"),u.forEach(d=>d.setAttribute("tabindex","0")),u[0].focus(),u[0].addEventListener("keydown",M(a)),u[u.length-1].addEventListener("keydown",L(a))},M=a=>u=>{u.key==="Tab"&&u.shiftKey&&(u.preventDefault(),v(a))},L=a=>u=>{u.key==="Tab"&&!u.shiftKey&&(u.preventDefault(),v(a))},b=a=>{var c;let u=h(a),d=r(a);a.addEventListener("keyup",l=>{l.key==="Escape"&&v(a)}),d.forEach(l=>{let s=l.closest("li");if(s&&s.classList.contains("js-mobile-subnav-trigger")){let o=s.querySelector(".go-NavigationDrawer-submenuItem");l.addEventListener("click",()=>{w(o)})}}),u&&(v(a),(c=a==null?void 0:a.querySelector(".go-NavigationDrawer-header"))==null||c.addEventListener("click",l=>{l.preventDefault(),v(a)}))};document.querySelectorAll(".go-NavigationDrawer").forEach(a=>b(a)),v(t)}function U(){let t=document.querySelector(".js-searchForm"),e=document.querySelector(".js-expandSearch"),n=t==null?void 0:t.querySelector("input"),i=document.querySelector(".js-headerLogo"),r=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"),r==null||r.classList.add("go-Header-navOpen--hidden"),n==null||n.focus()}),document==null||document.addEventListener("click",h=>{t!=null&&t.contains(h.target)||(t==null||t.classList.remove("go-SearchForm--expanded"),i==null||i.classList.remove("go-Header-logo--hidden"),r==null||r.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"),r=document.createElement("button");r.classList.add("go-Carousel-dot"),n===this.activeIndex&&r.classList.add("go-Carousel-dot--active"),r.innerHTML=`<span class="go-Carousel-obscured">Slide ${n+1}</span>`,r.addEventListener("click",()=>this.setActive(n)),i.append(r),e.append(i),this.dots.push(r)}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,r,h,v;this.data=(n=e.dataset.toCopy)!=null?n:e.innerText,!this.data&&((i=e.parentElement)!=null&&i.classList.contains("go-InputGroup"))&&(this.data=(v=this.data||((h=(r=e.parentElement)==null?void 0:r.querySelector("input"))==null?void 0:h.value))!=null?v:""),e.addEventListener("click",w=>this.handleCopyClick(w))}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,r=i.value;i.value.startsWith("/")||(r="/"+r),window.location.href=r})}};var q=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 I(t,e,n,i){var r;(r=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 W(t){var e;(e=window.dataLayer)!=null||(window.dataLayer=[]),window.dataLayer.push(t)}var O=class{constructor(){this.handlers={},document.addEventListener("keydown",e=>this.handleKeyPress(e))}on(e,n,i,r){var h,v;return(v=(h=this.handlers)[e])!=null||(h[e]=new Set),this.handlers[e].add({description:n,callback:i,...r}),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 r=e.target;if(!i.target&&((r==null?void 0:r.tagName)==="INPUT"||(r==null?void 0:r.tagName)==="SELECT"||(r==null?void 0:r.tagName)==="TEXTAREA")||r!=null&&r.isContentEditable||i.withMeta&&!(e.ctrlKey||e.metaKey)||!i.withMeta&&(e.ctrlKey||e.metaKey))return;I("keypress","hotkeys",`${e.key} pressed`,i.description),i.callback(e)}}},H=new O;function $(){var l;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"),r=document.querySelector(".js-documentation"),h;function v(){let s=[];if(r){for(let o of r.querySelectorAll("[data-kind]"))s.push(w(o));for(let o of s)o.link.addEventListener("click",function(){t==null||t.close()});return s.sort(function(o,f){return o.lower.localeCompare(f.lower)}),s}}function w(s){var E;let o=document.createElement("a"),f=s.getAttribute("id");o.setAttribute("href","#"+f),o.setAttribute("tabindex","-1"),o.setAttribute("data-gtmc","jump to link");let p=s.getAttribute("data-kind");return{link:o,name:f!=null?f:"",kind:p!=null?p:"",lower:(E=f==null?void 0:f.toLowerCase())!=null?E:""}}let M,L=-1;function b(s){for(M=s,h||(h=v()),a(-1);n!=null&&n.firstChild;)n.firstChild.remove();if(s){let o=s.toLowerCase(),f=[],p=[],E=[],S=(g,y,T)=>g.name.substring(0,y)+"<b>"+g.name.substring(y,T)+"</b>"+g.name.substring(T);for(let g of h!=null?h:[]){let y=g.name.toLowerCase();if(y===o)g.link.innerHTML=S(g,0,g.name.length),f.push(g);else if(y.startsWith(o))g.link.innerHTML=S(g,0,s.length),p.push(g);else{let T=y.indexOf(o);T>-1&&(g.link.innerHTML=S(g,T,T+s.length),E.push(g))}}for(let g of f.concat(p).concat(E))n==null||n.appendChild(g.link)}else{if(!h||h.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 h!=null?h:[])o.link.innerHTML=o.name+" <i>"+o.kind+"</i>",n==null||n.appendChild(o.link)}e&&(e.scrollTop=0),h!=null&&h.length&&n&&n.children.length>0&&a(0)}function a(s){let o=n==null?void 0:n.children;if(!(!o||!e)){if(L>=0&&o[L].classList.remove("JumpDialog-active"),s>=o.length&&(s=o.length-1),s>=0){o[s].classList.add("JumpDialog-active");let f=o[s].offsetTop-o[0].offsetTop,p=f+o[s].clientHeight;f<e.scrollTop?e.scrollTop=f:p>e.scrollTop+e.clientHeight&&(e.scrollTop=p-e.clientHeight)}L=s}}function u(s){if(L<0)return;let o=L+s;o<0&&(o=0),a(o)}i==null||i.addEventListener("keyup",function(){i.value.toUpperCase()!=M.toUpperCase()&&b(i.value)}),i==null||i.addEventListener("keydown",function(s){switch(s.which){case 38:u(-1),s.preventDefault();break;case 40:u(1),s.preventDefault();break;case 13:L>=0&&n&&(n.children[L].click(),s.preventDefault());break}});let d=document.querySelector(".ShortcutsDialog");H.on("f","open jump to modal",s=>{var o;t!=null&&t.open||d!=null&&d.open||(s.preventDefault(),i&&(i.value=""),(o=t==null?void 0:t.showModal)==null||o.call(t),i==null||i.focus(),b(""))}).on("?","open shortcuts modal",()=>{var s;t!=null&&t.open||d!=null&&d.open||(s=d==null?void 0:d.showModal)==null||s.call(d)});let c=document.querySelector(".js-jumpToInput");c&&c.addEventListener("click",()=>{var s;i&&(i.value=""),b(""),!(t!=null&&t.open||d!=null&&d.open)&&((s=t==null?void 0:t.showModal)==null||s.call(t),i==null||i.focus())}),(l=document.querySelector(".js-openShortcuts"))==null||l.addEventListener("click",()=>{var s;(s=d==null?void 0:d.showModal)==null||s.call(d)})}var G=async function(){if(!["/about"].includes(window.location.pathname))return;let e="h2, h3, h4",n=".LeftNav a",i=document.querySelector(".LeftNav"),r=document.querySelector(".go-Content"),h=!1;function v(c="",l={},...s){if(!c)throw new Error("Provide `type` to create document element.");let o=Object.assign(document.createElement(c),l);return s.forEach(f=>{typeof f=="string"?o.appendChild(document.createTextNode(f)):Array.isArray(f)?f.forEach(p=>o.appendChild(p)):f instanceof HTMLElement&&o.appendChild(f)}),o}function w(){return new Promise((c,l)=>{var f,p,E,S,g,y,T,J,R,_;let s=[],o=[];if(!r||!i)return l(".SiteContent not found.");if(i instanceof HTMLElement&&!((f=i==null?void 0:i.dataset)!=null&&f.hydrate))return c(!0);for(let m of r.querySelectorAll(e))if(m instanceof HTMLElement&&!((p=m==null?void 0:m.dataset)!=null&&p.ignore))switch(m.tagName){case"H2":s=[...s,{id:m.id,label:(E=m==null?void 0:m.dataset)!=null&&E.title?m.dataset.title:(S=m.textContent)!=null?S:""}];break;case"H3":case"H4":(g=s[s.length-1])!=null&&g.subnav?s[s.length-1].subnav&&((_=s[s.length-1].subnav)==null||_.push({id:m.id,label:(J=m==null?void 0:m.dataset)!=null&&J.title?m.dataset.title:(R=m.textContent)!=null?R:""})):s[s.length-1].subnav=[{id:m.id,label:(y=m==null?void 0:m.dataset)!=null&&y.title?m.dataset.title:(T=m.textContent)!=null?T:""}];break}for(let m of s){let V=v("a",{href:"#"+m.id},v("span",{},m.label));if(o=[...o,V],m!=null&&m.subnav){let N=[];for(let K of m.subnav){let z=v("li",{},v("a",{href:"#"+K.id},v("img",{src:"/static/frontend/about/dot.svg",width:"5",height:"5"}),v("span",{},K.label)));N=[...N,z]}let X=v("ul",{className:"LeftSubnav"},N);o=[...o,X]}}return o.forEach(m=>i.appendChild(m)),c(!0)})}function M(){return new Promise(c=>{if(!document.querySelectorAll(n))return c(!0);for(let l of document.querySelectorAll(n))if(l instanceof HTMLAnchorElement&&l.href===location.href){b(l);break}c(!0)})}function L(){return new Promise(c=>{if(!document.querySelectorAll(n))return c(!0);for(let l of document.querySelectorAll(n))l.classList.remove("active");c(!0)})}function b(c){c instanceof HTMLAnchorElement&&L().then(()=>{var s,o,f;c.classList.add("active");let l=(s=c==null?void 0:c.parentNode)==null?void 0:s.parentNode;l instanceof HTMLElement&&((o=l==null?void 0:l.classList)!=null&&o.contains("LeftSubnav"))&&((f=l.previousElementSibling)==null||f.classList.add("active"))})}function a(){u();let c=document.querySelector('[href="'+location.hash+'"]');c instanceof HTMLAnchorElement&&b(c)}function u(){h=!0,setTimeout(()=>{h=!1},200)}function d(){var c;if(window.addEventListener("hashchange",a),r!=null&&r.querySelectorAll(e)){let l=o=>{if(!h&&Array.isArray(o)&&o.length>0){for(let f of o)if(f.isIntersecting&&f.target instanceof HTMLElement){let{id:p}=f.target,E=document.querySelector('[href="#'+p+'"]');E instanceof HTMLAnchorElement&&b(E);break}}},s=new IntersectionObserver(l,{threshold:0,rootMargin:"0px 0px -50% 0px"});for(let o of r.querySelectorAll(e))o instanceof HTMLElement&&!((c=o==null?void 0:o.dataset)!=null&&c.ignore)&&s.observe(o)}}try{await w(),await M(),location.hash&&u(),d()}catch(c){c instanceof Error?console.error(c.message):console.error(c)}};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 q(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",()=>{Y()});(t=document.querySelector(".js-gtmID"))!=null&&t.dataset.gtmid&&window.dataLayer?W(function(){B()}):B(),P(),U(),$(),G(),Z()});H.on("/","focus search",t=>{let e=Array.from(document.querySelectorAll(".js-searchFocus")).pop();e&&!window.navigator.userAgent.includes("Firefox")&&(t.preventDefault(),e.focus())});H.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(){I({"gtm.start":new Date().getTime(),event:"gtm.js"})})();function B(){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 Y(){let t="dark",e=document.documentElement.getAttribute("data-theme");e==="dark"?t="light":e==="light"&&(t="auto");let n="";(location.hostname==="go.dev"||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;`}function Z(){if(!document.cookie.match(/cookie-consent=true/)){let e=document.querySelector(".js-cookieNotice"),n=e==null?void 0:e.querySelector("button");e==null||e.classList.add("Cookie-notice--visible"),n==null||n.addEventListener("click",()=>{let i="";(location.hostname==="go.dev"||location.hostname.endsWith(".go.dev"))&&(i="domain=.go.dev;"),document.cookie=`cookie-consent=true;${i}path=/;max-age=31536000`,e==null||e.remove()})}}
/**
* @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.
*/
/*!
* @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 2022 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.
*/
//# sourceMappingURL=frontend.js.map