This repository has been archived by the owner on Dec 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
106 lines (96 loc) · 2.47 KB
/
index.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
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
var _ = require('lodash');
var protractor = require('protractor');
var Key = protractor.Key;
var hotkeyMap;
exports.hotkeyMap = hotkeyMap = {
'*': Key.MULTIPLY,
'+': Key.ADD,
'-': Key.SUBTRACT,
'.': Key.DECIMAL,
'/': Key.DIVIDE,
';': Key.SEMICOLON,
'=': Key.EQUALS,
0: Key.NUMPAD0,
1: Key.NUMPAD1,
2: Key.NUMPAD2,
3: Key.NUMPAD3,
4: Key.NUMPAD4,
5: Key.NUMPAD5,
6: Key.NUMPAD6,
7: Key.NUMPAD7,
8: Key.NUMPAD8,
9: Key.NUMPAD9,
alt: Key.ALT,
backspace: Key.BACK_SPACE,
cancel: Key.CANCEL,
capslock: Key.CAPS_LOCK,
clear: Key.CLEAR,
command: Key.COMMAND,
control: Key.CONTROL,
delete: Key.DELETE,
down: Key.ARROW_DOWN,
end: Key.END,
enter: Key.ENTER,
escape: Key.ESCAPE,
f10: Key.F10,
f11: Key.F11,
f12: Key.F12,
f1: Key.F1,
f2: Key.F2,
f3: Key.F3,
f4: Key.F4,
f5: Key.F5,
f6: Key.F6,
f7: Key.F7,
f8: Key.F8,
f9: Key.F9,
help: Key.HELP,
home: Key.HOME,
insert: Key.INSERT,
left: Key.ARROW_LEFT,
mod: Key.META,
null: Key.NULL,
pageDown: Key.PAGE_DOWN,
pageUp: Key.PAGE_UP,
pause: Key.PAUSE,
return: Key.RETURN,
right: Key.ARROW_RIGHT,
shift: Key.SHIFT,
space: Key.SPACE,
tab: Key.TAB,
up: Key.ARROW_UP,
};
exports.hotkeyAliases = {
caps: hotkeyMap.capslock,
cmd: hotkeyMap.mod,
command: hotkeyMap.mod,
ctrl: hotkeyMap.control,
del: hotkeyMap.delete,
esc: hotkeyMap.escape,
super: hotkeyMap.mod,
windowsKey: hotkeyMap.mod,
};
exports.HOTKEYS = _.extend(hotkeyMap, exports.hotkeyAliases);
exports.codify = function (list) {
return list.map(function (member) {
member.trim();
return exports.HOTKEYS[member] || member;
});
};
exports.trigger = function (command, options) {
if (options === undefined) {
options = {};
}
// 'a b ctrl+shift+c' -> ['a', 'b', 'ctrl+shift+c']
var commands = exports.codify(command.split(' '));
// ['a', 'b', 'ctrl+shift+c'] -> [['a'], ['b'], [Key.CONTROL, Key.SHIFT, 'c']]
commands = commands.map(function (keypressCode) {
return exports.codify(keypressCode.split('+'));
});
var target = options.targetElement || $('body');
commands.forEach(function (command) {
target.sendKeys.apply(target, command);
});
// return this same function for chaining
return { trigger: exports.trigger };
};