commit 154ffe21b5c7f13f5b08f424a45b40ff549bacdd
parent 7c7e1213d039bebde7e553b9a74a8329216d2799
Author: sorawee <sorawee.pwase@gmail.com>
Date: Mon, 16 Nov 2020 07:44:38 -0800
Fix JS error when searchbox is not present
When the search box is not present (e.g.,
https://docs.racket-lang.org/demo-m1/index.html),
pressing "S" will result in a JS error. This PR fixes the problem.
Note that semantically it makes more sense to give an ID to the
search box as we know exactly what search box we want.
Diffstat:
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/scribble-lib/scribble/html-render.rkt b/scribble-lib/scribble/html-render.rkt
@@ -225,6 +225,7 @@
`(form ([class "searchform"])
(input
([class "searchbox"]
+ [id "searchbox"]
[type "text"]
[tabindex "1"]
[placeholder ,emptylabel]
diff --git a/scribble-lib/scribble/scribble-common.js b/scribble-lib/scribble/scribble-common.js
@@ -173,8 +173,10 @@ AddOnLoad(function(){
AddOnLoad(function(){
window.addEventListener("keyup", function(e) {
if ((e.key === 's' || e.key === 'S') && e.target === document.body) {
- var field = document.getElementsByClassName("searchbox")[0];
- field.focus();
+ var searchBox = document.getElementById('searchbox');
+ if (searchBox) {
+ searchBox.focus();
+ }
}
}, false);
});