vendor/assets/javascripts/mousetrap.js in mousetrap-rails-0.0.7 vs vendor/assets/javascripts/mousetrap.js in mousetrap-rails-0.0.8

- old
+ new

@@ -14,11 +14,11 @@ * limitations under the License. * * Mousetrap is a simple keyboard shortcut library for Javascript with * no external dependencies * - * @version 1.2.1 + * @version 1.2.2 * @url craig.is/killing/mice */ (function() { /** @@ -176,11 +176,11 @@ * are we currently inside of a sequence? * type of action ("keyup" or "keydown" or "keypress") or false * * @type {boolean|string} */ - _inside_sequence = false; + _sequence_type = false; /** * loop through the f keys, f1 to f19 and add them to the map * programatically */ @@ -253,26 +253,26 @@ * resets all sequence counters except for the ones passed in * * @param {Object} do_not_reset * @returns void */ - function _resetSequences(do_not_reset) { + function _resetSequences(do_not_reset, max_level) { do_not_reset = do_not_reset || {}; var active_sequences = false, key; for (key in _sequence_levels) { - if (do_not_reset[key]) { + if (do_not_reset[key] && _sequence_levels[key] > max_level) { active_sequences = true; continue; } _sequence_levels[key] = 0; } if (!active_sequences) { - _inside_sequence = false; + _sequence_type = false; } } /** * finds all callbacks that match based on the keycode, modifiers, @@ -408,10 +408,11 @@ */ function _handleCharacter(character, e) { var callbacks = _getMatches(character, _eventModifiers(e), e), i, do_not_reset = {}, + max_level = 0, processed_sequence_callback = false; // loop through matching callbacks for this key event for (i = 0; i < callbacks.length; ++i) { @@ -421,28 +422,32 @@ // callback for matching g cause otherwise you can only ever // match the first one if (callbacks[i].seq) { processed_sequence_callback = true; + // as we loop through keep track of the max + // any sequence at a lower level will be discarded + max_level = Math.max(max_level, callbacks[i].level); + // keep a list of which sequences were matches for later do_not_reset[callbacks[i].seq] = 1; _fireCallback(callbacks[i].callback, e, callbacks[i].combo); continue; } // if there were no sequence matches but we are still here // that means this is a regular match so we should fire that - if (!processed_sequence_callback && !_inside_sequence) { + if (!processed_sequence_callback && !_sequence_type) { _fireCallback(callbacks[i].callback, e, callbacks[i].combo); } } // if you are inside of a sequence and the key you are pressing // is not a modifier key then we should reset all sequences // that were not matched by this key event - if (e.type == _inside_sequence && !_isModifier(character)) { - _resetSequences(do_not_reset); + if (e.type == _sequence_type && !_isModifier(character)) { + _resetSequences(do_not_reset, max_level); } } /** * handles a keydown event @@ -572,10 +577,10 @@ * * @param {Event} e * @returns void */ var _increaseSequence = function(e) { - _inside_sequence = action; + _sequence_type = action; ++_sequence_levels[combo]; _resetSequenceTimer(); }, /**