From 1b80100dffc2e3bcab2ac7825d2ec7fcfbd941fb Mon Sep 17 00:00:00 2001 From: Timotheus Kampik Date: Sun, 4 Oct 2015 19:44:17 +0200 Subject: [PATCH 1/4] HTML doc: navigate with left/right arrow keys Adjusted basic theme's JS accordingly --- AUTHORS | 2 +- CHANGES | 1 + sphinx/themes/basic/static/doctools.js | 25 +++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index c31cb6976..c823072bb 100644 --- a/AUTHORS +++ b/AUTHORS @@ -28,7 +28,7 @@ Other contributors, listed alphabetically, are: * Horst Gutmann -- internationalization support * Martin Hans -- autodoc improvements * Doug Hellmann -- graphviz improvements -* Timotheus Kampik - stop words language fix +* Timotheus Kampik - JS enhancements, stop words language fix * Takeshi Komiya -- numref feature * Dave Kuhlman -- original LaTeX writer * Blaise Laflamme -- pyramid theme diff --git a/CHANGES b/CHANGES index a0ac757d3..7b637443f 100644 --- a/CHANGES +++ b/CHANGES @@ -14,6 +14,7 @@ Features added * C++ type alias support (e.g., ``.. type:: T = int``) * C++ template support for classes, functions, type aliases, and variables (#1729, #1314). * C++, added new scope management directives ``namespace-push`` and ``namespace-pop``. +* #1970: Keyboard shortcuts to navigate Next and Previous topics Bugs fixed ---------- diff --git a/sphinx/themes/basic/static/doctools.js b/sphinx/themes/basic/static/doctools.js index c7bfe760a..07a6355af 100644 --- a/sphinx/themes/basic/static/doctools.js +++ b/sphinx/themes/basic/static/doctools.js @@ -124,6 +124,7 @@ var Documentation = { this.fixFirefoxAnchorBug(); this.highlightSearchWords(); this.initIndexTable(); + this.initOnKeyListeners(); }, /** @@ -252,6 +253,30 @@ var Documentation = { }); var url = parts.join('/'); return path.substring(url.lastIndexOf('/') + 1, path.length - 1); + }, + + /** + * init onKeyListernes (for navigation) + */ + initOnKeyListeners: function() { + $(document).keyup(function(event) { + if (!$(document.activeElement).is('input')) { //don't navigate when in search box + switch (event.keyCode) { + case 37: //left + var prevElement = $('link[rel="prev"]')[0]; + if (prevElement) { + window.location.href = prevElement.href; + } + break; + case 39: //right + var nextElement = $('link[rel="next"]')[0]; + if (nextElement) { + window.location.href = nextElement.href; + } + break; + } + } + }); } }; From 06ac2a0059382bd2494726d16c4de0ebb861c75e Mon Sep 17 00:00:00 2001 From: Timotheus Kampik Date: Fri, 9 Oct 2015 12:08:29 +0200 Subject: [PATCH 2/4] refactored code according to discussion in #2064 --- sphinx/themes/basic/static/doctools.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/sphinx/themes/basic/static/doctools.js b/sphinx/themes/basic/static/doctools.js index 07a6355af..ed24a2da3 100644 --- a/sphinx/themes/basic/static/doctools.js +++ b/sphinx/themes/basic/static/doctools.js @@ -260,20 +260,21 @@ var Documentation = { */ initOnKeyListeners: function() { $(document).keyup(function(event) { - if (!$(document.activeElement).is('input')) { //don't navigate when in search box + var activeElementType = $(document.activeElement).prop('tagName'); + if (activeElementType !== 'TEXTAREA' && activeElementType !== 'INPUT') { // don't navigate when in search box or textarea switch (event.keyCode) { - case 37: //left - var prevElement = $('link[rel="prev"]')[0]; - if (prevElement) { - window.location.href = prevElement.href; + case 37: // left + var prevHref = $('link[rel="prev"]').prop('href'); + if (prevHref) { + window.location.href = prevHref; } - break; - case 39: //right - var nextElement = $('link[rel="next"]')[0]; - if (nextElement) { - window.location.href = nextElement.href; + return false; + case 39: // right + var nextHref = $('link[rel="next"]').prop('href'); + if (nextHref) { + window.location.href = nextHref; } - break; + return false; } } }); From a6a55898a0695e9f103e360086bc0e2b10fa3ab5 Mon Sep 17 00:00:00 2001 From: Timotheus Kampik Date: Fri, 27 Nov 2015 00:54:10 +0100 Subject: [PATCH 3/4] refactor navigation basic template enable configuration via theme.conf --- .../basic/static/{doctools.js => doctools.js_t} | 14 +++++++------- sphinx/themes/basic/theme.conf | 3 ++- 2 files changed, 9 insertions(+), 8 deletions(-) rename sphinx/themes/basic/static/{doctools.js => doctools.js_t} (96%) diff --git a/sphinx/themes/basic/static/doctools.js b/sphinx/themes/basic/static/doctools.js_t similarity index 96% rename from sphinx/themes/basic/static/doctools.js rename to sphinx/themes/basic/static/doctools.js_t index ed24a2da3..1700e33bf 100644 --- a/sphinx/themes/basic/static/doctools.js +++ b/sphinx/themes/basic/static/doctools.js_t @@ -124,7 +124,9 @@ var Documentation = { this.fixFirefoxAnchorBug(); this.highlightSearchWords(); this.initIndexTable(); + {% if not theme_nonavigationwithkeys|tobool %} this.initOnKeyListeners(); + {% endif %} }, /** @@ -255,26 +257,24 @@ var Documentation = { return path.substring(url.lastIndexOf('/') + 1, path.length - 1); }, - /** - * init onKeyListernes (for navigation) - */ initOnKeyListeners: function() { $(document).keyup(function(event) { - var activeElementType = $(document.activeElement).prop('tagName'); - if (activeElementType !== 'TEXTAREA' && activeElementType !== 'INPUT') { // don't navigate when in search box or textarea + var activeElementType = document.activeElement.tagName; + // don't navigate when in search box or textarea + if (activeElementType !== 'TEXTAREA' && activeElementType !== 'INPUT' && activeElementType !== 'SELECT') { switch (event.keyCode) { case 37: // left var prevHref = $('link[rel="prev"]').prop('href'); if (prevHref) { window.location.href = prevHref; + return false; } - return false; case 39: // right var nextHref = $('link[rel="next"]').prop('href'); if (nextHref) { window.location.href = nextHref; + return false; } - return false; } } }); diff --git a/sphinx/themes/basic/theme.conf b/sphinx/themes/basic/theme.conf index f7283730b..f25e0e2a9 100644 --- a/sphinx/themes/basic/theme.conf +++ b/sphinx/themes/basic/theme.conf @@ -5,4 +5,5 @@ pygments_style = none [options] nosidebar = false -sidebarwidth = 230 \ No newline at end of file +sidebarwidth = 230 +nonavigationwithkeys = false \ No newline at end of file From 6c0ea6718521a10b1130974a9bc3a996fdb51b45 Mon Sep 17 00:00:00 2001 From: Timotheus Kampik Date: Sun, 17 Jan 2016 17:05:28 +0100 Subject: [PATCH 4/4] make navigation with keys in basic theme non-default --- sphinx/themes/basic/static/doctools.js_t | 2 +- sphinx/themes/basic/theme.conf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sphinx/themes/basic/static/doctools.js_t b/sphinx/themes/basic/static/doctools.js_t index 1700e33bf..bf2856286 100644 --- a/sphinx/themes/basic/static/doctools.js_t +++ b/sphinx/themes/basic/static/doctools.js_t @@ -124,7 +124,7 @@ var Documentation = { this.fixFirefoxAnchorBug(); this.highlightSearchWords(); this.initIndexTable(); - {% if not theme_nonavigationwithkeys|tobool %} + {% if theme_navigation_with_keys|tobool %} this.initOnKeyListeners(); {% endif %} }, diff --git a/sphinx/themes/basic/theme.conf b/sphinx/themes/basic/theme.conf index f25e0e2a9..c0b8edee6 100644 --- a/sphinx/themes/basic/theme.conf +++ b/sphinx/themes/basic/theme.conf @@ -6,4 +6,4 @@ pygments_style = none [options] nosidebar = false sidebarwidth = 230 -nonavigationwithkeys = false \ No newline at end of file +navigation_with_keys = False \ No newline at end of file