diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-03-15 01:37:05 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-03-15 02:25:27 +0100 |
commit | a313eed22e7c4f222e5101b96df27d98e5a0ed1d (patch) | |
tree | 070bab81a69eb2a4f27114cd76bf6a308c720ab9 /static/user/user-additions.js | |
parent | Introduce user-additions in frontend. (diff) | |
download | calp-a313eed22e7c4f222e5101b96df27d98e5a0ed1d.tar.gz calp-a313eed22e7c4f222e5101b96df27d98e5a0ed1d.tar.xz |
Add JS user config for hyperlinking locations at LiU.
This is rather specific to me, but we already have the president with
the bundled config.scm file.
Diffstat (limited to '')
-rw-r--r-- | static/user/user-additions.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/static/user/user-additions.js b/static/user/user-additions.js index 59a6248d..3b39b3ad 100644 --- a/static/user/user-additions.js +++ b/static/user/user-additions.js @@ -9,3 +9,40 @@ window.formatters.set('description', (el, d) => { el.innerHTML = d.replaceAll(/https?:\/\/\S+/g, '<a href="$&">$&</a>'); } }) + +/* This location formatter is generally not for general use. + It holds a small lookup table of "all" locations at Linköping University, + and makes location names from their calendar system clickable. + + To obtain salar.json, run scripts/fetch-liu-map-index.scm from calps source tree. +*/ + +window.salar = new Promise((resolve, reject) => + fetch('/static/user/salar.json') + .then(d => d.json()) + .then(d => resolve(d))) + + +window.formatters.set('location', async function(el, d) { + let rx = /Lokal: (.*)/ + let m = rx.exec(d) + if (! m) { + el.textContent = d; + return; + } + + let salar = await window.salar; + + let name = m[1] + let frag = salar[name]; + if (frag) { + let anch = document.createElement('a'); + anch.href = `https://old.liu.se/karta/${frag}` + anch.target = '_blank' + anch.textContent = name; + el.append('Lokal: '); + el.append(anch); + } else { + el.textContent = `Lokal: ${name}` + } +}) |