Debian Codegraph @

plugins/bind-dictionary/mousetrap-bind-dictionary.js

raw symbols SCIP
1 /**
2 * Overwrites default Mousetrap.bind method to optionally accept
3 * an object to bind multiple key events in a single call
4 *
5 * You can pass it in like:
6 *
7 * Mousetrap.bind({
8 * 'a': function() { console.log('a'); },
9 * 'b': function() { console.log('b'); }
10 * });
11 *
12 * And can optionally pass in 'keypress', 'keydown', or 'keyup'
13 * as a second argument
14 *
15 */
16 /* global Mousetrap:true */
17 (function(Mousetrap) {
18 var _oldBind = Mousetrap.prototype.bind;
19 var args;
20
21 Mousetrap.prototype.bind = function() {
22 var self = this;
23 args = arguments;
24
25 // normal call
26 if (typeof args[0] == 'string' || args[0] instanceof Array) {
27 return _oldBind.call(self, args[0], args[1], args[2]);
28 }
29
30 // object passed in
31 for (var key in args[0]) {
32 if (args[0].hasOwnProperty(key)) {
33 _oldBind.call(self, key, args[0][key], args[1]);
34 }
35 }
36 };
37
38 Mousetrap.init();
39 }) (Mousetrap);