The colour panel script loads on every page, and the custom swatch shows the stored hue
Browse files at this commit3d0c5e6e28af03d8f9654c97c7d16b5c84b79b96Parent: 3f07a50- fix
- the colour panel script loads on every page, and the custom swatch shows the stored hue
1 changed file +10 -1
crates/forge-web/assets/nav.jsmodified+10 -1
| @@ -837,6 +837,13 @@ | ||
| 837 | 837 | // swap, because the swap restores it as a changed field. Each panel is set up once; after that its |
| 838 | 838 | // shown panel follows its tab radios. Called on every page change (see `enhance`). |
| 839 | 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 | 847 | document.querySelectorAll('[data-colour-group]').forEach(function (group) { |
| 841 | 848 | var tabs = group.querySelectorAll('input[data-colour-tab]'); |
| 842 | 849 | if (!group.__colourTab) { |
| @@ -850,6 +857,8 @@ | ||
| 850 | 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 | 863 | // A filtered view asked for in place: the URL is replaced (no history entry per change), fields |
| 855 | 864 | // and caret come through the swap, and the scroll stays put. |
| @@ -1994,7 +2003,7 @@ | ||
| 1994 | 2003 | // ---- toolbar and upload ---- |
| 1995 | 2004 | |
| 1996 | 2005 | function enhance() { |
| 1997 | - enhanceColours(); | |
| 2006 | + if (window.__forgeColours) { window.__forgeColours(); } | |
| 1998 | 2007 | document.querySelectorAll('textarea').forEach(function (ta) { |
| 1999 | 2008 | if (ta.__md || !eligible(ta)) { return; } |
| 2000 | 2009 | ta.__md = true; |