mirror of
https://github.com/discourse/discourse.git
synced 2024-12-16 06:25:58 +08:00
090e9c8432
- Uses a Mousetrap plugin for global shortcuts - Implemented for search `ctrl+alt+f` and composer fullscreen `shift+f11` shortcuts
44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
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 */
|
|
(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;
|
|
}
|
|
|
|
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();
|
|
}) (Mousetrap);
|