Object extend Event _specialKeys backspace tab return 13 enter 13 shif

 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
Object.extend(Event,{
_specialKeys: {
'backspace': 8,
'tab': 9,
'return': 13, 'enter': 13,
'shift': 16,
'ctrl': 17, 'control': 17, 'cmd': 17, // 'cmd' is
detected by opera on macs instead of ctrl
'alt': 18, 'alterative': 18,
'pause': 19, 'break': 19,
'capsLock': 20, 'caps': 20,
'esc': 27, 'escape': 27,
'pageUp': 33,
'pageDown': 34,
'end': 35,
'home': 36,
'left': 37, 'leftArrow': 37,
'up': 38, 'upArrow': 38,
'right': 39, 'rightArrow': 39,
'down': 40, 'downArrow': 40,
'insert': 45,
'delete': 46, 'del': 46,
'windowsLeft': 91, 'Windows': 91,
'windowsRight': 92,
'select': 93,
'f1': 112,
'f2': 113,
'f3': 114,
'f4': 115,
'f5': 116,
'f6': 117,
'f7': 118,
'f8': 119,
'f9': 120,
'f10': 121,
'f11': 122,
'f12': 123,
'numLock': 144, 'num': 144,
'scrollLock': 145, 'scroll': 145
},
_code: function(event) {
var keyResult;
if (Object.isNumber(event.keyCode)) keyResult =
event.keyCode; //DOM
else if (Object.isNumber(event.which)) keyResult =
event.which; //NS 4 compatible
else if (Object.isNumber(event.charCode)) keyResult =
event.charCode; //also NS 6+, Mozilla 0.9+
else keyResult =
null; //total failure
return keyResult;
},
_withModifiers: function(event, keys) {
if (!keys) return false;
var check = [], modifiers = [ 'shift', 'ctrl', 'alt' ];
if (Object.isString(keys)) keys = $w(keys);
keys.each(function(key, index) {
if (modifiers.inArray(key)) check[check.length] = event[key
+'Key'];
});
return check.all();
},
isKey: function(event, key, modifiers) {
var KeyCode = this._code(event)
if (
( (KeyCode == (/\D/.match(key) ? this._specialKeys[key] : key))
|| (/\d/.match(key) && String.fromCharCode(KeyCode).toLowerCase() ==
key) )
&&
(Object.isUndefined(modifiers) ? true :
this._withModifiers(event, modifiers))
) return true;
return false;
}
});