blob: 85c10f925765efde04f669fc4498404a7d88bd29 [file] [log] [blame]
function q(){let n=document.querySelector(".js-header");document.querySelectorAll(".js-desktop-menu-hover").forEach(s=>{s.addEventListener("mouseenter",r=>{let i=r.target,t=document.querySelector(".forced-open");t&&t!==s&&(t.blur(),t.classList.remove("forced-open")),i.focus(),i.blur()});let c=r=>{let t=r.target?.classList.contains("forced-open"),a=r.currentTarget;t?(a.removeEventListener("blur",()=>a.classList.remove("forced-open")),a.classList.remove("forced-open"),a.classList.add("forced-closed"),a.blur(),a?.parentNode?.addEventListener("mouseout",()=>{a.classList.remove("forced-closed")})):(a.classList.remove("forced-closed"),a.classList.add("forced-open"),a.focus(),a.addEventListener("blur",()=>a.classList.remove("forced-open")),a?.parentNode?.removeEventListener("mouseout",()=>{a.classList.remove("forced-closed")}))};s.addEventListener("click",c)}),document.querySelectorAll(".Header-menuItem").forEach(s=>{s.addEventListener("keyup",c=>{let r=c;r.key==="Escape"&&r.target?.blur()})});let l=document.querySelectorAll(".js-headerMenuButton");l.forEach(s=>{s.addEventListener("click",c=>{c.preventDefault();let r=n?.classList.contains("is-active");r?h(n):y(n),s.setAttribute("aria-expanded",r?"true":"false")})}),document.querySelector(".js-scrim")?.addEventListener("click",s=>{s.preventDefault(),document.querySelectorAll(".go-NavigationDrawer-submenuItem.is-active").forEach(r=>h(r)),h(n),l.forEach(r=>{r.setAttribute("aria-expanded",n?.classList.contains("is-active")?"true":"false")})});let f=s=>{if(!s)return[];let c=Array.from(s.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")||[]),r=s.querySelector(".go-NavigationDrawer-header > a");return r&&c.unshift(r),c},g=s=>{if(s)return s.classList.contains("go-NavigationDrawer-submenuItem")},h=s=>{if(!s)return;let c=f(s);s.classList.remove("is-active"),s.closest(".go-NavigationDrawer-listItem")?.querySelector(":scope > a")?.focus(),c?.forEach(i=>i?.setAttribute("tabindex","-1")),c&&c[0]&&(c[0].removeEventListener("keydown",p(s)),c[c.length-1].removeEventListener("keydown",v(s))),s===n&&l&&l[0]?.focus()},y=s=>{let c=f(s);s.classList.add("is-active"),c.forEach(r=>r.setAttribute("tabindex","0")),c[0].focus(),c[0].addEventListener("keydown",p(s)),c[c.length-1].addEventListener("keydown",v(s))},p=s=>c=>{c.key==="Tab"&&c.shiftKey&&(c.preventDefault(),h(s))},v=s=>c=>{c.key==="Tab"&&!c.shiftKey&&(c.preventDefault(),h(s))},T=s=>{let c=g(s),r=f(s);s.addEventListener("keyup",i=>{i.key==="Escape"&&h(s)}),r.forEach(i=>{let t=i.closest("li");if(t&&t.classList.contains("js-mobile-subnav-trigger")){let a=t.querySelector(".go-NavigationDrawer-submenuItem");i.addEventListener("click",()=>{y(a)})}}),c&&(h(s),s?.querySelector(".go-NavigationDrawer-header")?.addEventListener("click",i=>{i.preventDefault(),h(s)}))};document.querySelectorAll(".go-NavigationDrawer").forEach(s=>T(s)),h(n)}function N(){let n=document.querySelector(".js-searchForm"),e=document.querySelector(".js-expandSearch"),o=n?.querySelector("input"),l=document.querySelector(".js-headerLogo"),u=document.querySelector(".js-headerMenuButton");e?.addEventListener("click",()=>{n?.classList.add("go-SearchForm--expanded"),l?.classList.add("go-Header-logo--hidden"),u?.classList.add("go-Header-navOpen--hidden"),o?.focus()}),document?.addEventListener("click",f=>{n?.contains(f.target)||(n?.classList.remove("go-SearchForm--expanded"),l?.classList.remove("go-Header-logo--hidden"),u?.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 o of this.dots)o.classList.remove("go-Carousel-dot--active");this.dots[this.activeIndex].classList.add("go-Carousel-dot--active");for(let o of this.slides)o.setAttribute("aria-hidden","true");this.slides[this.activeIndex].removeAttribute("aria-hidden"),this.liveRegion.textContent="Slide "+(this.activeIndex+1)+" of "+this.slides.length};this.slides=Array.from(e.querySelectorAll(".go-Carousel-slide")),this.dots=[],this.liveRegion=document.createElement("div"),this.activeIndex=Number(e.getAttribute("data-slide-index")??0),this.initSlides(),this.initArrows(),this.initDots(),this.initLiveRegion()}initSlides(){for(let[e,o]of this.slides.entries())e!==this.activeIndex&&o.setAttribute("aria-hidden","true")}initArrows(){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>
`,e.querySelector(".go-Carousel-prevSlide")?.addEventListener("click",()=>this.setActive(this.activeIndex-1)),e.querySelector(".go-Carousel-nextSlide")?.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 o=0;o<this.slides.length;o++){let l=document.createElement("li"),u=document.createElement("button");u.classList.add("go-Carousel-dot"),o===this.activeIndex&&u.classList.add("go-Carousel-dot--active"),u.innerHTML=`<span class="go-Carousel-obscured">Slide ${o+1}</span>`,u.addEventListener("click",()=>this.setActive(o)),l.append(u),e.append(l),this.dots.push(u)}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 k=class{constructor(e){this.el=e;this.data=e.dataset.toCopy??e.innerText,!this.data&&e.parentElement?.classList.contains("go-InputGroup")&&(this.data=(this.data||e.parentElement?.querySelector("input")?.value)??""),e.addEventListener("click",o=>this.handleCopyClick(o))}handleCopyClick(e){e.preventDefault();let o=1e3;if(!navigator.clipboard){this.showTooltipText("Unable to copy",o);return}navigator.clipboard.writeText(this.data).then(()=>{this.showTooltipText("Copied!",o)}).catch(()=>{this.showTooltipText("Unable to copy",o)})}showTooltipText(e,o){this.el.setAttribute("data-tooltip",e),setTimeout(()=>this.el.setAttribute("data-tooltip",""),o)}};var H=class{constructor(e){this.el=e;document.addEventListener("click",o=>{this.el.contains(o.target)||this.el.removeAttribute("open")})}};var A=class{constructor(e){this.el=e;this.el.addEventListener("change",o=>{let l=o.target,u=l.value;l.value.startsWith("/")||(u="/"+u),window.location.href=u})}};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",()=>{this.el.showModal?this.el.showModal():this.el.setAttribute("opened","true"),this.el.querySelector("input")?.focus()});for(let o of this.el.querySelectorAll("[data-modal-close]"))o.addEventListener("click",()=>{this.el.close?this.el.close():this.el.removeAttribute("opened")})}};function I(n,e,o,l){window.dataLayer??=[],typeof n=="string"?window.dataLayer.push({event:n,event_category:e,event_action:o,event_label:l}):window.dataLayer.push(n)}function D(n){window.dataLayer??=[],window.dataLayer.push(n)}var C=class{constructor(){this.handlers={},document.addEventListener("keydown",e=>this.handleKeyPress(e))}on(e,o,l,u){return this.handlers[e]??=new Set,this.handlers[e].add({description:o,callback:l,...u}),this}handleKeyPress(e){for(let o of this.handlers[e.key.toLowerCase()]??new Set){if(o.target&&o.target!==e.target)return;let l=e.target;if(!o.target&&(l?.tagName==="INPUT"||l?.tagName==="SELECT"||l?.tagName==="TEXTAREA")||l?.isContentEditable||o.withMeta&&!(e.ctrlKey||e.metaKey)||!o.withMeta&&(e.ctrlKey||e.metaKey))return;I("keypress","hotkeys",`${e.key} pressed`,o.description),o.callback(e)}}},M=new C;function j(){let n=document.querySelector(".JumpDialog"),e=n?.querySelector(".JumpDialog-body"),o=n?.querySelector(".JumpDialog-list"),l=n?.querySelector(".JumpDialog-input"),u=document.querySelector(".js-documentation"),f;function g(){let i=[];if(u){for(let t of u.querySelectorAll("[data-kind]"))i.push(h(t));for(let t of i)t.link.addEventListener("click",function(){n?.close()});return i.sort(function(t,a){return t.lower.localeCompare(a.lower)}),i}}function h(i){let t=document.createElement("a"),a=i.getAttribute("id");t.setAttribute("href","#"+a),t.setAttribute("tabindex","-1"),t.setAttribute("data-gtmc","jump to link");let d=i.getAttribute("data-kind");return{link:t,name:a??"",kind:d??"",lower:a?.toLowerCase()??""}}let y,p=-1;function v(i){for(y=i,f||(f=g()),T(-1);o?.firstChild;)o.firstChild.remove();if(i){let t=i.toLowerCase(),a=[],d=[],L=[],w=(m,E,b)=>m.name.substring(0,E)+"<b>"+m.name.substring(E,b)+"</b>"+m.name.substring(b);for(let m of f??[]){let E=m.name.toLowerCase();if(E===t)m.link.innerHTML=w(m,0,m.name.length),a.push(m);else if(E.startsWith(t))m.link.innerHTML=w(m,0,i.length),d.push(m);else{let b=E.indexOf(t);b>-1&&(m.link.innerHTML=w(m,b,b+i.length),L.push(m))}}for(let m of a.concat(d).concat(L))o?.appendChild(m.link)}else{if(!f||f.length===0){let t=document.createElement("i");t.innerHTML="There are no symbols on this page.",o?.appendChild(t)}for(let t of f??[])t.link.innerHTML=t.name+" <i>"+t.kind+"</i>",o?.appendChild(t.link)}e&&(e.scrollTop=0),f?.length&&o&&o.children.length>0&&T(0)}function T(i){let t=o?.children;if(!(!t||!e)){if(p>=0&&t[p].classList.remove("JumpDialog-active"),i>=t.length&&(i=t.length-1),i>=0){t[i].classList.add("JumpDialog-active");let a=t[i].offsetTop-t[0].offsetTop,d=a+t[i].clientHeight;a<e.scrollTop?e.scrollTop=a:d>e.scrollTop+e.clientHeight&&(e.scrollTop=d-e.clientHeight)}p=i}}function s(i){if(p<0)return;let t=p+i;t<0&&(t=0),T(t)}l?.addEventListener("keyup",function(){l.value.toUpperCase()!=y.toUpperCase()&&v(l.value)}),l?.addEventListener("keydown",function(i){switch(i.which){case 38:s(-1),i.preventDefault();break;case 40:s(1),i.preventDefault();break;case 13:p>=0&&o&&(o.children[p].click(),i.preventDefault());break}});let c=document.querySelector(".ShortcutsDialog");M.on("f","open jump to modal",i=>{n?.open||c?.open||(i.preventDefault(),l&&(l.value=""),n?.showModal?.(),l?.focus(),v(""))}).on("?","open shortcuts modal",()=>{n?.open||c?.open||c?.showModal?.()});let r=document.querySelector(".js-jumpToInput");r&&r.addEventListener("click",()=>{l&&(l.value=""),v(""),!(n?.open||c?.open)&&(n?.showModal?.(),l?.focus())}),document.querySelector(".js-openShortcuts")?.addEventListener("click",()=>{c?.showModal?.()})}var O=async function(){if(!["/about"].includes(window.location.pathname))return;let e="h2, h3, h4",o=".LeftNav a",l=document.querySelector(".LeftNav"),u=document.querySelector(".go-Content"),f=!1;function g(r="",i={},...t){if(!r)throw new Error("Provide `type` to create document element.");let a=Object.assign(document.createElement(r),i);return t.forEach(d=>{typeof d=="string"?a.appendChild(document.createTextNode(d)):Array.isArray(d)?d.forEach(L=>a.appendChild(L)):d instanceof HTMLElement&&a.appendChild(d)}),a}function h(){return new Promise((r,i)=>{let t=[],a=[];if(!u||!l)return i(".SiteContent not found.");if(l instanceof HTMLElement&&!l?.dataset?.hydrate)return r(!0);for(let d of u.querySelectorAll(e))if(d instanceof HTMLElement&&!d?.dataset?.ignore)switch(d.tagName){case"H2":t=[...t,{id:d.id,label:d?.dataset?.title?d.dataset.title:d.textContent??""}];break;case"H3":case"H4":t[t.length-1]?.subnav?t[t.length-1].subnav&&t[t.length-1].subnav?.push({id:d.id,label:d?.dataset?.title?d.dataset.title:d.textContent??""}):t[t.length-1].subnav=[{id:d.id,label:d?.dataset?.title?d.dataset.title:d.textContent??""}];break}for(let d of t){let L=g("a",{href:"#"+d.id},g("span",{},d.label));if(a=[...a,L],d?.subnav){let w=[];for(let E of d.subnav){let b=g("li",{},g("a",{href:"#"+E.id},g("img",{src:"/static/frontend/about/dot.svg",width:"5",height:"5"}),g("span",{},E.label)));w=[...w,b]}let m=g("ul",{className:"LeftSubnav"},w);a=[...a,m]}}return a.forEach(d=>l.appendChild(d)),r(!0)})}function y(){return new Promise(r=>{if(!document.querySelectorAll(o))return r(!0);for(let i of document.querySelectorAll(o))if(i instanceof HTMLAnchorElement&&i.href===location.href){v(i);break}r(!0)})}function p(){return new Promise(r=>{if(!document.querySelectorAll(o))return r(!0);for(let i of document.querySelectorAll(o))i.classList.remove("active");r(!0)})}function v(r){r instanceof HTMLAnchorElement&&p().then(()=>{r.classList.add("active");let i=r?.parentNode?.parentNode;i instanceof HTMLElement&&i?.classList?.contains("LeftSubnav")&&i.previousElementSibling?.classList.add("active")})}function T(){s();let r=document.querySelector('[href="'+location.hash+'"]');r instanceof HTMLAnchorElement&&v(r)}function s(){f=!0,setTimeout(()=>{f=!1},200)}function c(){if(window.addEventListener("hashchange",T),u?.querySelectorAll(e)){let r=t=>{if(!f&&Array.isArray(t)&&t.length>0){for(let a of t)if(a.isIntersecting&&a.target instanceof HTMLElement){let{id:d}=a.target,L=document.querySelector('[href="#'+d+'"]');L instanceof HTMLAnchorElement&&v(L);break}}},i=new IntersectionObserver(r,{threshold:0,rootMargin:"0px 0px -50% 0px"});for(let t of u.querySelectorAll(e))t instanceof HTMLElement&&!t?.dataset?.ignore&&i.observe(t)}}try{await h(),await y(),location.hash&&s(),c()}catch(r){r instanceof Error?console.error(r.message):console.error(r)}};window.addEventListener("load",()=>{for(let n of document.querySelectorAll(".js-clipboard"))new k(n);for(let n of document.querySelectorAll(".js-modal"))new x(n);for(let n of document.querySelectorAll(".js-tooltip"))new H(n);for(let n of document.querySelectorAll(".js-selectNav"))new A(n);for(let n of document.querySelectorAll(".js-carousel"))new S(n);for(let n of document.querySelectorAll(".js-toggleTheme"))n.addEventListener("click",()=>{_()});document.querySelector(".js-gtmID")?.dataset.gtmid&&window.dataLayer?D(function(){J()}):J(),q(),N(),j(),O(),K()});M.on("/","focus search",n=>{let e=Array.from(document.querySelectorAll(".js-searchFocus")).pop();e&&!window.navigator.userAgent.includes("Firefox")&&(n.preventDefault(),e.focus())});M.on("y","set canonical url",()=>{let n=document.querySelector(".js-canonicalURLPath")?.dataset.canonicalUrlPath;if(n&&n!==""){let e=window.location.hash;e&&(n+=e),window.history.replaceState(null,"",n)}});(function(){I({"gtm.start":new Date().getTime(),event:"gtm.js"})})();function J(){let n=new URLSearchParams(window.location.search),e=n.get("utm_source");if(e!=="gopls"&&e!=="godoc"&&e!=="pkggodev")return;let o=new URL(window.location.href);n.delete("utm_source"),o.search=n.toString(),window.history.replaceState(null,"",o.toString())}function _(){let n="dark",e=document.documentElement.getAttribute("data-theme");e==="dark"?n="light":e==="light"&&(n="auto");let o="";location.hostname.endsWith("go.dev")&&(o="domain=.go.dev;"),document.documentElement.setAttribute("data-theme",n),document.cookie=`prefers-color-scheme=${n};${o}path=/;max-age=31536000;`}function K(){if(!document.cookie.match(/cookie-consent=true/)){let e=document.querySelector(".js-cookieNotice"),o=e?.querySelector("button");e?.classList.add("Cookie-notice--visible"),o?.addEventListener("click",()=>{let l="";location.hostname.endsWith("go.dev")&&(l="domain=.go.dev;"),document.cookie=`cookie-consent=true;${l}path=/;max-age=31536000`,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