From 7c5a31a162eb6664eff665e0cfadc089188a5e8f Mon Sep 17 00:00:00 2001
From: Joris
Date: Sun, 4 Sep 2022 11:31:07 +0200
Subject: Remove inline styling for category colors
Also stop changing color of select options, because it does not work
reliably accross browsers.
---
assets/main.js | 20 ++++++++++++++++++++
templates/category/table.html | 3 ++-
templates/payment/create.html | 1 -
templates/payment/table.html | 10 ++++++----
templates/payment/table/search.html | 1 -
templates/payment/update.html | 1 -
6 files changed, 28 insertions(+), 8 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' }
+)
diff --git a/templates/category/table.html b/templates/category/table.html
index e05c84b..d4147aa 100644
--- a/templates/category/table.html
+++ b/templates/category/table.html
@@ -27,7 +27,8 @@
>
{{ category.name }}
diff --git a/templates/payment/create.html b/templates/payment/create.html
index 9af68b6..4ac73de 100644
--- a/templates/payment/create.html
+++ b/templates/payment/create.html
@@ -88,7 +88,6 @@
{% for category in categories %}