From c65f896a2a1747b509e414a1e06ddd0fdf6fb966 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Thu, 3 Feb 2022 09:34:33 -0500 Subject: [PATCH] Propagate upward accent color stylesheet only when it changes --- src/js/settings.js | 5 +++-- src/js/udom.js | 12 ++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/js/settings.js b/src/js/settings.js index a6b78802c..a73f6053c 100644 --- a/src/js/settings.js +++ b/src/js/settings.js @@ -212,13 +212,14 @@ const changeUserSettings = function(name, value) { // Maybe reflect some changes immediately switch ( name ) { case 'uiTheme': - uDom.setTheme(value, [ 'dark', 'light' ]); + uDom.setTheme(value, true); break; case 'uiAccentCustom': case 'uiAccentCustom0': uDom.setAccentColor( uDom.nodeFromSelector('[data-setting-name="uiAccentCustom"]').checked, - uDom.nodeFromSelector('[data-setting-name="uiAccentCustom0"]').value + uDom.nodeFromSelector('[data-setting-name="uiAccentCustom0"]').value, + true ); break; default: diff --git a/src/js/udom.js b/src/js/udom.js index cfb33ed48..4f6e8aafe 100644 --- a/src/js/udom.js +++ b/src/js/udom.js @@ -71,7 +71,7 @@ DOMListFactory.root = document.querySelector(':root'); /******************************************************************************/ -DOMListFactory.setTheme = function(theme) { +DOMListFactory.setTheme = function(theme, propagate = false) { if ( theme === 'auto' ) { if ( typeof self.matchMedia === 'function' ) { const mql = self.matchMedia('(prefers-color-scheme: dark)'); @@ -92,13 +92,19 @@ DOMListFactory.setTheme = function(theme) { rootcl.add('light'); rootcl.remove('dark'); } + if ( propagate === false ) { break; } if ( w === w.parent ) { break; } w = w.parent; try { void w.document; } catch(ex) { return; } } }; -DOMListFactory.setAccentColor = function(accentEnabled, accentColor, stylesheet = '') { +DOMListFactory.setAccentColor = function( + accentEnabled, + accentColor, + propagate, + stylesheet = '' +) { if ( accentEnabled && stylesheet === '' && self.hsluv !== undefined ) { const toRGB = hsl => self.hsluv.hsluvToRgb(hsl).map(a => Math.round(a * 255)).join(' '); // Normalize first @@ -145,6 +151,7 @@ DOMListFactory.setAccentColor = function(accentEnabled, accentColor, stylesheet } else { wdoc.documentElement.classList.remove('accented'); } + if ( propagate === false ) { break; } if ( w === w.parent ) { break; } w = w.parent; try { void w.document; } catch(ex) { break; } @@ -161,6 +168,7 @@ DOMListFactory.setAccentColor = function(accentEnabled, accentColor, stylesheet uDom.setAccentColor( true, response.uiAccentCustom0, + false, response.uiAccentStylesheet ); }