Created
September 19, 2012 03:30
-
-
Save ccampbell/3747509 to your computer and use it in GitHub Desktop.
Extends mousetrap.js to add pause/unpause support. Just include this js after mousetrap.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* adds a pause and unpause method to Mousetrap | |
* this allows you to enable or disable keyboard shortcuts | |
* without having to reset Mousetrap and rebind everything | |
*/ | |
Mousetrap = (function(Mousetrap) { | |
var self = Mousetrap, | |
_original_stop_callback = self.stopCallback, | |
enabled = true; | |
self.stopCallback = function(e, element) { | |
if (!enabled) { | |
return true; | |
} | |
return _original_stop_callback(e, element); | |
}; | |
self.pause = function() { | |
enabled = false; | |
}; | |
self.unpause = function() { | |
enabled = true; | |
}; | |
return self; | |
}) (Mousetrap); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Mousetrap=function(a){var c=a.stopCallback,b=!0;a.stopCallback=function(a,d){return!b?!0:c(a,d)};a.pause=function(){b=!1};a.unpause=function(){b=!0};return a}(Mousetrap); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment