content,internal: disable jump to identifier if documentation only has overview

When the doc for a package does not contain an index
we disable the jump to identifier dialog. This change
prevents both the button in the sidebar and the k key
from opening the modal.

Change-Id: I48e17a4f57f066bf80fdc5452e900f9803ecf933
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/264199
Reviewed-by: Julie Qiu <julie@golang.org>
Trust: Jamal Carvalho <jamal@golang.org>
diff --git a/content/static/html/helpers/_unit_outline.tmpl b/content/static/html/helpers/_unit_outline.tmpl
index aea5f85..6521cb3 100644
--- a/content/static/html/helpers/_unit_outline.tmpl
+++ b/content/static/html/helpers/_unit_outline.tmpl
@@ -7,7 +7,7 @@
 {{define "unit_outline"}}
   <div class="UnitOutline js-accordion">
     <div class="UnitOutline-jumpTo">
-      <button class="UnitOutline-jumpToInput js-jumpToInput"{{if (not .DocOutline.String)}} disabled{{end}}>
+      <button class="UnitOutline-jumpToInput js-jumpToInput">
         Jump to
       </button>
     </div>
diff --git a/content/static/js/jump.js b/content/static/js/jump.js
index bd6bf6b..14e64a8 100644
--- a/content/static/js/jump.js
+++ b/content/static/js/jump.js
@@ -28,6 +28,7 @@
 const jumpFilter = jumpDialog.querySelector('.JumpDialog-input');
 const searchInput = document.querySelector('.js-searchFocus');
 const doc = document.querySelector('.js-documentation');
+const docIndex = document.querySelector('.js-docIndex');
 
 if (!jumpDialog.showModal) {
   dialogPolyfill.registerDialog(jumpDialog);
@@ -275,7 +276,7 @@
     case 'F':
       e.preventDefault();
       jumpFilter.value = '';
-      jumpDialog.showModal();
+      showJumpDialogModal();
       updateJumpList('');
       break;
     case '?':
@@ -296,7 +297,18 @@
 if (jumpOutlineInput) {
   jumpOutlineInput.addEventListener('click', () => {
     jumpFilter.value = '';
-    jumpDialog.showModal();
+    showJumpDialogModal();
     updateJumpList('');
   });
+  // If the doc does not contain an index disable the button.
+  if (!docIndex) {
+    jumpOutlineInput.setAttribute('disabled', true);
+  }
+}
+
+function showJumpDialogModal() {
+  // If the doc does not contain an index do not open the modal.
+  if (docIndex) {
+    jumpDialog.showModal();
+  }
 }
diff --git a/content/static/js/jump.min.js b/content/static/js/jump.min.js
index 10f89e0..b425d14 100644
--- a/content/static/js/jump.min.js
+++ b/content/static/js/jump.min.js
@@ -32,7 +32,7 @@
 (this.zIndexHigh_-this.zIndexLow_)/2-1)return!1;1===this.pendingDialogStack.unshift(a)&&this.blockDocument();this.updateStacking();return!0};k.DialogManager.prototype.removeDialog=function(a){a=this.pendingDialogStack.indexOf(a);-1!==a&&(this.pendingDialogStack.splice(a,1),0===this.pendingDialogStack.length&&this.unblockDocument(),this.updateStacking())};k.dm=new k.DialogManager;k.formSubmitter=null;k.useValue=null;if(void 0===window.HTMLDialogElement){var q=document.createElement("form");q.setAttribute("method",
 "dialog");if("dialog"!==q.method&&(q=Object.getOwnPropertyDescriptor(HTMLFormElement.prototype,"method"))){var u=q.get;q.get=function(){return f(this)?"dialog":u.call(this)};var v=q.set;q.set=function(a){return"string"===typeof a&&"dialog"===a.toLowerCase()?this.setAttribute("method",a):v.call(this,a)};Object.defineProperty(HTMLFormElement.prototype,"method",q)}document.addEventListener("click",function(a){k.formSubmitter=null;k.useValue=null;if(!a.defaultPrevented){var d=a.target;if(d&&f(d.form)){if(!("submit"===
 d.type&&-1<["button","input"].indexOf(d.localName))){if("input"!==d.localName||"image"!==d.type)return;k.useValue=a.offsetX+","+a.offsetY}c(d)&&(k.formSubmitter=d)}}},!1);var w=HTMLFormElement.prototype.submit;HTMLFormElement.prototype.submit=function(){if(!f(this))return w.call(this);var a=c(this);a&&a.close()};document.addEventListener("submit",function(a){if(!a.defaultPrevented){var d=a.target;if(f(d)&&(a.preventDefault(),a=c(d))){var h=k.formSubmitter;h&&h.form===d?a.close(k.useValue||h.value):
-a.close();k.formSubmitter=null}}},!1)}return k});var jumpDialog=document.querySelector(".JumpDialog"),jumpBody=jumpDialog.querySelector(".JumpDialog-body"),jumpList=jumpDialog.querySelector(".JumpDialog-list"),jumpFilter=jumpDialog.querySelector(".JumpDialog-input"),searchInput=document.querySelector(".js-searchFocus"),doc=document.querySelector(".js-documentation");jumpDialog.showModal||dialogPolyfill.registerDialog(jumpDialog);var jumpListItems;
+a.close();k.formSubmitter=null}}},!1)}return k});var jumpDialog=document.querySelector(".JumpDialog"),jumpBody=jumpDialog.querySelector(".JumpDialog-body"),jumpList=jumpDialog.querySelector(".JumpDialog-list"),jumpFilter=jumpDialog.querySelector(".JumpDialog-input"),searchInput=document.querySelector(".js-searchFocus"),doc=document.querySelector(".js-documentation"),docIndex=document.querySelector(".js-docIndex");jumpDialog.showModal||dialogPolyfill.registerDialog(jumpDialog);var jumpListItems;
 function collectJumpListItems(){for(var b=[],c=$jscomp.makeIterator(doc.querySelectorAll("[data-kind]")),e=c.next();!e.done;e=c.next())b.push(newJumpListItem(e.value));0==b.length&&(b=collectJumpListItemsFallback(doc));c=$jscomp.makeIterator(b);for(e=c.next();!e.done;e=c.next())e.value.link.addEventListener("click",function(){jumpDialog.close()});b.sort(function(f,g){return f.lower.localeCompare(g.lower)});return b}
 function collectJumpListItemsFallback(b){var c=[],e={};b=$jscomp.makeIterator(b.querySelectorAll("*[id]"));for(var f=b.next();!f.done;f=b.next()){f=f.value;var g=f.getAttribute("id");!e[g]&&/^[^_][^-]*$/.test(g)&&(e[g]=!0,c.push(newJumpListItem(f)))}return c}
 function newJumpListItem(b){var c=document.createElement("a"),e=b.getAttribute("id");c.setAttribute("href","#"+e);c.setAttribute("tabindex","-1");var f=b.getAttribute("data-kind");f||(f=guessKind(b));return{link:c,name:e,kind:f,lower:e.toLowerCase()}}
