diff options
Diffstat (limited to 'presentation/plugin/cursor/cursor.js')
-rw-r--r-- | presentation/plugin/cursor/cursor.js | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/presentation/plugin/cursor/cursor.js b/presentation/plugin/cursor/cursor.js new file mode 100644 index 0000000..f475fb2 --- /dev/null +++ b/presentation/plugin/cursor/cursor.js @@ -0,0 +1,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); |