Skip to content

Commit

Permalink
Add attNameWPDarkModePluginInstalled
Browse files Browse the repository at this point in the history
  • Loading branch information
medied committed Mar 26, 2024
1 parent 5fe9aaa commit 2a02a98
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/link/colorScheme.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
const attNameWPDarkModePlugin = 'data-wp-dark-mode-active';
const attNameWPDarkModePluginActive = 'data-wp-dark-mode-active';
const attNameWPDarkModePluginInstalled = 'data-wp-dark-mode-preset';

const isWPDarkModePluginActive = () => {
return document.documentElement.hasAttribute( attNameWPDarkModePlugin );
return document.documentElement.hasAttribute( attNameWPDarkModePluginActive );
};

const isWPDarkModePluginInstalled = () => {
return document.documentElement.hasAttribute( attNameWPDarkModePluginInstalled );
};

export const getColorScheme = () => {
if ( isWPDarkModePluginActive() ) {
if ( isWPDarkModePluginInstalled() && isWPDarkModePluginActive() ) {
return 'dark';
} else if ( isWPDarkModePluginInstalled() && ! isWPDarkModePluginActive() ) {
return 'light';
}
return 'detect';
};
Expand All @@ -20,5 +27,5 @@ export const observeDarkModePluginActivation = ( callback ) => {
callback( 'light' );
}
} );
observer.observe( document.documentElement, { attributeFilter: [ attNameWPDarkModePlugin ] } );
observer.observe( document.documentElement, { attributeFilter: [ attNameWPDarkModePluginActive ] } );
};

0 comments on commit 2a02a98

Please sign in to comment.