-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshortcut.js
44 lines (35 loc) · 1.06 KB
/
shortcut.js
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
Drupal.behaviors.shortcut = function(context) {
$(document).keydown(processShortcutDown);
};
shortcutsPress = new Array();
shortcutsDown = new Array();
shortcut_found = false;
shortcut_call_external_path = function(path){
document.location = path;
}
shortcut_call_internal_path = function(path){
document.location = Drupal.settings.basePath + path;
}
processShortcutDown = function(ev){
shortcut_found = false;
code = ev.keyCode;
for(i=0; i < Drupal.settings.shortcuts.length; i++) {
shortcutDown = Drupal.settings.shortcuts[i];
//we sum a empty string into the ev values for cast it his values to a string
if(
shortcutDown.char_code == code
&& shortcutDown.alt == ev.altKey+''
&& shortcutDown.ctrl == ev.ctrlKey+''
&& shortcutDown.shift == ev.shiftKey+''){
if(ev.stopPropagation){
ev.stopPropagation(true);
ev.preventDefault(true);
} else {
ev.cancelBubble = true;
}
eval(shortcutDown.func_name+'("'+shortcutDown.param+'")');
shortcut_found = true;
return false;
}
}
}