szurubooru/public_html/js/Keyboard.js

41 lines
749 B
JavaScript
Raw Normal View History

2014-09-19 17:37:10 +02:00
var App = App || {};
App.Keyboard = function(mousetrap) {
var oldStopCallback = mousetrap.stopCallback;
mousetrap.stopCallback = function(e, element, combo, sequence) {
if (combo.indexOf('ctrl') !== -1) {
return false;
}
return oldStopCallback.apply(mousetrap, arguments);
}
2014-09-19 17:37:10 +02:00
function keyup(key, callback) {
2014-10-18 12:42:29 +02:00
unbind(key);
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);
mousetrap.bind(key, callback);
2014-09-19 17:37:10 +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,
reset: reset,
2014-10-05 10:09:02 +02:00
unbind: unbind,
2014-09-19 17:37:10 +02:00
};
};
App.DI.register('keyboard', ['mousetrap'], App.Keyboard);