mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-04 18:01:42 +01:00
e0669ddaae
For a full list of changes since [49330], see 5759e96...e7d5991
.
Props poena, luminuu, ryelle, kjellr, aristath, justinahinon, felipeelia, joostdevalk.
See #51526.
Built from https://develop.svn.wordpress.org/trunk@49478
git-svn-id: http://core.svn.wordpress.org/trunk@49237 1a063a9b-81f0-0310-95a4-ce76da25c4cd
43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
function toggleDarkMode() { // jshint ignore:line
|
|
var toggler = document.getElementById( 'dark-mode-toggler' ),
|
|
html = document.querySelector( 'html' );
|
|
|
|
if ( 'false' === toggler.getAttribute( 'aria-pressed' ) ) {
|
|
toggler.setAttribute( 'aria-pressed', 'true' );
|
|
html.classList.add( 'is-dark-mode' );
|
|
window.localStorage.setItem( 'twentytwentyoneDarkMode', 'yes' );
|
|
} else {
|
|
toggler.setAttribute( 'aria-pressed', 'false' );
|
|
html.classList.remove( 'is-dark-mode' );
|
|
window.localStorage.setItem( 'twentytwentyoneDarkMode', 'no' );
|
|
}
|
|
}
|
|
|
|
function darkModeInitialLoad() {
|
|
var toggler = document.getElementById( 'dark-mode-toggler' ),
|
|
isDarkMode = window.matchMedia( '(prefers-color-scheme: dark)' ).matches,
|
|
html;
|
|
|
|
if ( 'yes' === window.localStorage.getItem( 'twentytwentyoneDarkMode' ) ) {
|
|
isDarkMode = true;
|
|
} else if ( 'no' === window.localStorage.getItem( 'twentytwentyoneDarkMode' ) ) {
|
|
isDarkMode = false;
|
|
}
|
|
|
|
if ( ! toggler ) {
|
|
return;
|
|
}
|
|
if ( isDarkMode ) {
|
|
toggler.setAttribute( 'aria-pressed', 'true' );
|
|
}
|
|
|
|
html = document.querySelector( 'html' );
|
|
if ( isDarkMode ) {
|
|
html.classList.add( 'is-dark-mode' );
|
|
} else {
|
|
html.classList.remove( 'is-dark-mode' );
|
|
}
|
|
}
|
|
|
|
darkModeInitialLoad();
|