File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed
Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -89,9 +89,17 @@ $(document).ready(function() {
8989 var isDark = document . documentElement . getAttribute ( 'data-theme' ) === 'dark' ;
9090 $ ( "#theme-toggle i" ) . attr ( "class" , isDark ? "fas fa-sun" : "fas fa-moon" ) ;
9191 }
92- updateThemeIcon ( ) ;
9392
94- $ ( "#theme-toggle" ) . on ( "click" , function ( e ) {
93+ // Periodic check to update icon because navbar is loaded asynchronously
94+ var checkNavbar = setInterval ( function ( ) {
95+ if ( $ ( "#theme-toggle i" ) . length ) {
96+ updateThemeIcon ( ) ;
97+ clearInterval ( checkNavbar ) ;
98+ }
99+ } , 50 ) ;
100+
101+ // Event delegation to handle dynamically loaded navbar
102+ $ ( document ) . on ( "click" , "#theme-toggle" , function ( e ) {
95103 e . preventDefault ( ) ;
96104 var isDark = document . documentElement . getAttribute ( 'data-theme' ) !== 'dark' ;
97105 document . documentElement . setAttribute ( 'data-theme' , isDark ? 'dark' : 'light' ) ;
You can’t perform that action at this time.
0 commit comments