2016-10-22 14:57:10 +00:00
|
|
|
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
|
|
|
|
|
|
|
// global var 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
|
|
|
|
*
|
|
|
|
* @param object event data
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function onKeyDownArrowsHandler (e) {
|
2016-10-22 14:57:10 +00:00
|
|
|
e = e || window.event;
|
|
|
|
|
|
|
|
var o = (e.srcElement || e.target);
|
|
|
|
if (!o) {
|
|
|
|
return;
|
|
|
|
}
|
2018-04-14 09:18:00 +00:00
|
|
|
if (o.tagName !== 'TEXTAREA' && o.tagName !== 'INPUT' && o.tagName !== 'SELECT') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-04-14 09:18:00 +00:00
|
|
|
if ((e.which !== 17) && (e.which !== 37) && (e.which !== 38) && (e.which !== 39) && (e.which !== 40)) {
|
2016-10-22 14:57:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!o.id) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
if (e.type === 'keyup') {
|
|
|
|
if (e.which === 17) {
|
2016-10-22 14:57:10 +00:00
|
|
|
ctrlKeyHistory = 0;
|
|
|
|
}
|
|
|
|
return;
|
2018-04-14 09:18:00 +00:00
|
|
|
} else if (e.type === 'keydown') {
|
|
|
|
if (e.which === 17) {
|
2016-10-22 14:57:10 +00:00
|
|
|
ctrlKeyHistory = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
if (ctrlKeyHistory !== 1) {
|
2016-10-22 14:57:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
var pos = o.id.split('_');
|
|
|
|
if (pos[0] !== 'field' || typeof pos[2] === 'undefined') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
var x = pos[2];
|
|
|
|
var y = pos[1];
|
2016-10-22 14:57:10 +00:00
|
|
|
|
|
|
|
switch (e.keyCode) {
|
|
|
|
case 38:
|
|
|
|
// up
|
|
|
|
y--;
|
|
|
|
break;
|
|
|
|
case 40:
|
|
|
|
// down
|
|
|
|
y++;
|
|
|
|
break;
|
|
|
|
case 37:
|
|
|
|
// left
|
|
|
|
x--;
|
|
|
|
break;
|
|
|
|
case 39:
|
|
|
|
// right
|
|
|
|
x++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
var is_firefox = navigator.userAgent.toLowerCase().indexOf('firefox/') > -1;
|
2016-10-22 14:57:10 +00:00
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
var id = 'field_' + y + '_' + x;
|
2016-10-22 14:57:10 +00:00
|
|
|
|
|
|
|
var nO = document.getElementById(id);
|
|
|
|
if (! nO) {
|
2018-04-14 09:18:00 +00:00
|
|
|
id = 'field_' + y + '_' + x + '_0';
|
2016-10-22 14:57:10 +00:00
|
|
|
nO = document.getElementById(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
// skip non existent fields
|
|
|
|
if (! nO) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// for firefox select tag
|
|
|
|
var lvalue = o.selectedIndex;
|
|
|
|
var nOvalue = nO.selectedIndex;
|
|
|
|
|
|
|
|
nO.focus();
|
|
|
|
|
|
|
|
if (is_firefox) {
|
|
|
|
var ffcheck = 0;
|
|
|
|
var ffversion;
|
|
|
|
for (ffversion = 3 ; ffversion < 25 ; ffversion++) {
|
2018-04-14 09:18:00 +00:00
|
|
|
var is_firefox_v_24 = navigator.userAgent.toLowerCase().indexOf('firefox/' + ffversion) > -1;
|
2016-10-22 14:57:10 +00:00
|
|
|
if (is_firefox_v_24) {
|
|
|
|
ffcheck = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-04-14 09:18:00 +00:00
|
|
|
if (ffcheck === 1) {
|
|
|
|
if (e.which === 38 || e.which === 37) {
|
2016-10-22 14:57:10 +00:00
|
|
|
nOvalue++;
|
2018-04-14 09:18:00 +00:00
|
|
|
} else if (e.which === 40 || e.which === 39) {
|
2016-10-22 14:57:10 +00:00
|
|
|
nOvalue--;
|
|
|
|
}
|
2018-04-14 09:18:00 +00:00
|
|
|
nO.selectedIndex = nOvalue;
|
|
|
|
} else {
|
|
|
|
if (e.which === 38 || e.which === 37) {
|
2016-10-22 14:57:10 +00:00
|
|
|
lvalue++;
|
2018-04-14 09:18:00 +00:00
|
|
|
} else if (e.which === 40 || e.which === 39) {
|
2016-10-22 14:57:10 +00:00
|
|
|
lvalue--;
|
|
|
|
}
|
2018-04-14 09:18:00 +00:00
|
|
|
o.selectedIndex = lvalue;
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
if (nO.tagName !== 'SELECT') {
|
2016-10-22 14:57:10 +00:00
|
|
|
nO.select();
|
|
|
|
}
|
|
|
|
e.returnValue = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
AJAX.registerTeardown('keyhandler.js', function () {
|
|
|
|
$(document).off('keydown keyup', '#table_columns');
|
|
|
|
$(document).off('keydown keyup', 'table.insertRowTable');
|
|
|
|
});
|
|
|
|
|
|
|
|
AJAX.registerOnload('keyhandler.js', function () {
|
|
|
|
$(document).on('keydown keyup', '#table_columns', function (event) {
|
|
|
|
onKeyDownArrowsHandler(event.originalEvent);
|
|
|
|
});
|
|
|
|
$(document).on('keydown keyup', 'table.insertRowTable', function (event) {
|
|
|
|
onKeyDownArrowsHandler(event.originalEvent);
|
|
|
|
});
|
|
|
|
});
|