Rev Author Line No. Line
250 kaklik 1 /**
2 * Allows moving around inputs/select by Ctrl+arrows
3 *
4 * @param object event data
5 */
6 function onKeyDownArrowsHandler(e) {
7 e = e||window.event;
8 var o = (e.srcElement||e.target);
9 if (!o) return;
10 if (o.tagName != "TEXTAREA" && o.tagName != "INPUT" && o.tagName != "SELECT") return;
11 if (navigator.userAgent.toLowerCase().indexOf('applewebkit/') != -1) {
12 if (e.ctrlKey || e.shiftKey || !e.altKey) return;
13 } else {
14 if (!e.ctrlKey || e.shiftKey || e.altKey) return;
15 }
16 if (!o.id) return;
17  
18 var pos = o.id.split("_");
19 if (pos[0] != "field" || typeof pos[2] == "undefined") return;
20  
21 var x = pos[2], y=pos[1];
22  
23 // skip non existent fields
24 for (i=0; i<10; i++)
25 {
26 if (switch_movement) {
27 switch(e.keyCode) {
28 case 38: x--; break; // up
29 case 40: x++; break; // down
30 case 37: y--; break; // left
31 case 39: y++; break; // right
32 default: return;
33 }
34 } else {
35 switch(e.keyCode) {
36 case 38: y--; break; // up
37 case 40: y++; break; // down
38 case 37: x--; break; // left
39 case 39: x++; break; // right
40 default: return;
41 }
42 }
43  
44 var id = "field_" + y + "_" + x;
45 var nO = document.getElementById(id);
46 if (!nO) {
47 var id = "field_" + y + "_" + x + "_0";
48 var nO = document.getElementById(id);
49 }
50 if (nO) break;
51 }
52  
53 if (!nO) return;
54 nO.focus();
55 if (nO.tagName != 'SELECT') {
56 nO.select();
57 }
58 e.returnValue = false;
59 }