From 93c40e8eeaef8e1609759fb1f0cad1fc9285ab86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Thu, 11 Nov 2021 16:28:49 +0100 Subject: Made VIEW and EDIT_MODE correctly global. --- static/globals.ts | 7 ++----- static/popup.ts | 4 ++-- static/script.ts | 9 +++++++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/static/globals.ts b/static/globals.ts index be79dae7..b0871aa2 100644 --- a/static/globals.ts +++ b/static/globals.ts @@ -1,6 +1,5 @@ export { find_block, - VIEW, EDIT_MODE, vcal_objects, event_calendar_mapping } @@ -13,14 +12,12 @@ const event_calendar_mapping: Map = new Map; declare global { interface Window { vcal_objects: Map; + VIEW: 'month' | 'week'; + EDIT_MODE: boolean; } } window.vcal_objects = vcal_objects; -declare let VIEW: 'month' | 'week' -declare let EDIT_MODE: boolean - - function find_block(uid: uid): HTMLElement | null { let obj = vcal_objects.get(uid) if (obj === undefined) { diff --git a/static/popup.ts b/static/popup.ts index ce643854..908787ae 100644 --- a/static/popup.ts +++ b/static/popup.ts @@ -1,4 +1,4 @@ -import { VIEW, find_block } from './globals' +import { find_block } from './globals' import { PopupElement } from './components/popup-element' import { uid } from './types' @@ -60,7 +60,7 @@ function open_popup(popup: HTMLElement) { let element = event_from_popup(popup); // let root = document.body; let root; - switch (VIEW) { + switch (window.VIEW) { case 'week': root = document.getElementsByClassName("days")[0]; break; diff --git a/static/script.ts b/static/script.ts index b9336165..655d1e36 100644 --- a/static/script.ts +++ b/static/script.ts @@ -2,7 +2,7 @@ import { close_all_popups } from './popup' import { VEvent, xml_to_vcal } from './vevent' import { SmallcalCellHighlight, Timebar } from './clock' import { makeElement } from './lib' -import { vcal_objects, event_calendar_mapping, EDIT_MODE } from './globals' +import { vcal_objects, event_calendar_mapping } from './globals' import { open_popup } from './popup' import { EventCreator } from './event-creator' import { PopupElement } from './components/popup-element' @@ -14,6 +14,11 @@ import { initialize_components } from './elements' window.addEventListener('load', function() { + /* + TODO possibly check here that both window.EDIT_MODE and window.VIEW have + defined values. + */ + // let json_objects_el = document.getElementById('json-objects'); let div = document.getElementById('xcal-data')!; let vevents = div.firstElementChild!.children; @@ -72,7 +77,7 @@ window.addEventListener('load', function() { }, 1000 * 60); /* Is event creation active? */ - if (true && EDIT_MODE) { + if (true && window.EDIT_MODE) { let eventCreator = new EventCreator; for (let c of document.getElementsByClassName("events")) { if (!(c instanceof HTMLElement)) continue; -- cgit v1.2.3