mousetrapjs 0.1.3.2 → 1.4.0

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: 695bbc0800be132445f64021f08b14450ed51408
4
- data.tar.gz: d87c345754c3ecbff2005b5fcde86c66a690acf7
3
+ metadata.gz: 8e244036ef071e3d6222f608a02a948661138a11
4
+ data.tar.gz: a1ca76a8c83b8df9cce0ab86d3538591dd4c5e56
5
5
  SHA512:
6
- metadata.gz: 60ac93071cd1eee948d5bde94115b2af5ce75cc4b0fcfebdd64555e726217b5106cd2f16cc65daa10624ccb10d451243530e94ba69764ae54c490d5cabd8d1f4
7
- data.tar.gz: 43609f8b5a37550e9711c3f1f7d0554186b22efa0aa673f9e7cdaceefd2547c23c187f24c3ad299f3899d1f70c44275fcf588c5af739b87fd992d19e9f78f44b
6
+ metadata.gz: d09f19f0fbb6d71efc1cfe9a324bec24a7ece344d05f948770fb19c1b370deaab8899cf257595dbdde6161ae560546b3b602ef2a7f884ded80eda41a0b914da9
7
+ data.tar.gz: 117a6788596f94ab0513fbfb12a61699abd52ddf62acf5189d0f59cd38ee5fec6e99edd79b5de8b05b1d106faff6f40b493dc88f01584dc76cf38042e7597706
@@ -1,3 +1,3 @@
1
1
  module Mousetrapjs
2
- VERSION = "0.1.3.2"
2
+ VERSION = "1.4.0"
3
3
  end
@@ -17,7 +17,7 @@
17
17
  * Mousetrap is a simple keyboard shortcut library for Javascript with
18
18
  * no external dependencies
19
19
  *
20
- * @version 1.3.2
20
+ * @version 1.4.0
21
21
  * @url craig.is/killing/mice
22
22
  */
23
23
  (function() {
@@ -125,7 +125,8 @@
125
125
  'option': 'alt',
126
126
  'command': 'meta',
127
127
  'return': 'enter',
128
- 'escape': 'esc'
128
+ 'escape': 'esc',
129
+ 'mod': /Mac|iPod|iPhone|iPad/.test(navigator.platform) ? 'meta' : 'ctrl'
129
130
  },
130
131
 
131
132
  /**
@@ -275,14 +276,14 @@
275
276
  * @param {Object} doNotReset
276
277
  * @returns void
277
278
  */
278
- function _resetSequences(doNotReset, maxLevel) {
279
+ function _resetSequences(doNotReset) {
279
280
  doNotReset = doNotReset || {};
280
281
 
281
282
  var activeSequences = false,
282
283
  key;
283
284
 
284
285
  for (key in _sequenceLevels) {
285
- if (doNotReset[key] && _sequenceLevels[key] > maxLevel) {
286
+ if (doNotReset[key]) {
286
287
  activeSequences = true;
287
288
  continue;
288
289
  }
@@ -434,6 +435,13 @@
434
435
  maxLevel = 0,
435
436
  processedSequenceCallback = false;
436
437
 
438
+ // Calculate the maxLevel for sequences so we can only execute the longest callback sequence
439
+ for (i = 0; i < callbacks.length; ++i) {
440
+ if (callbacks[i].seq) {
441
+ maxLevel = Math.max(maxLevel, callbacks[i].level);
442
+ }
443
+ }
444
+
437
445
  // loop through matching callbacks for this key event
438
446
  for (i = 0; i < callbacks.length; ++i) {
439
447
 
@@ -443,11 +451,20 @@
443
451
  // callback for matching g cause otherwise you can only ever
444
452
  // match the first one
445
453
  if (callbacks[i].seq) {
446
- processedSequenceCallback = true;
447
454
 
448
- // as we loop through keep track of the max
449
- // any sequence at a lower level will be discarded
450
- maxLevel = Math.max(maxLevel, callbacks[i].level);
455
+ // only fire callbacks for the maxLevel to prevent
456
+ // subsequences from also firing
457
+ //
458
+ // for example 'a option b' should not cause 'option b' to fire
459
+ // even though 'option b' is part of the other sequence
460
+ //
461
+ // any sequences that do not match here will be discarded
462
+ // below by the _resetSequences call
463
+ if (callbacks[i].level != maxLevel) {
464
+ continue;
465
+ }
466
+
467
+ processedSequenceCallback = true;
451
468
 
452
469
  // keep a list of which sequences were matches for later
453
470
  doNotReset[callbacks[i].seq] = 1;
@@ -457,16 +474,24 @@
457
474
 
458
475
  // if there were no sequence matches but we are still here
459
476
  // that means this is a regular match so we should fire that
460
- if (!processedSequenceCallback && !_sequenceType) {
477
+ if (!processedSequenceCallback) {
461
478
  _fireCallback(callbacks[i].callback, e, callbacks[i].combo);
462
479
  }
463
480
  }
464
481
 
465
- // if you are inside of a sequence and the key you are pressing
466
- // is not a modifier key then we should reset all sequences
467
- // that were not matched by this key event
482
+ // if the key you pressed matches the type of sequence without
483
+ // being a modifier (ie "keyup" or "keypress") then we should
484
+ // reset all sequences that were not matched by this event
485
+ //
486
+ // this is so, for example, if you have the sequence "h a t" and you
487
+ // type "h e a r t" it does not match. in this case the "e" will
488
+ // cause the sequence to reset
489
+ //
490
+ // modifier keys are ignored because you can have a sequence
491
+ // that contains modifiers such as "enter ctrl+space" and in most
492
+ // cases the modifier key will be pressed before the next key
468
493
  if (e.type == _sequenceType && !_isModifier(character)) {
469
- _resetSequences(doNotReset, maxLevel);
494
+ _resetSequences(doNotReset);
470
495
  }
471
496
  }
472
497
 
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: 0.1.3.2
4
+ version: 1.4.0
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-04-12 00:00:00.000000000 Z
11
+ date: 2013-05-20 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
@@ -46,7 +46,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
46
46
  version: '0'
47
47
  requirements: []
48
48
  rubyforge_project:
49
- rubygems_version: 2.0.0
49
+ rubygems_version: 2.0.3
50
50
  signing_key:
51
51
  specification_version: 4
52
52
  summary: Mousetrap is a simple library for handling keyboard shortcuts in Javascript