diff options
-rw-r--r-- | js/keyhandler.js | 78 |
1 files changed, 49 insertions, 29 deletions
diff --git a/js/keyhandler.js b/js/keyhandler.js index a378249c7a..6e46677a3b 100644 --- a/js/keyhandler.js +++ b/js/keyhandler.js @@ -1,8 +1,7 @@ /* vim: set expandtab sw=4 ts=4 sts=4: */ -// gloabl vars to hold Arrow Down event timeStamps -var prevTimeStamp = 0; -var curTimeStamp = 0; +// gloabl vars that holds: 0- if ctrl key is not pressed 1- if ctrl key is pressed +var ctrlKeyHistory = 0; /** * Allows moving around inputs/select by Ctrl+arrows @@ -13,16 +12,6 @@ function onKeyDownArrowsHandler(e) { e = e || window.event; - curTimeStamp = e.timeStamp; - if( prevTimeStamp == 0 ) { - prevTimeStamp = curTimeStamp; - } - else if( Math.abs(curTimeStamp-prevTimeStamp) < 150 ) { - // event in a very quick succession - return; - } - prevTimeStamp = curTimeStamp; - var o = (e.srcElement || e.target); if (!o) { return; @@ -30,19 +19,31 @@ function onKeyDownArrowsHandler(e) if (o.tagName != "TEXTAREA" && o.tagName != "INPUT" && o.tagName != "SELECT") { return; } - if (navigator.userAgent.toLowerCase().indexOf('applewebkit/') != -1) { - if (e.ctrlKey || e.shiftKey || !e.altKey) { - return; + if ((e.which != 17) && (e.which != 37) && (e.which != 38) && (e.which != 39) && (e.which !=40)) { + return; + } + if (!o.id) { + return; + } + + if (e.type == "keyup") { + if (e.which==17) { + ctrlKeyHistory = 0; } - } else { - if (!e.ctrlKey || e.shiftKey || e.altKey) { - return; + return; + } + else if (e.type == "keydown") { + if (e.which == 17) { + ctrlKeyHistory = 1; } } - if (!o.id) { + + if (ctrlKeyHistory != 1) { return; } + e.preventDefault(); + var pos = o.id.split("_"); if (pos[0] != "field" || typeof pos[2] == "undefined") { return; @@ -75,11 +76,6 @@ function onKeyDownArrowsHandler(e) var is_firefox = navigator.userAgent.toLowerCase().indexOf("firefox/") > -1; - // restore selected index, bug #3799 - if (is_firefox && e.type == "keyup") { - o.selectedIndex = window["selectedIndex_" + o.id]; - } - var id = "field_" + y + "_" + x; nO = document.getElementById(id); if (! nO) { @@ -91,12 +87,36 @@ function onKeyDownArrowsHandler(e) if (! nO) { return; } - if (e.type == "keydown") { - nO.focus(); - if (is_firefox) { - window["selectedIndex_" + nO.id] = nO.selectedIndex; + + // for firefox select tag + var lvalue = o.selectedIndex; + var nOvalue = nO.selectedIndex; + + nO.focus(); + + if (is_firefox) { + var ffversion = '24'; + var is_firefox_v_24 = navigator.userAgent.toLowerCase().indexOf('firefox/'+ffversion) > -1; + if (is_firefox_v_24) { + if (e.which == 38 || e.which == 37) { + nOvalue++; + } + else if (e.which == 40 || e.which == 39) { + nOvalue--; + } + nO.selectedIndex=nOvalue; + } + else { + if (e.which == 38 || e.which == 37) { + lvalue++; + } + else if (e.which == 40 || e.which == 39) { + lvalue--; + } + o.selectedIndex=lvalue; } } + if (nO.tagName != 'SELECT') { nO.select(); } |