aboutsummaryrefslogtreecommitdiff
path: root/client/js/util/keyboard.js
blob: 3e3158a22b054863fe40024c4089b873db6d32d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'use strict';

const mousetrap = require('mousetrap');
const settings = require('../models/settings.js');

let paused = false;
const _originalStopCallback = mousetrap.prototype.stopCallback;
mousetrap.prototype.stopCallback = function(...args) {
    var self = this;
    if (paused) {
        return true;
    }
    return _originalStopCallback.call(self, ...args);
};

function bind(hotkey, func) {
    if (settings.get().keyboardShortcuts) {
        mousetrap.bind(hotkey, func);
        return true;
    }
    return false;
}
function bindElement(element, hotkey, func) {
    if (settings.get().keyboardShortcuts) {
        mousetrap(element).bind(hotkey, func);
        return true;
    }
    return false;
}

function unbind(hotkey) {
    mousetrap.unbind(hotkey);
}

module.exports = {
    bind: bind,
    bindElement: bindElement,
    unbind: unbind,
    pause: () => { paused = true; },
    unpause: () => { paused = false; },
};

© 2015 - 2026 Jakob L. Kreuze