1
0

mousetrap-pause.js 779 B

12345678910111213141516171819202122232425262728293031
  1. /**
  2. * adds a pause and unpause method to Mousetrap
  3. * this allows you to enable or disable keyboard shortcuts
  4. * without having to reset Mousetrap and rebind everything
  5. */
  6. /* global Mousetrap:true */
  7. (function(Mousetrap) {
  8. var _originalStopCallback = Mousetrap.prototype.stopCallback;
  9. Mousetrap.prototype.stopCallback = function(e, element, combo) {
  10. var self = this;
  11. if (self.paused) {
  12. return true;
  13. }
  14. return _originalStopCallback.call(self, e, element, combo);
  15. };
  16. Mousetrap.prototype.pause = function() {
  17. var self = this;
  18. self.paused = true;
  19. };
  20. Mousetrap.prototype.unpause = function() {
  21. var self = this;
  22. self.paused = false;
  23. };
  24. Mousetrap.init();
  25. }) (Mousetrap);