summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCraig Campbell <iamcraigcampbell@gmail.com>2015-03-28 14:02:38 -0400
committerCraig Campbell <iamcraigcampbell@gmail.com>2015-03-28 14:02:38 -0400
commitdddbe0a977ec799cbd603136789df27656a64f61 (patch)
tree54a82633f364d624abf18b61fcb8d807c5483c7f
parent255f6c2716a841d83402960a5a031959dd03765e (diff)
downloadmousetrap-origin/wrap2.zip
mousetrap-origin/wrap2.tar.gz
mousetrap-origin/wrap2.tar.bz2
Update all plugins to work with new version of Mousetraporigin/wrap2
-rw-r--r--plugins/bind-dictionary/mousetrap-bind-dictionary.js16
-rw-r--r--plugins/global-bind/mousetrap-global-bind.js23
-rw-r--r--plugins/pause/mousetrap-pause.js26
-rw-r--r--plugins/record/mousetrap-record.js28
4 files changed, 59 insertions, 34 deletions
diff --git a/plugins/bind-dictionary/mousetrap-bind-dictionary.js b/plugins/bind-dictionary/mousetrap-bind-dictionary.js
index dc7054a..523fc86 100644
--- a/plugins/bind-dictionary/mousetrap-bind-dictionary.js
+++ b/plugins/bind-dictionary/mousetrap-bind-dictionary.js
@@ -14,26 +14,26 @@
*
*/
/* global Mousetrap:true */
-Mousetrap = (function(Mousetrap) {
- var self = Mousetrap,
- _oldBind = self.bind,
- args;
+(function(Mousetrap) {
+ var _oldBind = Mousetrap.prototype.bind;
+ var args;
- self.bind = function() {
+ Mousetrap.prototype.bind = function() {
+ var self = this;
args = arguments;
// normal call
if (typeof args[0] == 'string' || args[0] instanceof Array) {
- return _oldBind(args[0], args[1], args[2]);
+ return _oldBind.call(self, args[0], args[1], args[2]);
}
// object passed in
for (var key in args[0]) {
if (args[0].hasOwnProperty(key)) {
- _oldBind(key, args[0][key], args[1]);
+ _oldBind.call(self, key, args[0][key], args[1]);
}
}
};
- return self;
+ Mousetrap.init();
}) (Mousetrap);
diff --git a/plugins/global-bind/mousetrap-global-bind.js b/plugins/global-bind/mousetrap-global-bind.js
index 022ceb7..1c4ac14 100644
--- a/plugins/global-bind/mousetrap-global-bind.js
+++ b/plugins/global-bind/mousetrap-global-bind.js
@@ -7,20 +7,27 @@
* Mousetrap.bindGlobal('ctrl+s', _saveChanges);
*/
/* global Mousetrap:true */
-Mousetrap = (function(Mousetrap) {
- var _globalCallbacks = {},
- _originalStopCallback = Mousetrap.stopCallback;
+(function(Mousetrap) {
+ var _globalCallbacks = {};
+ var _originalStopCallback = Mousetrap.prototype.stopCallback;
+
+ Mousetrap.prototype.stopCallback = function(e, element, combo, sequence) {
+ var self = this;
+
+ if (self.paused) {
+ return true;
+ }
- Mousetrap.stopCallback = function(e, element, combo, sequence) {
if (_globalCallbacks[combo] || _globalCallbacks[sequence]) {
return false;
}
- return _originalStopCallback(e, element, combo);
+ return _originalStopCallback.call(self, e, element, combo);
};
- Mousetrap.bindGlobal = function(keys, callback, action) {
- Mousetrap.bind(keys, callback, action);
+ Mousetrap.prototype.bindGlobal = function(keys, callback, action) {
+ var self = this;
+ self.bind(keys, callback, action);
if (keys instanceof Array) {
for (var i = 0; i < keys.length; i++) {
@@ -32,5 +39,5 @@ Mousetrap = (function(Mousetrap) {
_globalCallbacks[keys] = true;
};
- return Mousetrap;
+ Mousetrap.init();
}) (Mousetrap);
diff --git a/plugins/pause/mousetrap-pause.js b/plugins/pause/mousetrap-pause.js
index ca9cafe..0138b8a 100644
--- a/plugins/pause/mousetrap-pause.js
+++ b/plugins/pause/mousetrap-pause.js
@@ -4,26 +4,28 @@
* without having to reset Mousetrap and rebind everything
*/
/* global Mousetrap:true */
-Mousetrap = (function(Mousetrap) {
- var self = Mousetrap,
- _originalStopCallback = self.stopCallback,
- enabled = true;
+(function(Mousetrap) {
+ var _originalStopCallback = Mousetrap.prototype.stopCallback;
- self.stopCallback = function(e, element, combo) {
- if (!enabled) {
+ Mousetrap.prototype.stopCallback = function(e, element, combo) {
+ var self = this;
+
+ if (self.paused) {
return true;
}
- return _originalStopCallback(e, element, combo);
+ return _originalStopCallback.call(self, e, element, combo);
};
- self.pause = function() {
- enabled = false;
+ Mousetrap.prototype.pause = function() {
+ var self = this;
+ self.paused = true;
};
- self.unpause = function() {
- enabled = true;
+ Mousetrap.prototype.unpause = function() {
+ var self = this;
+ self.paused = false;
};
- return self;
+ Mousetrap.init();
}) (Mousetrap);
diff --git a/plugins/record/mousetrap-record.js b/plugins/record/mousetrap-record.js
index 1b93533..b7d364d 100644
--- a/plugins/record/mousetrap-record.js
+++ b/plugins/record/mousetrap-record.js
@@ -46,7 +46,7 @@
*
* @type {Function}
*/
- _origHandleKey = Mousetrap.handleKey;
+ _origHandleKey = Mousetrap.prototype.handleKey;
/**
* handles a character key event
@@ -57,6 +57,13 @@
* @returns void
*/
function _handleKey(character, modifiers, e) {
+ var self = this;
+
+ if (!self.recording) {
+ _origHandleKey.apply(self, arguments);
+ return;
+ }
+
// remember this character if we're currently recording a sequence
if (e.type == 'keydown') {
if (character.length === 1 && _recordedCharacterKey) {
@@ -157,8 +164,6 @@
_recordedSequence = [];
_recordedSequenceCallback = null;
_currentRecordedKeys = [];
-
- Mousetrap.handleKey = _origHandleKey;
}
/**
@@ -181,9 +186,20 @@
* @param {Function} callback
* @returns void
*/
- Mousetrap.record = function(callback) {
- Mousetrap.handleKey = _handleKey;
- _recordedSequenceCallback = callback;
+ Mousetrap.prototype.record = function(callback) {
+ var self = this;
+ self.recording = true;
+ _recordedSequenceCallback = function() {
+ self.recording = false;
+ callback.apply(self, arguments);
+ };
};
+ Mousetrap.prototype.handleKey = function() {
+ var self = this;
+ _handleKey.apply(self, arguments);
+ };
+
+ Mousetrap.init();
+
})(Mousetrap);