summaryrefslogtreecommitdiff
path: root/lib/rdoc/generator/template/darkfish/js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rdoc/generator/template/darkfish/js')
-rw-r--r--lib/rdoc/generator/template/darkfish/js/darkfish.js15
-rw-r--r--lib/rdoc/generator/template/darkfish/js/search.js8
2 files changed, 18 insertions, 5 deletions
diff --git a/lib/rdoc/generator/template/darkfish/js/darkfish.js b/lib/rdoc/generator/template/darkfish/js/darkfish.js
index 111bbf8eb9..19a85c54e1 100644
--- a/lib/rdoc/generator/template/darkfish/js/darkfish.js
+++ b/lib/rdoc/generator/template/darkfish/js/darkfish.js
@@ -54,7 +54,7 @@ function hookSearch() {
var html = '';
// TODO add relative path to <script> per-page
- html += '<p class="search-match"><a href="' + index_rel_prefix + result.path + '">' + this.hlt(result.title);
+ html += '<p class="search-match"><a href="' + index_rel_prefix + this.escapeHTML(result.path) + '">' + this.hlt(result.title);
if (result.params)
html += '<span class="params">' + result.params + '</span>';
html += '</a>';
@@ -78,7 +78,20 @@ function hookSearch() {
search.scrollIntoView = search.scrollInWindow;
};
+function hookFocus() {
+ document.addEventListener("keydown", (event) => {
+ if (document.activeElement.tagName === 'INPUT') {
+ return;
+ }
+ if (event.key === "/") {
+ event.preventDefault();
+ document.querySelector('#search-field').focus();
+ }
+ });
+}
+
document.addEventListener('DOMContentLoaded', function() {
hookSourceViews();
hookSearch();
+ hookFocus();
});
diff --git a/lib/rdoc/generator/template/darkfish/js/search.js b/lib/rdoc/generator/template/darkfish/js/search.js
index b558ca5b4f..d3cded1d57 100644
--- a/lib/rdoc/generator/template/darkfish/js/search.js
+++ b/lib/rdoc/generator/template/darkfish/js/search.js
@@ -15,9 +15,9 @@ Search.prototype = Object.assign({}, Navigation, new function() {
this.init = function() {
var _this = this;
var observer = function(e) {
- switch(e.keyCode) {
- case 38: // Event.KEY_UP
- case 40: // Event.KEY_DOWN
+ switch(e.key) {
+ case 'ArrowUp':
+ case 'ArrowDown':
return;
}
_this.search(_this.input.value);
@@ -101,7 +101,7 @@ Search.prototype = Object.assign({}, Navigation, new function() {
}
this.escapeHTML = function(html) {
- return html.replace(/[&<>]/g, function(c) {
+ return html.replace(/[&<>"`']/g, function(c) {
return '&#' + c.charCodeAt(0) + ';';
});
}