File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ // Prevent page jump when clicking theme toggle
2+ document . addEventListener ( 'DOMContentLoaded' , function ( ) {
3+ // Find all palette toggle buttons
4+ const paletteToggles = document . querySelectorAll ( '.md-header__button[for^="__palette_"]' ) ;
5+
6+ paletteToggles . forEach ( function ( toggle ) {
7+ toggle . addEventListener ( 'click' , function ( e ) {
8+ // Prevent the default anchor link behavior that causes page jump
9+ e . preventDefault ( ) ;
10+
11+ // Get the input element that the label is for
12+ const targetId = toggle . getAttribute ( 'for' ) ;
13+ const input = document . getElementById ( targetId ) ;
14+
15+ if ( input ) {
16+ // Toggle the input manually
17+ input . checked = true ;
18+ // Trigger change event so Material theme switcher works
19+ input . dispatchEvent ( new Event ( 'change' , { bubbles : true } ) ) ;
20+ }
21+ } ) ;
22+ } ) ;
23+ } ) ;
24+
Original file line number Diff line number Diff line change @@ -72,6 +72,10 @@ markdown_extensions:
7272extra_css :
7373 - stylesheets/extra.css
7474
75+ # Extra JavaScript
76+ extra_javascript :
77+ - javascripts/extra.js
78+
7579# Extra configuration
7680extra :
7781 social :
You can’t perform that action at this time.
0 commit comments