aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-07-07 20:29:11 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2022-07-07 21:14:09 +0200
commit6c44e85b820902a4d7bb640324d5ed927e414bcb (patch)
tree4fbf828cf87b65d2aeb52d5038d46f40d548f2c0
parentImport missing car+cdr. (diff)
downloadcalp-6c44e85b820902a4d7bb640324d5ed927e414bcb.tar.gz
calp-6c44e85b820902a4d7bb640324d5ed927e414bcb.tar.xz
Extend javascript formatters to also take VEvent.
-rw-r--r--doc/ref/javascript/formatters.texi9
-rw-r--r--static/components/vevent-description.ts4
-rw-r--r--static/formatters.ts15
-rw-r--r--static/user/user-additions.js4
4 files changed, 18 insertions, 14 deletions
diff --git a/doc/ref/javascript/formatters.texi b/doc/ref/javascript/formatters.texi
index 16a988c4..71394b39 100644
--- a/doc/ref/javascript/formatters.texi
+++ b/doc/ref/javascript/formatters.texi
@@ -4,13 +4,14 @@
Formatting procedures used by some components.
@c TODO can we have a backref of every node containing @ref{formatters-proc}?
-@deftypevar {Map<string, (e:HTMLElement, s:any) => void>} formatters
+@deftypevar {Map<string, (e:HTMLElement, d:VEvent, s:any) => void>} formatters
@anchor{formatters-proc}
-Each procedure takes two arguments. The HTML-element which contents
-should be replaced, along with the target value, as returned by @ref{VEvent.getProperty}.
+Each procedure takes three arguments. The HTML-element which contents
+should be replaced, the VEvent containing all data, and the target
+value, as returned by @ref{VEvent.getProperty}.
@end deftypevar
-@deftypevr {Window Value} {Map<string, (e:HTMLElement, s:string) => void>} formatters
+@deftypevr {Window Value} {Map<string, (e:HTMLElement, d:VEvent, s:string) => void>} formatters
Same object as @xref{formatters-proc}. Provided for @xref{user-additions.js}.
@end deftypevr
diff --git a/static/components/vevent-description.ts b/static/components/vevent-description.ts
index f0d224be..463725f1 100644
--- a/static/components/vevent-description.ts
+++ b/static/components/vevent-description.ts
@@ -28,8 +28,8 @@ class ComponentDescription extends ComponentVEvent {
if ((d = data.getProperty(p))) {
let key = p.toLowerCase();
let f = formatters.get(key);
- if (f) f(el, d);
- else window.formatters.get('default')!(el, d);
+ if (f) f(el, data, d);
+ else window.formatters.get('default')!(el, data, d);
}
}
diff --git a/static/formatters.ts b/static/formatters.ts
index 70f63504..5605e051 100644
--- a/static/formatters.ts
+++ b/static/formatters.ts
@@ -3,18 +3,21 @@ export {
}
import { makeElement } from './lib'
+import { VEvent } from './vevent'
+
+type formatter = (e: HTMLElement, d: VEvent, s: any) => void
declare global {
interface Window {
- formatters: Map<string, (e: HTMLElement, s: any) => void>;
+ formatters: Map<string, formatter>;
}
}
-let formatters: Map<string, (e: HTMLElement, s: any) => void>;
+let formatters: Map<string, formatter>;
formatters = window.formatters = new Map();
-formatters.set('categories', (el, d) => {
+formatters.set('categories', (el, _, d) => {
for (let item of d) {
let q = encodeURIComponent(
`(member "${item}" (or (prop event (quote CATEGORIES)) (quote ())))`)
@@ -25,7 +28,7 @@ formatters.set('categories', (el, d) => {
}
})
-function format_time_tag(el: HTMLElement, d: any): void {
+function format_time_tag(el: HTMLElement, ev: VEvent, d: any): void {
if (el instanceof HTMLTimeElement) {
if (d instanceof Date) {
let fmt = '';
@@ -40,13 +43,13 @@ function format_time_tag(el: HTMLElement, d: any): void {
}
}
- formatters.get('default')!(el, d);
+ formatters.get('default')!(el, ev, d);
}
formatters.set('dtstart', format_time_tag)
formatters.set('dtend', format_time_tag)
-formatters.set('default', (el, d) => {
+formatters.set('default', (el, _, d) => {
let fmt;
if ((fmt = el.dataset.fmt)) {
el.textContent = d.format(fmt);
diff --git a/static/user/user-additions.js b/static/user/user-additions.js
index c0579df5..5f5357eb 100644
--- a/static/user/user-additions.js
+++ b/static/user/user-additions.js
@@ -1,4 +1,4 @@
-window.formatters.set('description', (el, d) => {
+window.formatters.set('description', (el, ev, d) => {
if (/<\/?\w+( +\w+(=["']?\w+["']?)?)* *\/?>/.exec(d)) {
/* Assume that the text is HTML if it contains something which looks
like an HTML tag */
@@ -40,7 +40,7 @@ window.salar = new Promise((resolve, reject) =>
)
-window.formatters.set('location', async function(el, d) {
+window.formatters.set('location', async function(el, _, d) {
let rx = /Lokal: (.*)/
let m = rx.exec(d)
if (! m) {