@ntlab/ntjs-assets 2.0.1 → 2.0.2

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.
Files changed (29) hide show
  1. package/assets/js/mousetrap/Gruntfile.js +35 -0
  2. package/assets/js/mousetrap/LICENSE +193 -0
  3. package/assets/js/mousetrap/README.md +101 -0
  4. package/assets/js/mousetrap/mousetrap.js +1058 -0
  5. package/assets/js/mousetrap/mousetrap.min.js +11 -0
  6. package/assets/js/mousetrap/mousetrap.sublime-project +20 -0
  7. package/assets/js/mousetrap/package-lock.json +1979 -0
  8. package/assets/js/mousetrap/package.json +34 -0
  9. package/assets/js/mousetrap/plugins/README.md +24 -0
  10. package/assets/js/mousetrap/plugins/bind-dictionary/README.md +16 -0
  11. package/assets/js/mousetrap/plugins/bind-dictionary/mousetrap-bind-dictionary.js +39 -0
  12. package/assets/js/mousetrap/plugins/bind-dictionary/mousetrap-bind-dictionary.min.js +1 -0
  13. package/assets/js/mousetrap/plugins/global-bind/README.md +15 -0
  14. package/assets/js/mousetrap/plugins/global-bind/mousetrap-global-bind.js +46 -0
  15. package/assets/js/mousetrap/plugins/global-bind/mousetrap-global-bind.min.js +1 -0
  16. package/assets/js/mousetrap/plugins/pause/README.md +13 -0
  17. package/assets/js/mousetrap/plugins/pause/mousetrap-pause.js +31 -0
  18. package/assets/js/mousetrap/plugins/pause/mousetrap-pause.min.js +1 -0
  19. package/assets/js/mousetrap/plugins/record/README.md +16 -0
  20. package/assets/js/mousetrap/plugins/record/mousetrap-record.js +205 -0
  21. package/assets/js/mousetrap/plugins/record/mousetrap-record.min.js +2 -0
  22. package/assets/js/mousetrap/plugins/record/tests/index.html +29 -0
  23. package/assets/js/mousetrap/plugins/record/tests/jelly.css +18 -0
  24. package/assets/js/mousetrap/plugins/record/tests/jelly.js +53 -0
  25. package/assets/js/mousetrap/tests/libs/jquery-1.7.2.min.js +4 -0
  26. package/assets/js/mousetrap/tests/libs/key-event.js +158 -0
  27. package/assets/js/mousetrap/tests/mousetrap.html +24 -0
  28. package/assets/js/mousetrap/tests/test.mousetrap.js +772 -0
  29. package/package.json +1 -1
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "mousetrap",
3
+ "version": "1.6.5",
4
+ "description": "Simple library for handling keyboard shortcuts",
5
+ "main": "mousetrap.js",
6
+ "directories": {
7
+ "test": "tests"
8
+ },
9
+ "scripts": {
10
+ "test": "mocha --reporter=nyan tests/test.mousetrap.js"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git://github.com/ccampbell/mousetrap.git"
15
+ },
16
+ "keywords": [
17
+ "keyboard",
18
+ "shortcuts",
19
+ "events"
20
+ ],
21
+ "author": "Craig Campbell",
22
+ "license": "Apache-2.0 WITH LLVM-exception",
23
+ "gitHead": "c202a0bd4967d5a3064f9cb376db51dec9345336",
24
+ "readmeFilename": "README.md",
25
+ "devDependencies": {
26
+ "chai": "^4.2.0",
27
+ "grunt": "~1.0.3",
28
+ "grunt-complexity": "~1.1.0",
29
+ "jsdom": "^13.1.0",
30
+ "jsdom-global": "^3.0.2",
31
+ "mocha": "^5.2.0",
32
+ "sinon": "^7.2.2"
33
+ }
34
+ }
@@ -0,0 +1,24 @@
1
+ # Plugins
2
+
3
+ Plugins extend the functionality of Mousetrap. To use a plugin just include the plugin after mousetrap.
4
+
5
+ ```html
6
+ <script src="mousetrap.js"></script>
7
+ <script src="mousetrap-record.js"></script>
8
+ ```
9
+
10
+ ## Bind dictionary
11
+
12
+ Allows you to make multiple bindings in a single ``Mousetrap.bind`` call.
13
+
14
+ ## Global bind
15
+
16
+ Allows you to set global bindings that work even inside of input fields.
17
+
18
+ ## Pause/unpause
19
+
20
+ Allows you to temporarily prevent Mousetrap events from firing.
21
+
22
+ ## Record
23
+
24
+ Allows you to capture a keyboard shortcut or sequence defined by a user.
@@ -0,0 +1,16 @@
1
+ # Bind Dictionary
2
+
3
+ This extension overwrites the default bind behavior and allows you to bind multiple combinations in a single bind call.
4
+
5
+ Usage looks like:
6
+
7
+ ```javascript
8
+ Mousetrap.bind({
9
+ 'a': function() { console.log('a'); },
10
+ 'b': function() { console.log('b'); }
11
+ });
12
+ ```
13
+
14
+ You can optionally pass in ``keypress``, ``keydown`` or ``keyup`` as a second argument.
15
+
16
+ Other bind calls work the same way as they do by default.
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Overwrites default Mousetrap.bind method to optionally accept
3
+ * an object to bind multiple key events in a single call
4
+ *
5
+ * You can pass it in like:
6
+ *
7
+ * Mousetrap.bind({
8
+ * 'a': function() { console.log('a'); },
9
+ * 'b': function() { console.log('b'); }
10
+ * });
11
+ *
12
+ * And can optionally pass in 'keypress', 'keydown', or 'keyup'
13
+ * as a second argument
14
+ *
15
+ */
16
+ /* global Mousetrap:true */
17
+ (function(Mousetrap) {
18
+ var _oldBind = Mousetrap.prototype.bind;
19
+ var args;
20
+
21
+ Mousetrap.prototype.bind = function() {
22
+ var self = this;
23
+ args = arguments;
24
+
25
+ // normal call
26
+ if (typeof args[0] == 'string' || args[0] instanceof Array) {
27
+ return _oldBind.call(self, args[0], args[1], args[2]);
28
+ }
29
+
30
+ // object passed in
31
+ for (var key in args[0]) {
32
+ if (args[0].hasOwnProperty(key)) {
33
+ _oldBind.call(self, key, args[0][key], args[1]);
34
+ }
35
+ }
36
+ };
37
+
38
+ Mousetrap.init();
39
+ }) (Mousetrap);
@@ -0,0 +1 @@
1
+ (function(b){var c=b.prototype.bind,a;b.prototype.bind=function(){a=arguments;if("string"==typeof a[0]||a[0]instanceof Array)return c.call(this,a[0],a[1],a[2]);for(var b in a[0])a[0].hasOwnProperty(b)&&c.call(this,b,a[0][b],a[1])};b.init()})(Mousetrap);
@@ -0,0 +1,15 @@
1
+ # Global Bind
2
+
3
+ This extension allows you to specify keyboard events that will work anywhere including inside textarea/input fields.
4
+
5
+ Usage looks like:
6
+
7
+ ```javascript
8
+ Mousetrap.bindGlobal('ctrl+s', function() {
9
+ _save();
10
+ });
11
+ ```
12
+
13
+ This means that a keyboard event bound using ``Mousetrap.bind`` will only work outside of form input fields, but using ``Moustrap.bindGlobal`` will work in both places.
14
+
15
+ If you wanted to create keyboard shortcuts that only work when you are inside a specific textarea you can do that too by creating your own extension.
@@ -0,0 +1,46 @@
1
+ /**
2
+ * adds a bindGlobal method to Mousetrap that allows you to
3
+ * bind specific keyboard shortcuts that will still work
4
+ * inside a text input field
5
+ *
6
+ * usage:
7
+ * Mousetrap.bindGlobal('ctrl+s', _saveChanges);
8
+ */
9
+ /* global Mousetrap:true */
10
+ (function(Mousetrap) {
11
+ if (! Mousetrap) {
12
+ return;
13
+ }
14
+ var _globalCallbacks = {};
15
+ var _originalStopCallback = Mousetrap.prototype.stopCallback;
16
+
17
+ Mousetrap.prototype.stopCallback = function(e, element, combo, sequence) {
18
+ var self = this;
19
+
20
+ if (self.paused) {
21
+ return true;
22
+ }
23
+
24
+ if (_globalCallbacks[combo] || _globalCallbacks[sequence]) {
25
+ return false;
26
+ }
27
+
28
+ return _originalStopCallback.call(self, e, element, combo);
29
+ };
30
+
31
+ Mousetrap.prototype.bindGlobal = function(keys, callback, action) {
32
+ var self = this;
33
+ self.bind(keys, callback, action);
34
+
35
+ if (keys instanceof Array) {
36
+ for (var i = 0; i < keys.length; i++) {
37
+ _globalCallbacks[keys[i]] = true;
38
+ }
39
+ return;
40
+ }
41
+
42
+ _globalCallbacks[keys] = true;
43
+ };
44
+
45
+ Mousetrap.init();
46
+ }) (typeof Mousetrap !== "undefined" ? Mousetrap : undefined);
@@ -0,0 +1 @@
1
+ (function(a){var c={},d=a.prototype.stopCallback;a.prototype.stopCallback=function(e,b,a,f){return this.paused?!0:c[a]||c[f]?!1:d.call(this,e,b,a)};a.prototype.bindGlobal=function(a,b,d){this.bind(a,b,d);if(a instanceof Array)for(b=0;b<a.length;b++)c[a[b]]=!0;else c[a]=!0};a.init()})(Mousetrap);
@@ -0,0 +1,13 @@
1
+ # Pause/unpause
2
+
3
+ This extension allows Mousetrap to be paused and unpaused without having to reset keyboard shortcuts and rebind them.
4
+
5
+ Usage looks like:
6
+
7
+ ```javascript
8
+ // stop Mousetrap events from firing
9
+ Mousetrap.pause();
10
+
11
+ // allow Mousetrap events to fire again
12
+ Mousetrap.unpause();
13
+ ```
@@ -0,0 +1,31 @@
1
+ /**
2
+ * adds a pause and unpause method to Mousetrap
3
+ * this allows you to enable or disable keyboard shortcuts
4
+ * without having to reset Mousetrap and rebind everything
5
+ */
6
+ /* global Mousetrap:true */
7
+ (function(Mousetrap) {
8
+ var _originalStopCallback = Mousetrap.prototype.stopCallback;
9
+
10
+ Mousetrap.prototype.stopCallback = function(e, element, combo) {
11
+ var self = this;
12
+
13
+ if (self.paused) {
14
+ return true;
15
+ }
16
+
17
+ return _originalStopCallback.call(self, e, element, combo);
18
+ };
19
+
20
+ Mousetrap.prototype.pause = function() {
21
+ var self = this;
22
+ self.paused = true;
23
+ };
24
+
25
+ Mousetrap.prototype.unpause = function() {
26
+ var self = this;
27
+ self.paused = false;
28
+ };
29
+
30
+ Mousetrap.init();
31
+ }) (Mousetrap);
@@ -0,0 +1 @@
1
+ (function(a){var b=a.prototype.stopCallback;a.prototype.stopCallback=function(a,c,d){return this.paused?!0:b.call(this,a,c,d)};a.prototype.pause=function(){this.paused=!0};a.prototype.unpause=function(){this.paused=!1};a.init()})(Mousetrap);
@@ -0,0 +1,16 @@
1
+ # Record
2
+
3
+ This extension lets you use Mousetrap to record keyboard sequences and play them back:
4
+
5
+ ```html
6
+ <button onclick="recordSequence()">Record</button>
7
+
8
+ <script>
9
+ function recordSequence() {
10
+ Mousetrap.record(function(sequence) {
11
+ // sequence is an array like ['ctrl+k', 'c']
12
+ alert('You pressed: ' + sequence.join(' '));
13
+ });
14
+ }
15
+ </script>
16
+ ```
@@ -0,0 +1,205 @@
1
+ /**
2
+ * This extension allows you to record a sequence using Mousetrap.
3
+ *
4
+ * @author Dan Tao <daniel.tao@gmail.com>
5
+ */
6
+ (function(Mousetrap) {
7
+ /**
8
+ * the sequence currently being recorded
9
+ *
10
+ * @type {Array}
11
+ */
12
+ var _recordedSequence = [],
13
+
14
+ /**
15
+ * a callback to invoke after recording a sequence
16
+ *
17
+ * @type {Function|null}
18
+ */
19
+ _recordedSequenceCallback = null,
20
+
21
+ /**
22
+ * a list of all of the keys currently held down
23
+ *
24
+ * @type {Array}
25
+ */
26
+ _currentRecordedKeys = [],
27
+
28
+ /**
29
+ * temporary state where we remember if we've already captured a
30
+ * character key in the current combo
31
+ *
32
+ * @type {boolean}
33
+ */
34
+ _recordedCharacterKey = false,
35
+
36
+ /**
37
+ * a handle for the timer of the current recording
38
+ *
39
+ * @type {null|number}
40
+ */
41
+ _recordTimer = null,
42
+
43
+ /**
44
+ * the original handleKey method to override when Mousetrap.record() is
45
+ * called
46
+ *
47
+ * @type {Function}
48
+ */
49
+ _origHandleKey = Mousetrap.prototype.handleKey;
50
+
51
+ /**
52
+ * handles a character key event
53
+ *
54
+ * @param {string} character
55
+ * @param {Array} modifiers
56
+ * @param {Event} e
57
+ * @returns void
58
+ */
59
+ function _handleKey(character, modifiers, e) {
60
+ var self = this;
61
+
62
+ if (!self.recording) {
63
+ _origHandleKey.apply(self, arguments);
64
+ return;
65
+ }
66
+
67
+ // remember this character if we're currently recording a sequence
68
+ if (e.type == 'keydown') {
69
+ if (character.length === 1 && _recordedCharacterKey) {
70
+ _recordCurrentCombo();
71
+ }
72
+
73
+ for (i = 0; i < modifiers.length; ++i) {
74
+ _recordKey(modifiers[i]);
75
+ }
76
+ _recordKey(character);
77
+
78
+ // once a key is released, all keys that were held down at the time
79
+ // count as a keypress
80
+ } else if (e.type == 'keyup' && _currentRecordedKeys.length > 0) {
81
+ _recordCurrentCombo();
82
+ }
83
+ }
84
+
85
+ /**
86
+ * marks a character key as held down while recording a sequence
87
+ *
88
+ * @param {string} key
89
+ * @returns void
90
+ */
91
+ function _recordKey(key) {
92
+ var i;
93
+
94
+ // one-off implementation of Array.indexOf, since IE6-9 don't support it
95
+ for (i = 0; i < _currentRecordedKeys.length; ++i) {
96
+ if (_currentRecordedKeys[i] === key) {
97
+ return;
98
+ }
99
+ }
100
+
101
+ _currentRecordedKeys.push(key);
102
+
103
+ if (key.length === 1) {
104
+ _recordedCharacterKey = true;
105
+ }
106
+ }
107
+
108
+ /**
109
+ * marks whatever key combination that's been recorded so far as finished
110
+ * and gets ready for the next combo
111
+ *
112
+ * @returns void
113
+ */
114
+ function _recordCurrentCombo() {
115
+ _recordedSequence.push(_currentRecordedKeys);
116
+ _currentRecordedKeys = [];
117
+ _recordedCharacterKey = false;
118
+ _restartRecordTimer();
119
+ }
120
+
121
+ /**
122
+ * ensures each combo in a sequence is in a predictable order and formats
123
+ * key combos to be '+'-delimited
124
+ *
125
+ * modifies the sequence in-place
126
+ *
127
+ * @param {Array} sequence
128
+ * @returns void
129
+ */
130
+ function _normalizeSequence(sequence) {
131
+ var i;
132
+
133
+ for (i = 0; i < sequence.length; ++i) {
134
+ sequence[i].sort(function(x, y) {
135
+ // modifier keys always come first, in alphabetical order
136
+ if (x.length > 1 && y.length === 1) {
137
+ return -1;
138
+ } else if (x.length === 1 && y.length > 1) {
139
+ return 1;
140
+ }
141
+
142
+ // character keys come next (list should contain no duplicates,
143
+ // so no need for equality check)
144
+ return x > y ? 1 : -1;
145
+ });
146
+
147
+ sequence[i] = sequence[i].join('+');
148
+ }
149
+ }
150
+
151
+ /**
152
+ * finishes the current recording, passes the recorded sequence to the stored
153
+ * callback, and sets Mousetrap.handleKey back to its original function
154
+ *
155
+ * @returns void
156
+ */
157
+ function _finishRecording() {
158
+ if (_recordedSequenceCallback) {
159
+ _normalizeSequence(_recordedSequence);
160
+ _recordedSequenceCallback(_recordedSequence);
161
+ }
162
+
163
+ // reset all recorded state
164
+ _recordedSequence = [];
165
+ _recordedSequenceCallback = null;
166
+ _currentRecordedKeys = [];
167
+ }
168
+
169
+ /**
170
+ * called to set a 1 second timeout on the current recording
171
+ *
172
+ * this is so after each key press in the sequence the recording will wait for
173
+ * 1 more second before executing the callback
174
+ *
175
+ * @returns void
176
+ */
177
+ function _restartRecordTimer() {
178
+ clearTimeout(_recordTimer);
179
+ _recordTimer = setTimeout(_finishRecording, 1000);
180
+ }
181
+
182
+ /**
183
+ * records the next sequence and passes it to a callback once it's
184
+ * completed
185
+ *
186
+ * @param {Function} callback
187
+ * @returns void
188
+ */
189
+ Mousetrap.prototype.record = function(callback) {
190
+ var self = this;
191
+ self.recording = true;
192
+ _recordedSequenceCallback = function() {
193
+ self.recording = false;
194
+ callback.apply(self, arguments);
195
+ };
196
+ };
197
+
198
+ Mousetrap.prototype.handleKey = function() {
199
+ var self = this;
200
+ _handleKey.apply(self, arguments);
201
+ };
202
+
203
+ Mousetrap.init();
204
+
205
+ })(Mousetrap);
@@ -0,0 +1,2 @@
1
+ (function(d){function n(b,a,h){if(this.recording)if("keydown"==h.type){1===b.length&&g&&k();for(i=0;i<a.length;++i)l(a[i]);l(b)}else"keyup"==h.type&&0<c.length&&k();else p.apply(this,arguments)}function l(b){var a;for(a=0;a<c.length;++a)if(c[a]===b)return;c.push(b);1===b.length&&(g=!0)}function k(){e.push(c);c=[];g=!1;clearTimeout(m);m=setTimeout(q,1E3)}function r(b){var a;for(a=0;a<b.length;++a)b[a].sort(function(a,b){return 1<a.length&&1===b.length?-1:1===a.length&&1<b.length?1:a>b?1:-1}),b[a]=
2
+ b[a].join("+")}function q(){f&&(r(e),f(e));e=[];f=null;c=[]}var e=[],f=null,c=[],g=!1,m=null,p=d.prototype.handleKey;d.prototype.record=function(b){var a=this;a.recording=!0;f=function(){a.recording=!1;b.apply(a,arguments)}};d.prototype.handleKey=function(){n.apply(this,arguments)};d.init()})(Mousetrap);
@@ -0,0 +1,29 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+
4
+ <head>
5
+ <title>Jelly</title>
6
+ <meta charset=utf-8>
7
+ <link href="jelly.css" rel="stylesheet">
8
+ </head>
9
+
10
+ <body>
11
+ <h1>Jelly</h1>
12
+
13
+ <h2>For testing the <strong>record</strong> extension</h2>
14
+
15
+ <p>Click "Record" to test recording a sequence.</p>
16
+ <button class="test-record">Record</button>
17
+ <div class="test-record-result"></div>
18
+
19
+ <script type="text/javascript" src="../../../tests/libs/jquery-1.7.2.min.js"></script>
20
+ <script type="text/javascript" src="../../../mousetrap.js"></script>
21
+ <script type="text/javascript" src="../mousetrap-record.js"></script>
22
+ <script type="text/javascript" src="jelly.js"></script>
23
+
24
+ <script type="text/javascript">
25
+ Jelly.spread();
26
+ </script>
27
+ </body>
28
+
29
+ </html>
@@ -0,0 +1,18 @@
1
+ body {
2
+ font-family: helvetica, arial, sans-serif;
3
+ line-height: 20px;
4
+ }
5
+
6
+ kbd {
7
+ background-color: #ccc;
8
+ display: inline-block;
9
+ padding: 0.5ex 1em;
10
+ }
11
+
12
+ .test-record-result {
13
+ margin-top: 20px;
14
+ }
15
+
16
+ .test-record-result span:nth-child(n+2) {
17
+ margin-left: 10px;
18
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Peanut butter goes great with jelly.
3
+ *
4
+ * @author Dan Tao <daniel.tao@gmail.com>
5
+ */
6
+ var Jelly = (function() {
7
+ var recordButton = $("button.test-record"),
8
+ recordResult = $("div.test-record-result");
9
+
10
+ function _formatSequenceAsHtml(sequence) {
11
+ var combos = [],
12
+ i;
13
+
14
+ for (i = 0; i < sequence.length; ++i) {
15
+ combos.push('<span>' + _formatKeysAsHtml(sequence[i].split('+')) + '</span>');
16
+ }
17
+
18
+ return combos.join(' ');
19
+ }
20
+
21
+ function _formatKeysAsHtml(keys) {
22
+ var htmlKeys = [],
23
+ i;
24
+
25
+ for (i = 0; i < keys.length; ++i) {
26
+ htmlKeys.push('<kbd>' + keys[i] + '</kbd>');
27
+ }
28
+
29
+ return htmlKeys.join('+');
30
+ }
31
+
32
+ function _prepareRecordTest() {
33
+ recordButton.prop('disabled', true);
34
+ recordButton.text('Recording');
35
+
36
+ Mousetrap.record(function(sequence) {
37
+ recordResult.html(_formatSequenceAsHtml(sequence));
38
+ recordButton.prop('disabled', false);
39
+ recordButton.text('Record');
40
+ });
41
+
42
+ // take focus away from the button so that Mousetrap will actually
43
+ // capture keystrokes
44
+ recordButton.blur();
45
+ }
46
+
47
+ return {
48
+ spread: function() {
49
+ recordButton.click(_prepareRecordTest);
50
+ }
51
+ };
52
+
53
+ })();