1 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 // global var that holds: 0- if ctrl key is not pressed 1- if ctrl key is pressed
4 var ctrlKeyHistory = 0;
7 * Allows moving around inputs/select by Ctrl+arrows
9 * @param object event data
11 function onKeyDownArrowsHandler (e) {
12 e = e || window.event;
14 var o = (e.srcElement || e.target);
18 if (o.tagName !== 'TEXTAREA' && o.tagName !== 'INPUT' && o.tagName !== 'SELECT') {
21 if ((e.which !== 17) && (e.which !== 37) && (e.which !== 38) && (e.which !== 39) && (e.which !== 40)) {
28 if (e.type === 'keyup') {
33 } else if (e.type === 'keydown') {
39 if (ctrlKeyHistory !== 1) {
45 var pos = o.id.split('_');
46 if (pos[0] !== 'field' || typeof pos[2] === 'undefined') {
74 var is_firefox = navigator.userAgent.toLowerCase().indexOf('firefox/') > -1;
76 var id = 'field_' + y + '_' + x;
78 var nO = document.getElementById(id);
80 id = 'field_' + y + '_' + x + '_0';
81 nO = document.getElementById(id);
84 // skip non existent fields
89 // for firefox select tag
90 var lvalue = o.selectedIndex;
91 var nOvalue = nO.selectedIndex;
98 for (ffversion = 3 ; ffversion < 25 ; ffversion++) {
99 var is_firefox_v_24 = navigator.userAgent.toLowerCase().indexOf('firefox/' + ffversion) > -1;
100 if (is_firefox_v_24) {
106 if (e.which === 38 || e.which === 37) {
108 } else if (e.which === 40 || e.which === 39) {
111 nO.selectedIndex = nOvalue;
113 if (e.which === 38 || e.which === 37) {
115 } else if (e.which === 40 || e.which === 39) {
118 o.selectedIndex = lvalue;
122 if (nO.tagName !== 'SELECT') {
125 e.returnValue = false;
128 AJAX.registerTeardown('keyhandler.js', function () {
129 $(document).off('keydown keyup', '#table_columns');
130 $(document).off('keydown keyup', 'table.insertRowTable');
133 AJAX.registerOnload('keyhandler.js', function () {
134 $(document).on('keydown keyup', '#table_columns', function (event) {
135 onKeyDownArrowsHandler(event.originalEvent);
137 $(document).on('keydown keyup', 'table.insertRowTable', function (event) {
138 onKeyDownArrowsHandler(event.originalEvent);