From a64c2a665af1abe0b91f1c5eb1f97df91ed8a4de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sun, 3 Oct 2021 17:48:13 +0200 Subject: Further work, rework popup. --- static/popup.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'static/popup.js') diff --git a/static/popup.js b/static/popup.js index e19db6f2..0b04b280 100644 --- a/static/popup.js +++ b/static/popup.js @@ -2,12 +2,14 @@ /* event component => coresponding popup component */ function event_from_popup(popup) { - return document.getElementById(popup.id.substr(5)) + // return document.getElementById(popup.id.substr(5)) + return find_block(popup.closest('[data-uid]').dataset.uid) } /* popup component => coresponding event component */ function popup_from_event(event) { - return document.getElementById("popup" + event.id); + // return document.getElementById("popup" + event.id); + return find_popup(event.closest('[data-uid]').dataset.uid) } /* hides given popup */ @@ -17,7 +19,7 @@ function close_popup(popup) { /* hides all popups */ function close_all_popups () { - for (let popup of document.querySelectorAll(".popup-container.visible")) { + for (let popup of document.querySelectorAll("popup-element.visible")) { close_popup(popup); } } @@ -51,8 +53,8 @@ function open_popup(popup) { } /* toggles open/closed status of popup given by id */ -function toggle_popup(popup_id) { - let popup = document.getElementById(popup_id); +function toggle_popup(popup) { + // let popup = document.getElementById(popup_id); if (popup.classList.contains("visible")) { close_popup(popup); } else { -- cgit v1.2.3 From c6c65f9e8273a5bc1b2ac1155d66003d2b98591c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 4 Oct 2021 17:40:59 +0200 Subject: {.js => .ts} on relavant files. --- static/popup.js | 105 -------------------------------------------------------- 1 file changed, 105 deletions(-) delete mode 100644 static/popup.js (limited to 'static/popup.js') diff --git a/static/popup.js b/static/popup.js deleted file mode 100644 index 0b04b280..00000000 --- a/static/popup.js +++ /dev/null @@ -1,105 +0,0 @@ - - -/* event component => coresponding popup component */ -function event_from_popup(popup) { - // return document.getElementById(popup.id.substr(5)) - return find_block(popup.closest('[data-uid]').dataset.uid) -} - -/* popup component => coresponding event component */ -function popup_from_event(event) { - // return document.getElementById("popup" + event.id); - return find_popup(event.closest('[data-uid]').dataset.uid) -} - -/* hides given popup */ -function close_popup(popup) { - popup.classList.remove("visible"); -} - -/* hides all popups */ -function close_all_popups () { - for (let popup of document.querySelectorAll("popup-element.visible")) { - close_popup(popup); - } -} - -/* open given popup */ -function open_popup(popup) { - popup.classList.add("visible"); - let element = event_from_popup(popup); - // let root = document.body; - let root; - switch (VIEW) { - case 'week': - root = document.getElementsByClassName("days")[0]; - break; - case 'month': - default: - root = document.body; - break; - } - /* start sets offset between top left corner - of event in calendar and popup. 10, 10 soo old - event is still visible */ - let offsetX = 10, offsetY = 10; - while (element !== root) { - offsetX += element.offsetLeft; - offsetY += element.offsetTop; - element = element.offsetParent; - } - popup.style.left = offsetX + "px"; - popup.style.top = offsetY + "px"; -} - -/* toggles open/closed status of popup given by id */ -function toggle_popup(popup) { - // let popup = document.getElementById(popup_id); - if (popup.classList.contains("visible")) { - close_popup(popup); - } else { - open_popup(popup); - } -} - -/* Code for managing "selected" popup */ -/* Makes the popup last hovered over the selected popup, moving it to - * the top, and allowing global keyboard bindings to affect it. */ - -let activePopup; - -for (let popup of document.querySelectorAll('.popup-container')) { - /* TODO possibly only change "active" element after a fraction of - * a second, for example when moving between tabs */ - popup.addEventListener('mouseover', function () { - /* This is ever so slightly inefficient, - but it really dosen't mammet */ - for (let other of - document.querySelectorAll('.popup-container')) - { - /* TODO get this from somewhere */ - /* Currently it's manually copied from the stylesheet */ - other.style['z-index'] = 1000; - } - popup.style['z-index'] += 1; - activePopup = popup; - }); -} - -document.addEventListener('keydown', function (event) { - /* Physical key position, names are what that key would - be in QWERTY */ - let i = ({ - 'KeyQ': 0, - 'KeyW': 1, - 'KeyE': 2, - 'KeyR': 3, - })[event.code]; - if (i === undefined) return - if (! activePopup) return; - let element = activePopup.querySelectorAll(".tab > label")[i]; - if (! element) return; - element.click(); -}); - -/* END Code for managing "selected" popup */ -- cgit v1.2.3