From 8ec2f441d40ab89b40cc3158f65c914eff497cee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 4 Oct 2021 23:18:24 +0200 Subject: Major typescript work. --- static/dragable.ts | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'static/dragable.ts') diff --git a/static/dragable.ts b/static/dragable.ts index 6eb0b999..20acdd3a 100644 --- a/static/dragable.ts +++ b/static/dragable.ts @@ -9,34 +9,35 @@ /* Given the navbar of a popup, make it dragable. */ -function bind_popup_control (nav) { +function bind_popup_control(nav: HTMLElement) { - if (! nav.closest('.popup-container')) { - throw TypeError('not a popup container'); - } + // if (!nav.closest('popup-element')) { + // console.log(nav); + // throw TypeError('not a popup container'); + // } - nav.onmousedown = function (e) { + nav.onmousedown = 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"); + let popup = nav.closest("popup-element") as HTMLElement; nav.dataset.startPoint = popup.offsetLeft + ";" + popup.offsetTop; } - window.addEventListener('mousemove', function (e) { + 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 [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"); + 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 () { + window.addEventListener('mouseup', function() { nav.dataset.grabbed = ""; nav.style.cursor = ""; }); -- cgit v1.2.3