From dc3254303d3cfa201f18d15140efbea54f581ee9 Mon Sep 17 00:00:00 2001 From: sorawee Date: Fri, 6 Nov 2020 07:55:50 -0800 Subject: [PATCH] Use key instead of keyCode In non QWERTY keyboard, pressing S won't focus the search bar. This commit fixes the problem. Note that `keyCode` is not supported in IE8 already, so the fact that `key` is not supported in IE8 too doesn't really matter: the PR doesn't cause browser compatibility for the features to degrade. --- scribble-lib/scribble/scribble-common.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scribble-lib/scribble/scribble-common.js b/scribble-lib/scribble/scribble-common.js index dd3c23c4..f1b1bf63 100644 --- a/scribble-lib/scribble/scribble-common.js +++ b/scribble-lib/scribble/scribble-common.js @@ -129,7 +129,7 @@ function NormalizePath(path) { function DoSearchKey(event, field, ver, top_path) { var val = field.value; - if (event && event.keyCode == 13) { + if (event && event.key === 'Enter') { var u = GetCookie("PLT_Root."+ver, null); if (u == null) u = top_path; // default: go to the top path u += "search/index.html?q=" + encodeURIComponent(val); @@ -171,8 +171,8 @@ AddOnLoad(function(){ // Pressing "S" or "s" focuses on the "...search manuals..." text field AddOnLoad(function(){ - window.addEventListener("keyup", function(event) { - if (event && (event.keyCode == 83 || event.keyCode == 115) && event.target == document.body) { + window.addEventListener("keyup", function(e) { + if ((e.key === 's' || e.key === 'S') && e.target === document.body) { var field = document.getElementsByClassName("searchbox")[0]; field.focus(); }