Added ability to turn keyboard shortcuts off

This commit is contained in:
Marcin Kurczewski
2015-05-14 23:04:30 +02:00
parent 8d119d2b62
commit c569504ce7
6 changed files with 50 additions and 4 deletions

View File

@ -1,7 +1,8 @@
var App = App || {};
App.Keyboard = function(jQuery, mousetrap) {
App.Keyboard = function(jQuery, mousetrap, browsingSettings) {
var enabled = browsingSettings.getSettings().keyboardShortcuts;
var oldStopCallback = mousetrap.stopCallback;
mousetrap.stopCallback = function(e, element, combo, sequence) {
if (combo.indexOf('ctrl') === -1 && e.ctrlKey) {
@ -28,12 +29,16 @@ App.Keyboard = function(jQuery, mousetrap) {
function keyup(key, callback) {
unbind(key);
mousetrap.bind(key, callback, 'keyup');
if (enabled) {
mousetrap.bind(key, callback, 'keyup');
}
}
function keydown(key, callback) {
unbind(key);
mousetrap.bind(key, callback);
if (enabled) {
mousetrap.bind(key, callback);
}
}
function reset() {
@ -53,4 +58,4 @@ App.Keyboard = function(jQuery, mousetrap) {
};
};
App.DI.register('keyboard', ['jQuery', 'mousetrap'], App.Keyboard);
App.DI.register('keyboard', ['jQuery', 'mousetrap', 'browsingSettings'], App.Keyboard);