From 7db580850856d838d5d155ea5897d091d62e6ff6 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Fri, 16 Jun 2017 17:17:15 +0200 Subject: [PATCH] keys: javascript mode match reorder, comments Code cleanup, optimisation. --- keys.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/keys.js b/keys.js index b625db7..993e8f4 100644 --- a/keys.js +++ b/keys.js @@ -23,19 +23,27 @@ document.onkeypress = function(e) { keys[keylabels[i].innerHTML] = keylabels[i].parentNode; } var input = e.charCode || e.keyCode; + + // find key element matching input for (var i = 0; i < keylabels.length; i++) { var key = keylabels[i].parentNode; - if (!key.onclick) continue; + if (!key.onclick) continue; // link var keychar = key.className.match(/ chr(\d+)$/); - if (!keychar) continue; // not enterable + if (!keychar) continue; // has code keychar = keychar[1]; - if (keychar != input) continue; // different key + if (keychar != input) continue; // matches code + + // match mode (visibility) var row = key.parentNode; + var shown = row.style.display != 'none'; + if (!shown) continue; + + // match key modifiers var keymod = row.className; - if ((keymod.search(/\bctrl\b/) != -1) != e.ctrlKey) continue; // modifier mismatch + if ((keymod.search(/\bctrl\b/) != -1) != e.ctrlKey) continue; if ((keymod.search(/\bmeta\b/) != -1) != e.altKey) continue; - var shown = row.style.display != 'none'; - if (!shown) continue; // foreign mode + + // select if (keyfocus) keyfocus.style.outline = ''; key.style.outline = '1px solid red'; keyfocus = key; -- 2.30.0