blob: e531bcaae5140e9cc1713eeb278328270a539317 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
import $ from 'jquery';
// var that holds: 0- if ctrl key is not pressed 1- if ctrl key is pressed
let ctrlKeyHistory = 0;
/**
* Allows moving around inputs/select by Ctrl+arrows
*
* @param {object} event data
*/
const onKeyDownArrowsHandler = function (event) {
var e = event || window.event;
var o = (e.srcElement || e.target);
if (!o) {
return;
}
if (o.tagName !== 'TEXTAREA' && o.tagName !== 'INPUT' && o.tagName !== 'SELECT') {
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;
}
return;
} else if (e.type === 'keydown') {
if (e.which === 17) {
ctrlKeyHistory = 1;
}
}
if (ctrlKeyHistory !== 1) {
return;
}
e.preventDefault();
var pos = o.id.split('_');
if (pos[0] !== 'field' || typeof pos[2] === 'undefined') {
return;
}
var x = pos[2];
var y = pos[1];
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;
}
// eslint-disable-next-line compat/compat
var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox/') > -1;
var id = 'field_' + y + '_' + x;
var nO = document.getElementById(id);
if (!nO) {
id = 'field_' + y + '_' + x + '_0';
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 (isFirefox) {
var ffcheck = 0;
var ffversion;
for (ffversion = 3; ffversion < 25; ffversion++) {
var isFirefoxV24 = navigator.userAgent.toLowerCase().indexOf('firefox/' + ffversion) > -1;
if (isFirefoxV24) {
ffcheck = 1;
break;
}
}
if (ffcheck === 1) {
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();
}
e.returnValue = false;
};
const KeyHandlerEvents = {
/**
* @return {function}
*/
off: function () {
return function () {
$(document).off('keydown keyup', '#table_columns');
$(document).off('keydown keyup', 'table.insertRowTable');
};
},
/**
* @return {function}
*/
on: function () {
return function () {
$(document).on('keydown keyup', '#table_columns', function (event) {
onKeyDownArrowsHandler(event.originalEvent);
});
$(document).on('keydown keyup', 'table.insertRowTable', function (event) {
onKeyDownArrowsHandler(event.originalEvent);
});
};
}
};
window.KeyHandlerEvents = KeyHandlerEvents;
|