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 @@
837 // swap, because the swap restores it as a changed field. Each panel is set up once; after that its837 // swap, because the swap restores it as a changed field. Each panel is set up once; after that its
838 // shown panel follows its tab radios. Called on every page change (see `enhance`).838 // shown panel follows its tab radios. Called on every page change (see `enhance`).
839 function enhanceColours() {839 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+ });
840 document.querySelectorAll('[data-colour-group]').forEach(function (group) {847 document.querySelectorAll('[data-colour-group]').forEach(function (group) {
841 var tabs = group.querySelectorAll('input[data-colour-tab]');848 var tabs = group.querySelectorAll('input[data-colour-tab]');
842 if (!group.__colourTab) {849 if (!group.__colourTab) {
@@ -850,6 +857,8 @@
850 if (on) { group.setAttribute('data-tab', on.value); }857 if (on) { group.setAttribute('data-tab', on.value); }
851 });858 });
852 }859 }
860+ // The authoring script below runs this from its own `enhance`, so it is shared the way `__forgeQuery` is.
861+ window.__forgeColours = enhanceColours;
853 862
854 // A filtered view asked for in place: the URL is replaced (no history entry per change), fields863 // A filtered view asked for in place: the URL is replaced (no history entry per change), fields
855 // and caret come through the swap, and the scroll stays put.864 // and caret come through the swap, and the scroll stays put.
@@ -1994,7 +2003,7 @@
1994 // ---- toolbar and upload ----2003 // ---- toolbar and upload ----
1995 2004
1996 function enhance() {2005 function enhance() {
1997- enhanceColours();2006+ if (window.__forgeColours) { window.__forgeColours(); }
1998 document.querySelectorAll('textarea').forEach(function (ta) {2007 document.querySelectorAll('textarea').forEach(function (ta) {
1999 if (ta.__md || !eligible(ta)) { return; }2008 if (ta.__md || !eligible(ta)) { return; }
2000 ta.__md = true;2009 ta.__md = true;