From 44b138a6b730ca8c5a2cc5bb3ddbf9a5677eef8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Sun, 13 Feb 2022 09:32:52 +0100 Subject: [PATCH] theme: remove JS errors if no variant is defined #158 --- layouts/partials/stylesheet.html | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/layouts/partials/stylesheet.html b/layouts/partials/stylesheet.html index fd35d6d49e..28125cc4b8 100644 --- a/layouts/partials/stylesheet.html +++ b/layouts/partials/stylesheet.html @@ -21,21 +21,28 @@ changeTheme( theme ); function getTheme(){ var link = document.querySelector( '#variant-style' ); + if( !link ){ + return; + } var path = link.getAttribute( 'href' ); var theme = path.match(/^.*\/theme-(.*?)\.css.*$/)[ 1 ]; return theme; } function markTheme( theme ){ var select = document.querySelector( '#select-theme' ); - if( select ){ - select.value = theme; + if( !select ){ + return; } + select.value = theme; } function changeTheme( theme, noanimation ){ if( !theme ){ return; } var link = document.querySelector( '#variant-style' ); + if( !link ){ + return; + } var old_path = link.getAttribute( 'href' ); var new_path = old_path.replace( /^(.*\/theme-).*?(\.css.*)$/, '$1' + theme + '$2' ); if( old_path != new_path ){