Skip to content
This repository
Browse code

Merge pull request #31 from davoclavo/unbind

Add unbind method
  • Loading branch information...
commit 049774dfb5335f3360a5164f416160182656ff03 2 parents 91d4eb3 + 6fd0bc4
Craig Campbell authored July 09, 2012

Showing 1 changed file with 20 additions and 0 deletions. Show diff stats Hide diff stats

  1. 20  mousetrap.js
20  mousetrap.js
@@ -696,6 +696,26 @@ window.Mousetrap = (function() {
696 696
         },
697 697
 
698 698
         /**
  699
+         * unbinds an event to mousetrap
  700
+         *
  701
+         * the unbinding just sets the callback function of that keycombo as an empty function
  702
+         * and deletes the corresponding key in the _direct_map dict.
  703
+         * the keycombo+action has to be exactly the same as it was defined in the bind method
  704
+         *
  705
+         * @param {string|Array} keys
  706
+         * @param {string} action - 'up' for keyup anything else assumes keydown
  707
+         * @returns boolean
  708
+         */
  709
+        unbind: function(keys, action) {
  710
+            if(_direct_map[keys + ':' + action]){
  711
+                delete _direct_map[keys + ':' + action];
  712
+                this.bind(keys, function(){}, action);
  713
+                return true;
  714
+            }
  715
+            return false;
  716
+        },
  717
+
  718
+        /**
699 719
          * triggers an event that has already been bound
700 720
          *
701 721
          * @param {string} keys

0 notes on commit 049774d

Please sign in to comment.
Something went wrong with that request. Please try again.