From 235316966e40ce2b28d94557a280f1bc3b9c2eef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 13 Jul 2020 00:51:36 +0200 Subject: Add basic movement of popups. --- static/script.js | 22 ++++++++++++++++++++++ static/style.css | 5 +++++ 2 files changed, 27 insertions(+) diff --git a/static/script.js b/static/script.js index 008cc1e2..af0fba8f 100644 --- a/static/script.js +++ b/static/script.js @@ -324,6 +324,28 @@ window.onload = function () { } } + for (let nav of document.getElementsByClassName("popup-control")) { + nav.onmousedown = function (e) { + if (e.target != nav) return; + nav.style.cursor = "grabbing"; + nav.dataset.grabbed = "true"; + nav.dataset.grabPoint = e.layerX + ";" + e.layerY; + } + nav.onmousemove = function (e) { + if (nav.dataset.grabbed) { + let [x, y] = nav.dataset.grabPoint.split(";").map(Number); + let popup = nav.closest(".popup-container"); + + popup.style.left = popup.offsetLeft + (e.layerX - x) + "px"; + popup.style.top = popup.offsetTop + (e.layerY - y) + "px"; + } + } + nav.onmouseup = function () { + nav.dataset.grabbed = ""; + nav.style.cursor = ""; + } + } + for (let el of document.getElementsByClassName("event")) { /* Popup script replaces need for anchors to events. On mobile they also have the problem that they make diff --git a/static/style.css b/static/style.css index 88342c75..abb4f8c7 100644 --- a/static/style.css +++ b/static/style.css @@ -644,6 +644,9 @@ along with their colors. display: none; position: absolute; z-index: 10; + + left: 10px; + top: -50px; } .popup-container.visible { @@ -680,6 +683,8 @@ along with their colors. /* not needed, but the icons aren't text and should therefor not be copied */ user-select: none; + + cursor: grab; } .popup-control .btn { -- cgit v1.2.3