mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-23 15:57:57 +00:00
theme: remove JS errors if no variant is defined #158
This commit is contained in:
parent
a3ca106822
commit
44b138a6b7
1 changed files with 9 additions and 2 deletions
|
@ -21,21 +21,28 @@
|
||||||
changeTheme( theme );
|
changeTheme( theme );
|
||||||
function getTheme(){
|
function getTheme(){
|
||||||
var link = document.querySelector( '#variant-style' );
|
var link = document.querySelector( '#variant-style' );
|
||||||
|
if( !link ){
|
||||||
|
return;
|
||||||
|
}
|
||||||
var path = link.getAttribute( 'href' );
|
var path = link.getAttribute( 'href' );
|
||||||
var theme = path.match(/^.*\/theme-(.*?)\.css.*$/)[ 1 ];
|
var theme = path.match(/^.*\/theme-(.*?)\.css.*$/)[ 1 ];
|
||||||
return theme;
|
return theme;
|
||||||
}
|
}
|
||||||
function markTheme( theme ){
|
function markTheme( theme ){
|
||||||
var select = document.querySelector( '#select-theme' );
|
var select = document.querySelector( '#select-theme' );
|
||||||
if( select ){
|
if( !select ){
|
||||||
select.value = theme;
|
return;
|
||||||
}
|
}
|
||||||
|
select.value = theme;
|
||||||
}
|
}
|
||||||
function changeTheme( theme, noanimation ){
|
function changeTheme( theme, noanimation ){
|
||||||
if( !theme ){
|
if( !theme ){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var link = document.querySelector( '#variant-style' );
|
var link = document.querySelector( '#variant-style' );
|
||||||
|
if( !link ){
|
||||||
|
return;
|
||||||
|
}
|
||||||
var old_path = link.getAttribute( 'href' );
|
var old_path = link.getAttribute( 'href' );
|
||||||
var new_path = old_path.replace( /^(.*\/theme-).*?(\.css.*)$/, '$1' + theme + '$2' );
|
var new_path = old_path.replace( /^(.*\/theme-).*?(\.css.*)$/, '$1' + theme + '$2' );
|
||||||
if( old_path != new_path ){
|
if( old_path != new_path ){
|
||||||
|
|
Loading…
Reference in a new issue