password-manager/frontend/delta/js/MouseTrap/mousetrap-global-bind.js
Giulio Cesare Solaroli 7a116201f7 Removed clipperz copyright/license note
The script that automatically adds the copyright notice was wrongly configured.
2015-03-22 21:10:48 +01:00

37 lines
987 B
JavaScript

/**
* 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 */
Mousetrap = (function(Mousetrap) {
var _globalCallbacks = {},
_originalStopCallback = Mousetrap.stopCallback;
Mousetrap.stopCallback = function(e, element, combo, sequence) {
if (_globalCallbacks[combo] || _globalCallbacks[sequence]) {
return false;
}
return _originalStopCallback(e, element, combo);
};
Mousetrap.bindGlobal = function(keys, callback, action) {
Mousetrap.bind(keys, callback, action);
if (keys instanceof Array) {
for (var i = 0; i < keys.length; i++) {
_globalCallbacks[keys[i]] = true;
}
return;
}
_globalCallbacks[keys] = true;
};
return Mousetrap;
}) (Mousetrap);