aboutsummaryrefslogtreecommitdiff
path: root/static/popup.ts
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2021-12-10 00:16:25 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2021-12-10 00:48:09 +0100
commitde593cf0d4a6a082f0c42e00be395e0f6cf49e96 (patch)
tree578e4d10aabc3bfac98d9962ea4644b357fbb044 /static/popup.ts
parentRemove vcal.js. (diff)
downloadcalp-de593cf0d4a6a082f0c42e00be395e0f6cf49e96.tar.gz
calp-de593cf0d4a6a082f0c42e00be395e0f6cf49e96.tar.xz
Remove popup.ts, migrating all functionality elsewhere.
The simple procedures - close_popup - open_popup - toggle_popup - find_popup Were mostly here for legacy. The procedures - popup_from_event - event_from_popup where holdovers from the old way of finding popups, and should be done through the VEvent objects now. close_all_popups was used only once, so the code was moved inline. Finally, moving the last hovered over popup to the top, along with tab switch keybings were restored, and moved to propper places.
Diffstat (limited to 'static/popup.ts')
-rw-r--r--static/popup.ts107
1 files changed, 0 insertions, 107 deletions
diff --git a/static/popup.ts b/static/popup.ts
deleted file mode 100644
index 69edbb6e..00000000
--- a/static/popup.ts
+++ /dev/null
@@ -1,107 +0,0 @@
-import { find_block } from './globals'
-import { PopupElement } from './components/popup-element'
-import { ComponentBlock } from './components/vevent-block'
-import { uid } from './types'
-
-export {
- event_from_popup, popup_from_event, close_popup,
- close_all_popups, open_popup, toggle_popup, activePopup,
- find_popup
-}
-
-/* TODO rewrite most of this */
-
-/* event component => coresponding popup component */
-function event_from_popup(popup: PopupElement): ComponentBlock | null {
- // return document.getElementById(popup.id.substr(5))
- let el = popup.closest('[data-uid]')
- if (!el) return null;
- let uid = (el as HTMLElement).dataset.uid
- if (!uid) return null;
- return find_block(uid)
-}
-
-/* popup component => coresponding event component */
-function popup_from_event(event: ComponentBlock): PopupElement | null {
- // return document.getElementById("popup" + event.id);
- // return find_popup(event.closest('[data-uid]').dataset.uid)
- let el = event.closest('[data-uid]')
- if (!el) return null;
- let uid = (el as HTMLElement).dataset.uid
- if (!uid) return null;
- return find_popup(uid)
-}
-
-/* hides given popup */
-function close_popup(popup: PopupElement): void {
- popup.visible = false;
-}
-
-/* hides all popups */
-function close_all_popups() {
- for (let popup of document.querySelectorAll("popup-element[visible]")) {
- close_popup(popup as PopupElement)
- }
-}
-
-
-function find_popup(uid: uid): PopupElement | null {
- // for (let el of vcal_objects[uid].registered) {
- // if (el.tagName === 'popup-element') {
- // return el;
- // }
- // }
- // throw 'Popup not fonud';
- return document.querySelector(`popup-element[data-uid="${uid}"]`)
-}
-
-/* open given popup */
-function open_popup(popup: PopupElement) {
- popup.visible = true;
-}
-
-/* toggles open/closed status of popup given by id */
-function toggle_popup(popup: PopupElement) {
- popup.visible = !popup.visible;
-}
-
-/* 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: PopupElement | undefined;
-
-for (let popup of document.querySelectorAll('popup-element')) {
- /* 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-element')) {
- /* TODO get this from somewhere */
- /* Currently it's manually copied from the stylesheet */
- ((other as PopupElement).style as any)['z-index'] = 1000;
- }
- ((popup as PopupElement).style as any)['z-index'] += 1;
- activePopup = popup as PopupElement
- });
-}
-
-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: HTMLLabelElement | undefined = activePopup.querySelectorAll(".tab > label")[i] as HTMLLabelElement;
- if (!element) return;
- element.click();
-});
-
-/* END Code for managing "selected" popup */