@@ -41,5 +41,5 @@
 0;0<jumpList.children.length&&setActiveJumpItem(0)}function setActiveJumpItem(b){var c=jumpList.children;0<=activeJumpItem&&c[activeJumpItem].classList.remove("JumpDialog-active");b>=c.length&&(b=c.length-1);if(0<=b){c[b].classList.add("JumpDialog-active");var e=c[b].offsetTop-c[0].offsetTop;c=e+c[b].clientHeight;e<jumpBody.scrollTop?jumpBody.scrollTop=e:c>jumpBody.scrollTop+jumpBody.clientHeight&&(jumpBody.scrollTop=c-jumpBody.clientHeight)}activeJumpItem=b}
 function incActiveJumpItem(b){0>activeJumpItem||(b=activeJumpItem+b,0>b&&(b=0),setActiveJumpItem(b))}jumpFilter.addEventListener("keyup",function(b){jumpFilter.value.toUpperCase()!=lastFilterValue.toUpperCase()&&updateJumpList(jumpFilter.value)});jumpFilter.addEventListener("keydown",function(b){switch(b.which){case 38:incActiveJumpItem(-1);b.preventDefault();break;case 40:incActiveJumpItem(1);b.preventDefault();break;case 13:0<=activeJumpItem&&jumpList.children[activeJumpItem].click()}});
 var shortcutsDialog=document.querySelector(".ShortcutsDialog");shortcutsDialog.showModal||dialogPolyfill.registerDialog(shortcutsDialog);
-document.addEventListener("keypress",function(b){if(!jumpDialog.open&&!shortcutsDialog.open&&doc){var c=b.target.tagName;if("INPUT"!=c&&"SELECT"!=c&&"TEXTAREA"!=c&&!(b.target.contentEditable&&"true"==b.target.contentEditable||b.metaKey||b.ctrlKey))switch(String.fromCharCode(b.which)){case "f":case "F":b.preventDefault();jumpFilter.value="";jumpDialog.showModal();updateJumpList("");break;case "?":shortcutsDialog.showModal();break;case "/":searchInput&&!window.navigator.userAgent.includes("Firefox")&&
-(b.preventDefault(),searchInput.focus())}}});var jumpOutlineInput=document.querySelector(".js-jumpToInput");jumpOutlineInput&&jumpOutlineInput.addEventListener("click",function(){jumpFilter.value="";jumpDialog.showModal();updateJumpList("")});
+document.addEventListener("keypress",function(b){if(!jumpDialog.open&&!shortcutsDialog.open&&doc){var c=b.target.tagName;if("INPUT"!=c&&"SELECT"!=c&&"TEXTAREA"!=c&&!(b.target.contentEditable&&"true"==b.target.contentEditable||b.metaKey||b.ctrlKey))switch(String.fromCharCode(b.which)){case "f":case "F":b.preventDefault();jumpFilter.value="";showJumpDialogModal();updateJumpList("");break;case "?":shortcutsDialog.showModal();break;case "/":searchInput&&!window.navigator.userAgent.includes("Firefox")&&
+(b.preventDefault(),searchInput.focus())}}});var jumpOutlineInput=document.querySelector(".js-jumpToInput");jumpOutlineInput&&(jumpOutlineInput.addEventListener("click",function(){jumpFilter.value="";showJumpDialogModal();updateJumpList("")}),docIndex||jumpOutlineInput.setAttribute("disabled",!0));function showJumpDialogModal(){docIndex&&jumpDialog.showModal()};
diff --git a/internal/godoc/dochtml/template_body.go b/internal/godoc/dochtml/template_body.go
index e1ecf81..881b855 100644
--- a/internal/godoc/dochtml/template_body.go
+++ b/internal/godoc/dochtml/template_body.go
@@ -22,7 +22,7 @@
 
 
 {{- if or .Consts .Vars .Funcs .Types -}}
-	<section class="Documentation-index">
+	<section class="Documentation-index js-docIndex">
 		<h3 id="pkg-index" class="Documentation-indexHeader">Index <a href="#pkg-index">¶</a></h3>{{"\n\n" -}}
 		<ul class="Documentation-indexList">{{"\n" -}}
 			{{- if .Consts -}}<li class="Documentation-indexConstants"><a href="#pkg-constants">Constants</a></li>{{"\n"}}{{- end -}}