mousetrap-pause.js 678 B

1234567891011121314151617181920212223242526272829
  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. Mousetrap = (function(Mousetrap) {
  8. var self = Mousetrap,
  9. _originalStopCallback = self.stopCallback,
  10. enabled = true;
  11. self.stopCallback = function(e, element, combo) {
  12. if (!enabled) {
  13. return true;
  14. }
  15. return _originalStopCallback(e, element, combo);
  16. };
  17. self.pause = function() {
  18. enabled = false;
  19. };
  20. self.unpause = function() {
  21. enabled = true;
  22. };
  23. return self;
  24. }) (Mousetrap);