]> Cypherpunks repositories - gostls13.git/commitdiff
doc/godoc.js: put focus on div#page when necessary
authorShenghou Ma <minux.ma@gmail.com>
Tue, 16 Oct 2012 06:28:18 +0000 (14:28 +0800)
committerShenghou Ma <minux.ma@gmail.com>
Tue, 16 Oct 2012 06:28:18 +0000 (14:28 +0800)
so that keyboard navigation events are sent to div#page.

        Fixes #4233.

R=adg
CC=golang-dev
https://golang.org/cl/6652048

doc/godocs.js

index 7449efc22868df7034856ea078ba52240317273f..5d12da131f8037938a244a7ef111b0d912ac27a0 100644 (file)
@@ -163,6 +163,22 @@ function setupDropdownPlayground() {
   $('#menu').css('min-width', '+=60');
 }
 
+// fixFocus tries to put focus to div#page so that keyboard navigation works.
+function fixFocus() {
+  var page = $('div#page');
+  var topbar = $('div#topbar');
+  page.css('outline', 0); // disable outline when focused
+  page.attr('tabindex', -1); // and set tabindex so that it is focusable
+  $(window).resize(function (evt) {
+    // only focus page when the topbar is at fixed position (that is, it's in
+    // front of page, and keyboard event will go to the former by default.)
+    // by focusing page, keyboard event will go to page so that up/down arrow,
+    // space, etc. will work as expected.
+    if (topbar.css('position') == "fixed")
+      page.focus();
+  }).resize();
+}
+
 $(document).ready(function() {
   bindSearchEvents();
   generateTOC();
@@ -173,6 +189,7 @@ $(document).ready(function() {
   bindToggleLinks(".examplesLink", "");
   bindToggleLinks(".indexLink", "");
   setupDropdownPlayground();
+  fixFocus();
 });
 
 })();