2014-09-19 17:37:10 +02:00
|
|
|
var App = App || {};
|
|
|
|
|
2014-10-26 22:51:48 +01:00
|
|
|
App.Keyboard = function(jQuery, mousetrap) {
|
2014-09-19 17:37:10 +02:00
|
|
|
|
2014-10-18 15:37:04 +02:00
|
|
|
var oldStopCallback = mousetrap.stopCallback;
|
|
|
|
mousetrap.stopCallback = function(e, element, combo, sequence) {
|
|
|
|
if (combo.indexOf('ctrl') !== -1) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-10-26 22:51:48 +01:00
|
|
|
var $focused = jQuery(':focus').eq(0);
|
|
|
|
if ($focused.length && $focused.prop('tagName').match(/embed|object/i)) {
|
|
|
|
return true;
|
|
|
|
}
|
2014-10-18 15:37:04 +02:00
|
|
|
return oldStopCallback.apply(mousetrap, arguments);
|
2014-10-19 12:10:22 +02:00
|
|
|
};
|
2014-10-18 15:37:04 +02:00
|
|
|
|
2014-09-19 17:37:10 +02:00
|
|
|
function keyup(key, callback) {
|
2014-10-18 12:42:29 +02:00
|
|
|
unbind(key);
|
2014-10-18 15:21:38 +02:00
|
|
|
mousetrap.bind(key, callback, 'keyup');
|
2014-09-19 17:37:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function keydown(key, callback) {
|
2014-10-18 12:42:29 +02:00
|
|
|
unbind(key);
|
2014-10-18 15:21:38 +02:00
|
|
|
mousetrap.bind(key, callback);
|
2014-09-19 17:37:10 +02:00
|
|
|
}
|
|
|
|
|
2014-09-29 18:11:21 +02:00
|
|
|
function reset() {
|
|
|
|
mousetrap.reset();
|
|
|
|
}
|
|
|
|
|
2014-10-05 10:09:02 +02:00
|
|
|
function unbind(key) {
|
2014-10-18 12:42:29 +02:00
|
|
|
mousetrap.unbind(key, 'keyup');
|
2014-10-05 10:09:02 +02:00
|
|
|
mousetrap.unbind(key);
|
|
|
|
}
|
|
|
|
|
2014-09-19 17:37:10 +02:00
|
|
|
return {
|
|
|
|
keydown: keydown,
|
|
|
|
keyup: keyup,
|
2014-09-29 18:11:21 +02:00
|
|
|
reset: reset,
|
2014-10-05 10:09:02 +02:00
|
|
|
unbind: unbind,
|
2014-09-19 17:37:10 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2014-10-26 22:51:48 +01:00
|
|
|
App.DI.register('keyboard', ['jQuery', 'mousetrap'], App.Keyboard);
|