@@ -39,30 +39,6 @@ const STYLESHEETS_MAPPING: Record<ShwStylesheets, string[]> = {
3939 ] ,
4040} ;
4141
42- const updatePageStylesheets = ( currentStylesheet : ShwStylesheets ) => {
43- // we need a fallback in case the `currentStylesheet` is not found in the `STYLESHEETS_MAPPING` list
44- // note: this may happen if the underlying code/names has changed but the `currentStylesheet` is read from local storage
45- const styleSheetToActivate : ShwStylesheets = STYLESHEETS_MAPPING [
46- currentStylesheet
47- ]
48- ? currentStylesheet
49- : 'standard' ;
50-
51- // toggle the stylesheets `disabled` attribute depending on the current choice
52- ALL_STYLESHEETS_IDS . forEach ( ( id ) => {
53- const stylesheetElement = document . getElementById ( id ) ;
54- const activate = STYLESHEETS_MAPPING [ styleSheetToActivate ] . includes ( id ) ;
55- if ( stylesheetElement ) {
56- if ( activate ) {
57- // note: `setAttribute('disabled', 'false')` does not work
58- stylesheetElement . removeAttribute ( 'disabled' ) ;
59- } else {
60- stylesheetElement . setAttribute ( 'disabled' , 'true' ) ;
61- }
62- }
63- } ) ;
64- } ;
65-
6642const LOCALSTORAGE_CURRENT_STYLESHEET = 'shw-theming-current-stylesheet' ;
6743
6844export default class ShwThemingService extends HdsThemingService {
@@ -95,18 +71,42 @@ export default class ShwThemingService extends HdsThemingService {
9571 // );
9672 // };
9773
98- setStylesheet ( stylesheet : ShwStylesheets ) {
74+ _updatePageStylesheets = ( currentStylesheet : ShwStylesheets ) => {
75+ // we need a fallback in case the `currentStylesheet` is not found in the `STYLESHEETS_MAPPING` list
76+ // note: this may happen if the underlying code/names has changed but the `currentStylesheet` is read from local storage
77+ const styleSheetToActivate : ShwStylesheets = STYLESHEETS_MAPPING [
78+ currentStylesheet
79+ ]
80+ ? currentStylesheet
81+ : 'standard' ;
82+
83+ // toggle the stylesheets `disabled` attribute depending on the current choice
84+ ALL_STYLESHEETS_IDS . forEach ( ( id ) => {
85+ const stylesheetElement = document . getElementById ( id ) ;
86+ const activate = STYLESHEETS_MAPPING [ styleSheetToActivate ] . includes ( id ) ;
87+ if ( stylesheetElement ) {
88+ if ( activate ) {
89+ // note: `setAttribute('disabled', 'false')` does not work
90+ stylesheetElement . removeAttribute ( 'disabled' ) ;
91+ } else {
92+ stylesheetElement . setAttribute ( 'disabled' , 'true' ) ;
93+ }
94+ }
95+ } ) ;
96+ } ;
97+
98+ setStylesheet = ( stylesheet : ShwStylesheets ) => {
9999 if ( stylesheet !== this . _currentStylesheet ) {
100100 this . _currentStylesheet = stylesheet ;
101- updatePageStylesheets ( this . _currentStylesheet ) ;
101+ this . _updatePageStylesheets ( this . _currentStylesheet ) ;
102102 }
103103
104104 // store the current stylesheet in local storage
105105 localStorage . setItem (
106106 LOCALSTORAGE_CURRENT_STYLESHEET ,
107107 this . _currentStylesheet ,
108108 ) ;
109- }
109+ } ;
110110
111111 get currentStylesheet ( ) : ShwStylesheets {
112112 return this . _currentStylesheet ;
0 commit comments