forge
Explore
Log in

Don't you dare go Hollow

The colour panel script loads on every page, and the custom swatch shows the stored hue

Browse files at this commit

3d0c5e6e28af03d8f9654c97c7d16b5c84b79b96Ahmet Kaan GümüşParent: 3f07a50
  • fix
    • the colour panel script loads on every page, and the custom swatch shows the stored hue
Show full message
🐛 fix: the colour panel script loads on every page, and the custom swatch shows the stored hue
crates/forge-web/assets/nav.jsmodified+10 -1
@@ -837,6 +837,13 @@
837837 // swap, because the swap restores it as a changed field. Each panel is set up once; after that its
838838 // shown panel follows its tab radios. Called on every page change (see `enhance`).
839839 function enhanceColours() {
840+ // The server renders each stripe's stored hue as the range value only, so the row's `--hue` (which
841+ // the Custom swatch reads) is set here from that value. Each row is set through the CSSOM because
842+ // the CSP forbids inline style attributes from the server.
843+ document.querySelectorAll('.hue-row').forEach(function (row) {
844+ var range = row.querySelector('input[data-hue-stripe]');
845+ if (range) { row.style.setProperty('--hue', range.value); }
846+ });
840847 document.querySelectorAll('[data-colour-group]').forEach(function (group) {
841848 var tabs = group.querySelectorAll('input[data-colour-tab]');
842849 if (!group.__colourTab) {
@@ -850,6 +857,8 @@
850857 if (on) { group.setAttribute('data-tab', on.value); }
851858 });
852859 }
860+ // The authoring script below runs this from its own `enhance`, so it is shared the way `__forgeQuery` is.
861+ window.__forgeColours = enhanceColours;
853862
854863 // A filtered view asked for in place: the URL is replaced (no history entry per change), fields
855864 // and caret come through the swap, and the scroll stays put.
@@ -1994,7 +2003,7 @@
19942003 // ---- toolbar and upload ----
19952004
19962005 function enhance() {
1997- enhanceColours();
2006+ if (window.__forgeColours) { window.__forgeColours(); }
19982007 document.querySelectorAll('textarea').forEach(function (ta) {
19992008 if (ta.__md || !eligible(ta)) { return; }
20002009 ta.__md = true;