blob: 04d9ed70564f784c7cd6ac7dbbdeaa1084e85a74 [file] [log] [blame]
/*!
* @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.
*/const c=document.querySelector(".JumpDialog"),f=c==null?void 0:c.querySelector(".JumpDialog-body"),o=c==null?void 0:c.querySelector(".JumpDialog-list"),s=c==null?void 0:c.querySelector(".JumpDialog-input"),k=document.querySelector(".js-documentation");let l;function E(){const t=[];if(!!k){for(const e of k.querySelectorAll("[data-kind]"))t.push(M(e));for(const e of t)e.link.addEventListener("click",function(){c==null||c.close()});return t.sort(function(e,n){return e.lower.localeCompare(n.lower)}),t}}function M(t){var a;const e=document.createElement("a"),n=t.getAttribute("id");e.setAttribute("href","#"+n),e.setAttribute("tabindex","-1"),e.setAttribute("data-gtmc","jump to link");const i=t.getAttribute("data-kind");return{link:e,name:n!=null?n:"",kind:i!=null?i:"",lower:(a=n==null?void 0:n.toLowerCase())!=null?a:""}}let v,u=-1;function p(t){for(v=t,l||(l=E()),T(-1);o==null?void 0:o.firstChild;)o.firstChild.remove();if(t){const e=t.toLowerCase(),n=[],i=[],a=[],d=(r,h,m)=>r.name.substring(0,h)+"<b>"+r.name.substring(h,m)+"</b>"+r.name.substring(m);for(const r of l!=null?l:[]){const h=r.name.toLowerCase();if(h===e)r.link.innerHTML=d(r,0,r.name.length),n.push(r);else if(h.startsWith(e))r.link.innerHTML=d(r,0,t.length),i.push(r);else{const m=h.indexOf(e);m>-1&&(r.link.innerHTML=d(r,m,m+t.length),a.push(r))}}for(const r of n.concat(i).concat(a))o==null||o.appendChild(r.link)}else{if(!l||l.length===0){const e=document.createElement("i");e.innerHTML="There are no symbols on this page.",o==null||o.appendChild(e)}for(const e of l!=null?l:[])e.link.innerHTML=e.name+" <i>"+e.kind+"</i>",o==null||o.appendChild(e.link)}f&&(f.scrollTop=0),(l==null?void 0:l.length)&&o&&o.children.length>0&&T(0)}function T(t){const e=o==null?void 0:o.children;if(!(!e||!f)){if(u>=0&&e[u].classList.remove("JumpDialog-active"),t>=e.length&&(t=e.length-1),t>=0){e[t].classList.add("JumpDialog-active");const n=e[t].offsetTop-e[0].offsetTop,i=n+e[t].clientHeight;n<f.scrollTop?f.scrollTop=n:i>f.scrollTop+f.clientHeight&&(f.scrollTop=i-f.clientHeight)}u=t}}function L(t){if(u<0)return;let e=u+t;e<0&&(e=0),T(e)}function b(){s==null||s.addEventListener("keyup",function(){s.value.toUpperCase()!=v.toUpperCase()&&p(s.value)}),s==null||s.addEventListener("keydown",function(n){const i=38,a=40,d=13;switch(n.which){case i:L(-1),n.preventDefault();break;case a:L(1),n.preventDefault();break;case d:u>=0&&o&&(o.children[u].click(),n.preventDefault());break}});const t=document.querySelector(".ShortcutsDialog");document.addEventListener("keypress",function(n){if((c==null?void 0:c.open)||(t==null?void 0:t.open))return;const i=n.target,a=i==null?void 0:i.tagName;if(a=="INPUT"||a=="SELECT"||a=="TEXTAREA"||(i==null?void 0:i.contentEditable)=="true"||n.metaKey||n.ctrlKey)return;switch(String.fromCharCode(n.which)){case"f":case"F":n.preventDefault(),s&&(s.value=""),c==null||c.showModal(),s==null||s.focus(),p("");break;case"?":t==null||t.showModal();break}});const e=document.querySelector(".js-jumpToInput");e&&e.addEventListener("click",()=>{s&&(s.value=""),p("")})}export{b as initModals};
//# sourceMappingURL=jump.js.map