aboutsummaryrefslogtreecommitdiff
path: root/assets
diff options
context:
space:
mode:
authorJoris2022-09-04 11:31:07 +0200
committerJoris2022-09-04 11:31:07 +0200
commit7c5a31a162eb6664eff665e0cfadc089188a5e8f (patch)
tree6ba3a21da0cce8a3ae76e00ed0918f20c62403d2 /assets
parentd8e39e49d32502a39c1097e2a4ee9354f321220a (diff)
Remove inline styling for category colors
Also stop changing color of select options, because it does not work reliably accross browsers.
Diffstat (limited to 'assets')
-rw-r--r--assets/main.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/assets/main.js b/assets/main.js
index bc5d65c..c83e4fc 100644
--- a/assets/main.js
+++ b/assets/main.js
@@ -272,3 +272,23 @@ function prettyPrintMonth(isoDate) {
function capitalize(str) {
return str.replace(/^\w/, function (c) { return c.toUpperCase() })
}
+
+/******************/
+/* Web components */
+/******************/
+
+/* Apply color given from attribute.
+ *
+ * This permits not to use the style attribute in HTML to respect a strict CSP policy.
+ */
+customElements.define(
+ 'colored-category',
+ class extends HTMLSpanElement {
+ constructor() {
+ super()
+ const span = this
+ span.style = `color: ${span.getAttribute('data-color')}`
+ }
+ },
+ { extends: 'span' }
+)