From a5c4962f1b3c9b2e4c23a7e3912af2dfcb4f0507 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sun, 12 Dec 2021 23:29:41 +0100 Subject: Merge draggable into popup-element. --- static/dragable.ts | 46 ---------------------------------------------- 1 file changed, 46 deletions(-) delete mode 100644 static/dragable.ts (limited to 'static/dragable.ts') diff --git a/static/dragable.ts b/static/dragable.ts deleted file mode 100644 index b32bb608..00000000 --- a/static/dragable.ts +++ /dev/null @@ -1,46 +0,0 @@ -export { bind_popup_control } - -/* - Apply to a given component to make it draggable. - Drag area (usually a title bar) should be be the only argument. - It is REQUIRED that the object which should be moved have the class - 'popup-container'; -*/ - - -/* - Given the navbar of a popup, make it dragable. - */ -function bind_popup_control(nav: HTMLElement) { - - // if (!nav.closest('popup-element')) { - // console.log(nav); - // throw TypeError('not a popup container'); - // } - - nav.addEventListener('mousedown', function(e) { - /* Ignore mousedown on children */ - if (e.target != nav) return; - nav.style.cursor = "grabbing"; - nav.dataset.grabbed = "true"; - nav.dataset.grabPoint = e.clientX + ";" + e.clientY; - // let popup = nav.closest(".popup-container"); - let popup = nav.closest("popup-element") as HTMLElement; - nav.dataset.startPoint = popup.offsetLeft + ";" + popup.offsetTop; - }) - window.addEventListener('mousemove', function(e) { - if (nav.dataset.grabbed) { - let [x, y] = nav.dataset.grabPoint!.split(";").map(Number); - let [startX, startY] = nav.dataset.startPoint!.split(";").map(Number); - // let popup = nav.closest(".popup-container"); - let popup = nav.closest("popup-element") as HTMLElement; - - popup.style.left = startX + (e.clientX - x) + "px"; - popup.style.top = startY + (e.clientY - y) + "px"; - } - }); - window.addEventListener('mouseup', function() { - nav.dataset.grabbed = ""; - nav.style.cursor = ""; - }); -} -- cgit v1.2.3