vendor/assets/javascripts/mousetrap.js in mousetrap-rails-0.0.5 vs vendor/assets/javascripts/mousetrap.js in mousetrap-rails-0.0.6

- 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.1.4 + * @version 1.2 * @url craig.is/killing/mice */ (function() { /** @@ -376,12 +376,18 @@ * * @param {Function} callback * @param {Event} e * @returns void */ - function _fireCallback(callback, e) { - if (callback(e) === false) { + function _fireCallback(callback, e, combo) { + + // if this event should not happen stop here + if (Mousetrap.stopCallback(e, e.target || e.srcElement, combo)) { + return; + } + + if (callback(e, combo) === false) { if (e.preventDefault) { e.preventDefault(); } if (e.stopPropagation) { @@ -399,16 +405,10 @@ * @param {string} character * @param {Event} e * @returns void */ function _handleCharacter(character, e) { - - // if this event should not happen stop here - if (Mousetrap.stopCallback(e, e.target || e.srcElement)) { - return; - } - var callbacks = _getMatches(character, _eventModifiers(e), e), i, do_not_reset = {}, processed_sequence_callback = false; @@ -423,18 +423,18 @@ if (callbacks[i].seq) { processed_sequence_callback = true; // keep a list of which sequences were matches for later do_not_reset[callbacks[i].seq] = 1; - _fireCallback(callbacks[i].callback, e); + _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) { - _fireCallback(callbacks[i].callback, e); + _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 @@ -585,11 +585,11 @@ * * @param {Event} e * @returns void */ _callbackAndReset = function(e) { - _fireCallback(callback, e); + _fireCallback(callback, e, combo); // we should ignore the next key up if the action is key down // or keypress. this is so if you finish a sequence and // release the key the final key will not trigger a keyup if (action !== 'keyup') { @@ -789,11 +789,11 @@ * * @param {Event} e * @param {Element} element * @return {boolean} */ - stopCallback: function(e, element) { + stopCallback: function(e, element, combo) { // if the element has the class "mousetrap" then no need to stop if ((' ' + element.className + ' ').indexOf(' mousetrap ') > -1) { return false; } @@ -805,9 +805,9 @@ // expose mousetrap to the global object window.Mousetrap = Mousetrap; // expose mousetrap as an AMD module - if (typeof define == 'function' && define.amd) { + if (typeof define === 'function' && define.amd) { define('mousetrap', function() { return Mousetrap; }); } }) ();