aboutsummaryrefslogtreecommitdiffstats
path: root/_static/doctools.js
diff options
context:
space:
mode:
authorGravatar ChrisLovering <[email protected]>2022-04-02 20:57:41 +0000
committerGravatar ChrisLovering <[email protected]>2022-04-02 20:57:41 +0000
commitbc97054b9f27985523823e1643b7a0d5febc8ee1 (patch)
tree9e3331500d3b404f4a1ec949bb2862289336f282 /_static/doctools.js
parentDeploying to docs from @ python-discord/bot-core@3732ccccbebf26da1678b24c1446... (diff)
Deploying to docs from @ python-discord/bot-core@b31c793634113fc2e6213eb8597cef8423954a88 🚀
Diffstat (limited to '_static/doctools.js')
-rw-r--r--_static/doctools.js72
1 files changed, 52 insertions, 20 deletions
diff --git a/_static/doctools.js b/_static/doctools.js
index e509e483..e1bfd708 100644
--- a/_static/doctools.js
+++ b/_static/doctools.js
@@ -154,9 +154,7 @@ var Documentation = {
this.fixFirefoxAnchorBug();
this.highlightSearchWords();
this.initIndexTable();
- if (DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS) {
- this.initOnKeyListeners();
- }
+ this.initOnKeyListeners();
},
/**
@@ -269,6 +267,13 @@ var Documentation = {
window.history.replaceState({}, '', url);
},
+ /**
+ * helper function to focus on search bar
+ */
+ focusSearchBar : function() {
+ $('input[name=q]').first().focus();
+ },
+
/**
* make the url absolute
*/
@@ -291,27 +296,54 @@ var Documentation = {
},
initOnKeyListeners: function() {
+ // only install a listener if it is really needed
+ if (!DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS &&
+ !DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS)
+ return;
+
$(document).keydown(function(event) {
var activeElementType = document.activeElement.tagName;
// don't navigate when in search box, textarea, dropdown or button
if (activeElementType !== 'TEXTAREA' && activeElementType !== 'INPUT' && activeElementType !== 'SELECT'
- && activeElementType !== 'BUTTON' && !event.altKey && !event.ctrlKey && !event.metaKey
- && !event.shiftKey) {
- switch (event.keyCode) {
- case 37: // left
- var prevHref = $('link[rel="prev"]').prop('href');
- if (prevHref) {
- window.location.href = prevHref;
- return false;
- }
- break;
- case 39: // right
- var nextHref = $('link[rel="next"]').prop('href');
- if (nextHref) {
- window.location.href = nextHref;
- return false;
- }
- break;
+ && activeElementType !== 'BUTTON') {
+ if (event.altKey || event.ctrlKey || event.metaKey)
+ return;
+
+ if (!event.shiftKey) {
+ switch (event.key) {
+ case 'ArrowLeft':
+ if (!DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS)
+ break;
+ var prevHref = $('link[rel="prev"]').prop('href');
+ if (prevHref) {
+ window.location.href = prevHref;
+ return false;
+ }
+ break;
+ case 'ArrowRight':
+ if (!DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS)
+ break;
+ var nextHref = $('link[rel="next"]').prop('href');
+ if (nextHref) {
+ window.location.href = nextHref;
+ return false;
+ }
+ break;
+ case 'Escape':
+ if (!DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS)
+ break;
+ Documentation.hideSearchWords();
+ return false;
+ }
+ }
+
+ // some keyboard layouts may need Shift to get /
+ switch (event.key) {
+ case '/':
+ if (!DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS)
+ break;
+ Documentation.focusSearchBar();
+ return false;
}
}
});