mousetrapjs 1.4.1 → 1.4.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a05b6045de34fc7a0ad351cfbde3c00199238455
4
- data.tar.gz: 8c923714b26069877b456fffbfd66b5fbefa4485
3
+ metadata.gz: b371a2c09b8b414d06a0f6c8929c515ea3878065
4
+ data.tar.gz: daa31acbc49586adab1ef383ec2afc2f4bb9aa27
5
5
  SHA512:
6
- metadata.gz: 1c147ad6eeb0ab7b660fdaa2ff6d968ef4245f3bad8fda3f0281221bb3cb44e13ca21f4585869a3e02d98ed582c34d5325d8cdde16801d17383f52be4f89cf7e
7
- data.tar.gz: d3a340ed7919ea2731f88493e229a6815ac0ae8b861e6a087870377d39ff52a9fa49b64c5fdb207e9c0fb66fffb961e6ae7688d614f3d9cdb8d2cc2466c7622e
6
+ metadata.gz: 3dc22e20ef8425ac45ff35ff66d057f11f4391e46fd48b50aedd1f82b341a66de13d8bc30f7147032588fa6a31e15f398db504d623024ef4a16678eb39f3d4a2
7
+ data.tar.gz: f82b161215434176c74bde304156a07891d0acfd83b41d053792a65812d524a75ab6c6d68982b1f98ce63b8cf0aebf45fe48170b13f95fd46a92a887160b00f6
data/README.md CHANGED
@@ -1,3 +1,4 @@
1
+ [![Stories in Ready](https://badge.waffle.io/luizkowalski/mousetrapjs.png?label=ready)](https://waffle.io/luizkowalski/mousetrapjs)
1
2
  # MousetrapJS
2
3
  Mousetrap is a simple library for handling keyboard shortcuts in Javascript, with no external dependencies.
3
4
  Documentation can be found in [here](http://craig.is/killing/mice).
@@ -1,3 +1,3 @@
1
1
  module Mousetrapjs
2
- VERSION = "1.4.1"
2
+ VERSION = "1.4.6"
3
3
  end
@@ -17,10 +17,10 @@
17
17
  * Mousetrap is a simple keyboard shortcut library for Javascript with
18
18
  * no external dependencies
19
19
  *
20
- * @version 1.4.1
20
+ * @version 1.4.6
21
21
  * @url craig.is/killing/mice
22
22
  */
23
- (function() {
23
+ (function(window, document, undefined) {
24
24
 
25
25
  /**
26
26
  * mapping of special keycodes to their corresponding keys
@@ -174,6 +174,13 @@
174
174
  */
175
175
  _ignoreNextKeyup = false,
176
176
 
177
+ /**
178
+ * temporary state where we will ignore the next keypress
179
+ *
180
+ * @type {boolean}
181
+ */
182
+ _ignoreNextKeypress = false,
183
+
177
184
  /**
178
185
  * are we currently inside of a sequence?
179
186
  * type of action ("keyup" or "keydown" or "keypress") or false
@@ -395,6 +402,36 @@
395
402
  return modifiers;
396
403
  }
397
404
 
405
+ /**
406
+ * prevents default for this event
407
+ *
408
+ * @param {Event} e
409
+ * @returns void
410
+ */
411
+ function _preventDefault(e) {
412
+ if (e.preventDefault) {
413
+ e.preventDefault();
414
+ return;
415
+ }
416
+
417
+ e.returnValue = false;
418
+ }
419
+
420
+ /**
421
+ * stops propogation for this event
422
+ *
423
+ * @param {Event} e
424
+ * @returns void
425
+ */
426
+ function _stopPropagation(e) {
427
+ if (e.stopPropagation) {
428
+ e.stopPropagation();
429
+ return;
430
+ }
431
+
432
+ e.cancelBubble = true;
433
+ }
434
+
398
435
  /**
399
436
  * actually calls the callback function
400
437
  *
@@ -405,24 +442,16 @@
405
442
  * @param {Event} e
406
443
  * @returns void
407
444
  */
408
- function _fireCallback(callback, e, combo) {
445
+ function _fireCallback(callback, e, combo, sequence) {
409
446
 
410
447
  // if this event should not happen stop here
411
- if (Mousetrap.stopCallback(e, e.target || e.srcElement, combo)) {
448
+ if (Mousetrap.stopCallback(e, e.target || e.srcElement, combo, sequence)) {
412
449
  return;
413
450
  }
414
451
 
415
452
  if (callback(e, combo) === false) {
416
- if (e.preventDefault) {
417
- e.preventDefault();
418
- }
419
-
420
- if (e.stopPropagation) {
421
- e.stopPropagation();
422
- }
423
-
424
- e.returnValue = false;
425
- e.cancelBubble = true;
453
+ _preventDefault(e);
454
+ _stopPropagation(e);
426
455
  }
427
456
  }
428
457
 
@@ -474,7 +503,7 @@
474
503
 
475
504
  // keep a list of which sequences were matches for later
476
505
  doNotReset[callbacks[i].seq] = 1;
477
- _fireCallback(callbacks[i].callback, e, callbacks[i].combo);
506
+ _fireCallback(callbacks[i].callback, e, callbacks[i].combo, callbacks[i].seq);
478
507
  continue;
479
508
  }
480
509
 
@@ -496,9 +525,22 @@
496
525
  // modifier keys are ignored because you can have a sequence
497
526
  // that contains modifiers such as "enter ctrl+space" and in most
498
527
  // cases the modifier key will be pressed before the next key
499
- if (e.type == _nextExpectedAction && !_isModifier(character)) {
528
+ //
529
+ // also if you have a sequence such as "ctrl+b a" then pressing the
530
+ // "b" key will trigger a "keypress" and a "keydown"
531
+ //
532
+ // the "keydown" is expected when there is a modifier, but the
533
+ // "keypress" ends up matching the _nextExpectedAction since it occurs
534
+ // after and that causes the sequence to reset
535
+ //
536
+ // we ignore keypresses in a sequence that directly follow a keydown
537
+ // for the same character
538
+ var ignoreThisKeypress = e.type == 'keypress' && _ignoreNextKeypress;
539
+ if (e.type == _nextExpectedAction && !_isModifier(character) && !ignoreThisKeypress) {
500
540
  _resetSequences(doNotReset);
501
541
  }
542
+
543
+ _ignoreNextKeypress = processedSequenceCallback && e.type == 'keydown';
502
544
  }
503
545
 
504
546
  /**
@@ -522,7 +564,8 @@
522
564
  return;
523
565
  }
524
566
 
525
- if (e.type == 'keyup' && _ignoreNextKeyup == character) {
567
+ // need to use === for the character check because the character can be 0
568
+ if (e.type == 'keyup' && _ignoreNextKeyup === character) {
526
569
  _ignoreNextKeyup = false;
527
570
  return;
528
571
  }
@@ -891,7 +934,7 @@
891
934
  }
892
935
 
893
936
  // stop for input, select, and textarea
894
- return element.tagName == 'INPUT' || element.tagName == 'SELECT' || element.tagName == 'TEXTAREA' || (element.contentEditable && element.contentEditable == 'true');
937
+ return element.tagName == 'INPUT' || element.tagName == 'SELECT' || element.tagName == 'TEXTAREA' || element.isContentEditable;
895
938
  },
896
939
 
897
940
  /**
@@ -907,4 +950,4 @@
907
950
  if (typeof define === 'function' && define.amd) {
908
951
  define(Mousetrap);
909
952
  }
910
- }) ();
953
+ }) (window, document);
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mousetrapjs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luiz Eduardo Kowalski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-17 00:00:00.000000000 Z
11
+ date: 2015-01-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Gem for Mousetrap, a simple library for handling keyboard shortcuts in
14
14
  Javascript
@@ -18,7 +18,7 @@ executables: []
18
18
  extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
- - .gitignore
21
+ - ".gitignore"
22
22
  - Gemfile
23
23
  - LICENSE
24
24
  - README.md
@@ -36,17 +36,17 @@ require_paths:
36
36
  - lib
37
37
  required_ruby_version: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '>='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  required_rubygems_version: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - '>='
44
+ - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
47
  requirements: []
48
48
  rubyforge_project:
49
- rubygems_version: 2.0.3
49
+ rubygems_version: 2.4.5
50
50
  signing_key:
51
51
  specification_version: 4
52
52
  summary: Mousetrap is a simple library for handling keyboard shortcuts in Javascript