theme: IE11 compat for theme switch #178

This commit is contained in:
Sören Weber 2022-02-15 01:37:48 +01:00
parent 4f28e6af83
commit 99a7061a67
No known key found for this signature in database
GPG key ID: 07D17FF580AE7589

View file

@ -27,8 +27,8 @@
{{- end }} {{- end }}
</style> </style>
<script> <script>
// we need to define this script in the head to avoid flickering an {{ "// we need to define this script in the head to avoid flickering" | safeJS }}
// page load if the user has selected a non default variant {{ "// on page load if the user has selected a non default variant" | safeJS }}
var theme = window.localStorage.getItem( 'theme' ); var theme = window.localStorage.getItem( 'theme' );
changeTheme( theme ); changeTheme( theme );
function getTheme(){ function getTheme(){
@ -53,7 +53,7 @@
{{- $quotedthemevariants = $quotedthemevariants | append (printf "\"%s\"" .) }} {{- $quotedthemevariants = $quotedthemevariants | append (printf "\"%s\"" .) }}
{{- end }} {{- end }}
var themes = [ {{ delimit $quotedthemevariants ", " | safeJS }} ]; var themes = [ {{ delimit $quotedthemevariants ", " | safeJS }} ];
if( !themes.find( function(e){ return e==theme; } ) ){ if( themes.indexOf( theme ) < 0 ){
theme = themes.length ? themes[ 0 ] : null; theme = themes.length ? themes[ 0 ] : null;
} }
if( !theme ){ if( !theme ){
@ -69,9 +69,9 @@
window.localStorage.setItem( 'theme', theme ); window.localStorage.setItem( 'theme', theme );
link.setAttribute( 'href', new_path ); link.setAttribute( 'href', new_path );
markTheme( theme ); markTheme( theme );
// remove selection, because if some uses an arrow navigation {{ "// remove selection, because if some uses an arrow navigation" | safeJS }}
// by pressing the left or right cursor key, we will automatically {{ "// by pressing the left or right cursor key, we will automatically" | safeJS }}
// select a different style {{ "// select a different style" | safeJS }}
if( document.activeElement ){ if( document.activeElement ){
document.activeElement.blur(); document.activeElement.blur();
} }