summaryrefslogtreecommitdiff
path: root/client/js/util/keyboard.js
blob: c66eda1c0b0cd9137c6282107fc3114328135da3 (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
42
43
44
45
46
"use strict";

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

let paused = false;
const _originalStopCallback = mousetrap.prototype.stopCallback;
// eslint-disable-next-line func-names
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;
    },
};