diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2021-11-10 01:40:22 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2021-11-10 01:40:22 +0100 |
commit | 410404cfdd54c083b6609fd52334e02d320145d7 (patch) | |
tree | ac934bde696f099590496d23bdd636f691f4c637 /static/lib.ts | |
parent | Basic event modification works again. (diff) | |
download | calp-410404cfdd54c083b6609fd52334e02d320145d7.tar.gz calp-410404cfdd54c083b6609fd52334e02d320145d7.tar.xz |
Re-modularize javascript.
This moves almost everything out of globals.ts, into sepparate files.
Things are still slightly to tightly coupled. But that is worked on.
Diffstat (limited to 'static/lib.ts')
-rw-r--r-- | static/lib.ts | 35 |
1 files changed, 4 insertions, 31 deletions
diff --git a/static/lib.ts b/static/lib.ts index ee8046aa..1dfd83f4 100644 --- a/static/lib.ts +++ b/static/lib.ts @@ -1,7 +1,7 @@ export { - makeElement, date_to_percent, uid, - parseDate, gensym, to_local, boolean, - xcal, asList, round_time + makeElement, date_to_percent, + parseDate, gensym, to_local, to_boolean, + asList, round_time } /* @@ -41,8 +41,6 @@ declare global { } } -type uid = string - HTMLElement.prototype._addEventListener = HTMLElement.prototype.addEventListener; HTMLElement.prototype.addEventListener = function(name: string, proc: (e: Event) => void) { if (!this.listeners) this.listeners = {}; @@ -52,17 +50,6 @@ HTMLElement.prototype.addEventListener = function(name: string, proc: (e: Event) }; - -/* list of lists -> list of tuples */ -/* TODO figure out how to type this correctly */ -function zip(...args: any[]) { - // console.log(args); - if (args === []) return []; - return [...Array(Math.min(...args.map(x => x.length))).keys()] - .map((_, i) => args.map(lst => lst[i])); -} - - /* ----- Date Extensions ---------------------------- */ /* @@ -120,13 +107,6 @@ function parseDate(str: string): Date { return date; } -function copyDate(date: Date): Date { - let d = new Date(date); - d.utc = date.utc; - d.dateonly = date.dateonly; - return d; -} - function to_local(date: Date): Date { if (!date.utc) return date; @@ -162,11 +142,6 @@ function date_to_percent(date: Date): number /* in 0, 100 */ { /* js infix to not collide with stuff generated backend */ const gensym = (counter => (prefix = "gensym") => prefix + "js" + ++counter)(0) -function setVar(str: string, val: any) { - document.documentElement.style.setProperty("--" + str, val); -} - - function asList<T>(thing: Array<T> | T): Array<T> { if (thing instanceof Array) { return thing; @@ -176,7 +151,7 @@ function asList<T>(thing: Array<T> | T): Array<T> { } -function boolean(value: any): boolean { +function to_boolean(value: any): boolean { switch (typeof value) { case 'string': switch (value) { @@ -248,5 +223,3 @@ HTMLCollection.prototype.forEach = function(proc) { proc(el); } } - -const xcal = "urn:ietf:params:xml:ns:icalendar-2.0"; |