@checksub_team/peaks_timeline 1.4.35 → 1.4.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,112 +1,112 @@
1
- /**
2
- * @file
3
- *
4
- * Defines the {@link KeyboardHandler} class.
5
- *
6
- * @module keyboard-handler
7
- */
8
-
9
- define([], function() {
10
- 'use strict';
11
-
12
- var nodes = ['OBJECT', 'TEXTAREA', 'INPUT', 'SELECT', 'OPTION'];
13
-
14
- var keys = ['Spacebar', ' ', 'Tab', 'ArrowLeft', 'ArrowRight', 'Delete'];
15
-
16
- /**
17
- * Configures keyboard event handling.
18
- *
19
- * @class
20
- * @alias KeyboardHandler
21
- *
22
- * @param {EventEmitter} eventEmitter
23
- */
24
-
25
- function KeyboardHandler(eventEmitter) {
26
- this.eventEmitter = eventEmitter;
27
-
28
- this._handleKeyEvent = this._handleKeyEvent.bind(this);
29
-
30
- this._ctrlCmdPressed = false;
31
-
32
- document.addEventListener('keydown', this._handleKeyEvent);
33
- document.addEventListener('keypress', this._handleKeyEvent);
34
- document.addEventListener('keyup', this._handleKeyEvent);
35
- }
36
-
37
- KeyboardHandler.prototype.isCtrlCmdPressed = function handleKeyEvent() {
38
- return this._ctrlCmdPressed;
39
- };
40
-
41
- /**
42
- * Keyboard event handler function.
43
- *
44
- * @note Arrow keys only triggered on keydown, not keypress.
45
- *
46
- * @param {KeyboardEvent} event
47
- * @private
48
- */
49
-
50
- KeyboardHandler.prototype._handleKeyEvent = function handleKeyEvent(event) {
51
- if (nodes.indexOf(event.target.nodeName) === -1) {
52
- if (keys.indexOf(event.code) > -1) {
53
- event.preventDefault();
54
- }
55
-
56
- if (event.type === 'keydown' || event.type === 'keypress') {
57
- if ((event.ctrlKey || event.metaKey) && !this._ctrlCmdPressed) {
58
- this.eventEmitter.emit('keyboard.ctrlCmdDown');
59
- this._ctrlCmdPressed = true;
60
- }
61
- switch (event.code) {
62
- case 'Spacebar':
63
- case ' ':
64
- this.eventEmitter.emit('keyboard.space');
65
- break;
66
-
67
- case 'Tab':
68
- this.eventEmitter.emit('keyboard.tab');
69
- break;
70
- }
71
- }
72
- else if (event.type === 'keyup') {
73
- if (!(event.ctrlKey || event.metaKey) && this._ctrlCmdPressed) {
74
- this.eventEmitter.emit('keyboard.ctrlCmdUp');
75
- this._ctrlCmdPressed = false;
76
- }
77
- switch (event.code) {
78
- case 'ArrowLeft':
79
- if (event.shiftKey) {
80
- this.eventEmitter.emit('keyboard.shift_left');
81
- }
82
- else {
83
- this.eventEmitter.emit('keyboard.left');
84
- }
85
- break;
86
-
87
- case 'ArrowRight':
88
- if (event.shiftKey) {
89
- this.eventEmitter.emit('keyboard.shift_right');
90
- }
91
- else {
92
- this.eventEmitter.emit('keyboard.right');
93
- }
94
- break;
95
-
96
- case 'Delete':
97
- case 'Backspace':
98
- this.eventEmitter.emit('keyboard.delete');
99
- break;
100
- }
101
- }
102
- }
103
- };
104
-
105
- KeyboardHandler.prototype.destroy = function() {
106
- document.removeEventListener('keydown', this._handleKeyEvent);
107
- document.removeEventListener('keypress', this._handleKeyEvent);
108
- document.removeEventListener('keyup', this._handleKeyEvent);
109
- };
110
-
111
- return KeyboardHandler;
112
- });
1
+ /**
2
+ * @file
3
+ *
4
+ * Defines the {@link KeyboardHandler} class.
5
+ *
6
+ * @module keyboard-handler
7
+ */
8
+
9
+ define([], function() {
10
+ 'use strict';
11
+
12
+ var nodes = ['OBJECT', 'TEXTAREA', 'INPUT', 'SELECT', 'OPTION'];
13
+
14
+ var keys = ['Spacebar', ' ', 'Tab', 'ArrowLeft', 'ArrowRight', 'Delete'];
15
+
16
+ /**
17
+ * Configures keyboard event handling.
18
+ *
19
+ * @class
20
+ * @alias KeyboardHandler
21
+ *
22
+ * @param {EventEmitter} eventEmitter
23
+ */
24
+
25
+ function KeyboardHandler(eventEmitter) {
26
+ this.eventEmitter = eventEmitter;
27
+
28
+ this._handleKeyEvent = this._handleKeyEvent.bind(this);
29
+
30
+ this._ctrlCmdPressed = false;
31
+
32
+ document.addEventListener('keydown', this._handleKeyEvent);
33
+ document.addEventListener('keypress', this._handleKeyEvent);
34
+ document.addEventListener('keyup', this._handleKeyEvent);
35
+ }
36
+
37
+ KeyboardHandler.prototype.isCtrlCmdPressed = function handleKeyEvent() {
38
+ return this._ctrlCmdPressed;
39
+ };
40
+
41
+ /**
42
+ * Keyboard event handler function.
43
+ *
44
+ * @note Arrow keys only triggered on keydown, not keypress.
45
+ *
46
+ * @param {KeyboardEvent} event
47
+ * @private
48
+ */
49
+
50
+ KeyboardHandler.prototype._handleKeyEvent = function handleKeyEvent(event) {
51
+ if (nodes.indexOf(event.target.nodeName) === -1) {
52
+ if (keys.indexOf(event.code) > -1) {
53
+ event.preventDefault();
54
+ }
55
+
56
+ if (event.type === 'keydown' || event.type === 'keypress') {
57
+ if ((event.ctrlKey || event.metaKey) && !this._ctrlCmdPressed) {
58
+ this.eventEmitter.emit('keyboard.ctrlCmdDown');
59
+ this._ctrlCmdPressed = true;
60
+ }
61
+ switch (event.code) {
62
+ case 'Spacebar':
63
+ case ' ':
64
+ this.eventEmitter.emit('keyboard.space');
65
+ break;
66
+
67
+ case 'Tab':
68
+ this.eventEmitter.emit('keyboard.tab');
69
+ break;
70
+ }
71
+ }
72
+ else if (event.type === 'keyup') {
73
+ if (!(event.ctrlKey || event.metaKey) && this._ctrlCmdPressed) {
74
+ this.eventEmitter.emit('keyboard.ctrlCmdUp');
75
+ this._ctrlCmdPressed = false;
76
+ }
77
+ switch (event.code) {
78
+ case 'ArrowLeft':
79
+ if (event.shiftKey) {
80
+ this.eventEmitter.emit('keyboard.shift_left');
81
+ }
82
+ else {
83
+ this.eventEmitter.emit('keyboard.left');
84
+ }
85
+ break;
86
+
87
+ case 'ArrowRight':
88
+ if (event.shiftKey) {
89
+ this.eventEmitter.emit('keyboard.shift_right');
90
+ }
91
+ else {
92
+ this.eventEmitter.emit('keyboard.right');
93
+ }
94
+ break;
95
+
96
+ case 'Delete':
97
+ case 'Backspace':
98
+ this.eventEmitter.emit('keyboard.delete');
99
+ break;
100
+ }
101
+ }
102
+ }
103
+ };
104
+
105
+ KeyboardHandler.prototype.destroy = function() {
106
+ document.removeEventListener('keydown', this._handleKeyEvent);
107
+ document.removeEventListener('keypress', this._handleKeyEvent);
108
+ document.removeEventListener('keyup', this._handleKeyEvent);
109
+ };
110
+
111
+ return KeyboardHandler;
112
+ });