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.
This commit is contained in:
parent
b3f7015cba
commit
dc3254303d
|
@ -129,7 +129,7 @@ function NormalizePath(path) {
|
||||||
|
|
||||||
function DoSearchKey(event, field, ver, top_path) {
|
function DoSearchKey(event, field, ver, top_path) {
|
||||||
var val = field.value;
|
var val = field.value;
|
||||||
if (event && event.keyCode == 13) {
|
if (event && event.key === 'Enter') {
|
||||||
var u = GetCookie("PLT_Root."+ver, null);
|
var u = GetCookie("PLT_Root."+ver, null);
|
||||||
if (u == null) u = top_path; // default: go to the top path
|
if (u == null) u = top_path; // default: go to the top path
|
||||||
u += "search/index.html?q=" + encodeURIComponent(val);
|
u += "search/index.html?q=" + encodeURIComponent(val);
|
||||||
|
@ -171,8 +171,8 @@ AddOnLoad(function(){
|
||||||
|
|
||||||
// Pressing "S" or "s" focuses on the "...search manuals..." text field
|
// Pressing "S" or "s" focuses on the "...search manuals..." text field
|
||||||
AddOnLoad(function(){
|
AddOnLoad(function(){
|
||||||
window.addEventListener("keyup", function(event) {
|
window.addEventListener("keyup", function(e) {
|
||||||
if (event && (event.keyCode == 83 || event.keyCode == 115) && event.target == document.body) {
|
if ((e.key === 's' || e.key === 'S') && e.target === document.body) {
|
||||||
var field = document.getElementsByClassName("searchbox")[0];
|
var field = document.getElementsByClassName("searchbox")[0];
|
||||||
field.focus();
|
field.focus();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user