blob: 0ba869ebba9b89ff984a8e5490078f0d49a05f08 [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 jumpDialog=document.querySelector(".JumpDialog"),jumpBody=jumpDialog==null?void 0:jumpDialog.querySelector(".JumpDialog-body"),jumpList=jumpDialog==null?void 0:jumpDialog.querySelector(".JumpDialog-list"),jumpFilter=jumpDialog==null?void 0:jumpDialog.querySelector(".JumpDialog-input"),doc=document.querySelector(".js-documentation");let jumpListItems;function collectJumpListItems(){const t=[];if(!!doc){for(const e of doc.querySelectorAll("[data-kind]"))t.push(newJumpListItem(e));for(const e of t)e.link.addEventListener("click",function(){jumpDialog==null||jumpDialog.close()});return t.sort(function(e,n){return e.lower.localeCompare(n.lower)}),t}}function newJumpListItem(t){var s;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 c=t.getAttribute("data-kind");return{link:e,name:n!=null?n:"",kind:c!=null?c:"",lower:(s=n==null?void 0:n.toLowerCase())!=null?s:""}}let lastFilterValue,activeJumpItem=-1;function updateJumpList(t){for(lastFilterValue=t,jumpListItems||(jumpListItems=collectJumpListItems()),setActiveJumpItem(-1);jumpList==null?void 0:jumpList.firstChild;)jumpList.firstChild.remove();if(t){const e=t.toLowerCase(),n=[],c=[],s=[],l=(o,i,r)=>o.name.substring(0,i)+"<b>"+o.name.substring(i,r)+"</b>"+o.name.substring(r);for(const o of jumpListItems!=null?jumpListItems:[]){const i=o.name.toLowerCase();if(i===e)o.link.innerHTML=l(o,0,o.name.length),n.push(o);else if(i.startsWith(e))o.link.innerHTML=l(o,0,t.length),c.push(o);else{const r=i.indexOf(e);r>-1&&(o.link.innerHTML=l(o,r,r+t.length),s.push(o))}}for(const o of n.concat(c).concat(s))jumpList==null||jumpList.appendChild(o.link)}else{if(!jumpListItems||jumpListItems.length===0){const e=document.createElement("i");e.innerHTML="There are no symbols on this page.",jumpList==null||jumpList.appendChild(e)}for(const e of jumpListItems!=null?jumpListItems:[])e.link.innerHTML=e.name+" <i>"+e.kind+"</i>",jumpList==null||jumpList.appendChild(e.link)}jumpBody&&(jumpBody.scrollTop=0),(jumpListItems==null?void 0:jumpListItems.length)&&jumpList&&jumpList.children.length>0&&setActiveJumpItem(0)}function setActiveJumpItem(t){const e=jumpList==null?void 0:jumpList.children;if(!(!e||!jumpBody)){if(activeJumpItem>=0&&e[activeJumpItem].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,c=n+e[t].clientHeight;n<jumpBody.scrollTop?jumpBody.scrollTop=n:c>jumpBody.scrollTop+jumpBody.clientHeight&&(jumpBody.scrollTop=c-jumpBody.clientHeight)}activeJumpItem=t}}function incActiveJumpItem(t){if(activeJumpItem<0)return;let e=activeJumpItem+t;e<0&&(e=0),setActiveJumpItem(e)}jumpFilter==null||jumpFilter.addEventListener("keyup",function(){jumpFilter.value.toUpperCase()!=lastFilterValue.toUpperCase()&&updateJumpList(jumpFilter.value)}),jumpFilter==null||jumpFilter.addEventListener("keydown",function(t){const e=38,n=40,c=13;switch(t.which){case e:incActiveJumpItem(-1),t.preventDefault();break;case n:incActiveJumpItem(1),t.preventDefault();break;case c:activeJumpItem>=0&&jumpList&&(jumpList.children[activeJumpItem].click(),t.preventDefault());break}});const shortcutsDialog=document.querySelector(".ShortcutsDialog");document.addEventListener("keypress",function(t){if((jumpDialog==null?void 0:jumpDialog.open)||(shortcutsDialog==null?void 0:shortcutsDialog.open))return;const e=t.target,n=e==null?void 0:e.tagName;if(n=="INPUT"||n=="SELECT"||n=="TEXTAREA"||(e==null?void 0:e.contentEditable)=="true"||t.metaKey||t.ctrlKey)return;switch(String.fromCharCode(t.which)){case"f":case"F":t.preventDefault(),jumpFilter&&(jumpFilter.value=""),jumpDialog==null||jumpDialog.showModal(),jumpFilter==null||jumpFilter.focus(),updateJumpList("");break;case"?":shortcutsDialog==null||shortcutsDialog.showModal();break}});const jumpOutlineInput=document.querySelector(".js-jumpToInput");jumpOutlineInput&&jumpOutlineInput.addEventListener("click",()=>{jumpFilter&&(jumpFilter.value=""),updateJumpList("")});
//# sourceMappingURL=jump.js.map