Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/mousetrap/plugins/global-bind/mousetrap-global-bind.js')
-rw-r--r--node_modules/mousetrap/plugins/global-bind/mousetrap-global-bind.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/node_modules/mousetrap/plugins/global-bind/mousetrap-global-bind.js b/node_modules/mousetrap/plugins/global-bind/mousetrap-global-bind.js
new file mode 100644
index 0000000000..6b86a99fbf
--- /dev/null
+++ b/node_modules/mousetrap/plugins/global-bind/mousetrap-global-bind.js
@@ -0,0 +1,46 @@
+/**
+ * adds a bindGlobal method to Mousetrap that allows you to
+ * bind specific keyboard shortcuts that will still work
+ * inside a text input field
+ *
+ * usage:
+ * Mousetrap.bindGlobal('ctrl+s', _saveChanges);
+ */
+/* global Mousetrap:true */
+(function(Mousetrap) {
+ if (! Mousetrap) {
+ return;
+ }
+ var _globalCallbacks = {};
+ var _originalStopCallback = Mousetrap.prototype.stopCallback;
+
+ Mousetrap.prototype.stopCallback = function(e, element, combo, sequence) {
+ var self = this;
+
+ if (self.paused) {
+ return true;
+ }
+
+ if (_globalCallbacks[combo] || _globalCallbacks[sequence]) {
+ return false;
+ }
+
+ return _originalStopCallback.call(self, e, element, combo);
+ };
+
+ 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++) {
+ _globalCallbacks[keys[i]] = true;
+ }
+ return;
+ }
+
+ _globalCallbacks[keys] = true;
+ };
+
+ Mousetrap.init();
+}) (typeof Mousetrap !== "undefined" ? Mousetrap : undefined);