mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2025-06-24 17:50:31 +00:00
theme: fix JS errors on hugo --minifiy #724
This commit is contained in:
parent
682e6b6119
commit
fcb255caf7
3 changed files with 41 additions and 38 deletions
static/js
|
@ -1,3 +1,5 @@
|
|||
window.relearn = window.relearn || {};
|
||||
|
||||
// we need to load this script in the html head to avoid flickering
|
||||
// on page load if the user has selected a non default variant
|
||||
|
||||
|
@ -40,7 +42,7 @@ var variants = {
|
|||
|
||||
init: function( variants ){
|
||||
this.variants = variants;
|
||||
var variant = window.localStorage.getItem( baseUriFull+'variant' ) || ( this.variants.length ? this.variants[0] : '' );
|
||||
var variant = window.localStorage.getItem( window.relearn.baseUriFull+'variant' ) || ( this.variants.length ? this.variants[0] : '' );
|
||||
this.changeVariant( variant );
|
||||
document.addEventListener( 'readystatechange', function(){
|
||||
if( document.readyState == 'interactive' ){
|
||||
|
@ -55,7 +57,7 @@ var variants = {
|
|||
|
||||
setVariant: function( variant ){
|
||||
this.variant = variant;
|
||||
window.localStorage.setItem( baseUriFull+'variant', variant );
|
||||
window.localStorage.setItem( window.relearn.baseUriFull+'variant', variant );
|
||||
},
|
||||
|
||||
isVariantLoaded: function(){
|
||||
|
@ -92,11 +94,11 @@ var variants = {
|
|||
},
|
||||
|
||||
addCustomVariantOption: function(){
|
||||
var variantbase = window.localStorage.getItem( baseUriFull+'customvariantbase' );
|
||||
var variantbase = window.localStorage.getItem( window.relearn.baseUriFull+'customvariantbase' );
|
||||
if( this.variants.indexOf( variantbase ) < 0 ){
|
||||
variantbase = '';
|
||||
}
|
||||
if( !window.localStorage.getItem( baseUriFull+'customvariant' ) ){
|
||||
if( !window.localStorage.getItem( window.relearn.baseUriFull+'customvariant' ) ){
|
||||
variantbase = '';
|
||||
}
|
||||
if( !variantbase ){
|
||||
|
@ -133,15 +135,15 @@ var variants = {
|
|||
|
||||
saveCustomVariant: function(){
|
||||
if( this.getVariant() != this.customvariantname ){
|
||||
window.localStorage.setItem( baseUriFull+'customvariantbase', this.getVariant() );
|
||||
window.localStorage.setItem( window.relearn.baseUriFull+'customvariantbase', this.getVariant() );
|
||||
}
|
||||
window.localStorage.setItem( baseUriFull+'customvariant', this.generateStylesheet() );
|
||||
window.localStorage.setItem( window.relearn.baseUriFull+'customvariant', this.generateStylesheet() );
|
||||
this.setVariant( this.customvariantname );
|
||||
this.markSelectedVariant();
|
||||
},
|
||||
|
||||
loadCustomVariant: function(){
|
||||
var stylesheet = window.localStorage.getItem( baseUriFull+'customvariant' );
|
||||
var stylesheet = window.localStorage.getItem( window.relearn.baseUriFull+'customvariant' );
|
||||
|
||||
// temp styles to document
|
||||
var head = document.querySelector( 'head' );
|
||||
|
@ -167,10 +169,10 @@ var variants = {
|
|||
},
|
||||
|
||||
resetVariant: function(){
|
||||
var variantbase = window.localStorage.getItem( baseUriFull+'customvariantbase' );
|
||||
var variantbase = window.localStorage.getItem( window.relearn.baseUriFull+'customvariantbase' );
|
||||
if( variantbase && confirm( 'You have made changes to your custom variant. Are you sure you want to reset all changes?' ) ){
|
||||
window.localStorage.removeItem( baseUriFull+'customvariantbase' );
|
||||
window.localStorage.removeItem( baseUriFull+'customvariant' );
|
||||
window.localStorage.removeItem( window.relearn.baseUriFull+'customvariantbase' );
|
||||
window.localStorage.removeItem( window.relearn.baseUriFull+'customvariant' );
|
||||
this.removeCustomVariantOption();
|
||||
if( this.getVariant() == this.customvariantname ){
|
||||
this.changeVariant( variantbase );
|
||||
|
@ -202,11 +204,11 @@ var variants = {
|
|||
|
||||
changeVariant: function( variant ){
|
||||
if( variant == this.customvariantname ){
|
||||
var variantbase = window.localStorage.getItem( baseUriFull+'customvariantbase' );
|
||||
var variantbase = window.localStorage.getItem( window.relearn.baseUriFull+'customvariantbase' );
|
||||
if( this.variants.indexOf( variantbase ) < 0 ){
|
||||
variant = '';
|
||||
}
|
||||
if( !window.localStorage.getItem( baseUriFull+'customvariant' ) ){
|
||||
if( !window.localStorage.getItem( window.relearn.baseUriFull+'customvariant' ) ){
|
||||
variant = '';
|
||||
}
|
||||
this.setVariant( variant );
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue