1/** 2 * Handle dark-mode toggle in the header. 3 * 4 * Loaded in a separate JS file, so we can prevent FOIT (flash of incorrect theme). 5 */ 6 7const prefersDarkScheme = window.matchMedia( '(prefers-color-scheme: dark)' ); 8const currentTheme = localStorage.getItem( 'dark-mode-theme' ); 9 10if ( ( ! currentTheme && prefersDarkScheme ) || 'dark' === currentTheme ) { 11 document.body.classList.add( 'dark-theme' ); 12} 13 14jQuery( function() { 15 const btn = document.querySelector( '[data-js="lipe/project/template-parts/header/social/dark-mode"]' ); 16 btn.addEventListener( 'click', function() { 17 document.body.classList.toggle( 'dark-theme' ); 18 let theme = 'light'; 19 if ( document.body.classList.contains( 'dark-theme' ) ) { 20 theme = 'dark'; 21 } 22 localStorage.setItem( 'dark-mode-theme', theme ); 23 } ); 24} );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.