summaryrefslogtreecommitdiffhomepage
path: root/presentation/plugin/cursor/cursor.js
blob: f475fb2362d586e71fbc2c71f16931703228f17f (plain) (blame)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
(function (doc, win) {
    "use strict";

    const initial_css = {
        position: "absolute",
        float: "left",
        borderRadius: "50%",
        width: "30px",
        height: "30px",
        backgroundColor: "rgba(255, 0, 0, 0.4)",
        zIndex: 20,
        display: "none",
    };
    let toggleBind = false;
    const body = doc.getElementsByTagName("body")[0];
    let tail = doc.createElement("div");

    function initModule() {
        Object.assign(tail.style, initial_css);
        body.appendChild(tail);
        setKeyboards();
        if (window.Reveal.registerKeyboardShortcut) {
            Reveal.registerKeyboardShortcut("CAPSLOCK", "Toggle Mouse Pointer");
        }
    }

    function mouse_pointing(e) {
        tail.style.display = "block";
        tail.style.left = e.pageX - 15 + "px";
        tail.style.top = e.pageY - 15 + "px";
    }

    function toogleMousePointer() {
        if (!toggleBind) {
            document.removeEventListener("mousemove", mouse_pointing);
            tail.style.display = "none";
            body.style.cursor = "auto";
        } else {
            tail.style.display = "block";
            tail.style.width = "30px";
            tail.style.height = "30px";
            body.style.cursor = "none";
            document.addEventListener("mousemove", mouse_pointing);
        }
    }

    function setKeyboards(params) {
        document.addEventListener(
            "keydown",
            function (event) {
                if (event.keyCode === 20) {
                    event.preventDefault();
                    toggleBind = !toggleBind;
                    toogleMousePointer();
                }
            },
            false
        );
    }

    initModule();
})(document, window);