Skip to content

Instantly share code, notes, and snippets.

@ccampbell
Created September 19, 2012 03:30
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ccampbell/3747509 to your computer and use it in GitHub Desktop.
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.
/**
* 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);
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