szurubooru/public_html/js/Keyboard.js

38 lines
617 B
JavaScript
Raw Normal View History

2014-09-19 17:37:10 +02:00
var App = App || {};
App.Keyboard = function(mousetrap) {
function keyup(key, callback) {
mousetrap.bind(key, simpleKeyPressed(callback), 'keyup');
}
function keydown(key, callback) {
mousetrap.bind(key, simpleKeyPressed(callback));
}
function simpleKeyPressed(callback) {
return function(e) {
if (!e.altKey && !e.ctrlKey) {
callback();
}
};
}
function reset() {
mousetrap.reset();
}
2014-10-05 10:09:02 +02:00
function unbind(key) {
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);