diff --git a/layouts/partials/stylesheet.html b/layouts/partials/stylesheet.html
index dd9e6b5306..9c87abd35e 100644
--- a/layouts/partials/stylesheet.html
+++ b/layouts/partials/stylesheet.html
@@ -42,21 +42,22 @@
{{- end }}
var root_url="/";
var baseUri=root_url.replace(/\/$/, '');
- {{ "// translations" | safeJS }}
- window.T_Copy_to_clipboard = '{{ T "Copy-to-clipboard" | safeJS }}';
- window.T_Copied_to_clipboard = '{{ T "Copied-to-clipboard" | safeJS }}';
- window.T_Copy_link_to_clipboard = '{{ T "Copy-link-to-clipboard" | safeJS }}';
- window.T_Link_copied_to_clipboard = '{{ T "Link-copied-to-clipboard" | safeJS }}';
- window.T_Reset_view = '{{ T "Reset-view" | safeJS }}';
- window.T_View_reset = '{{ T "View-reset" | safeJS }}';
- window.T_No_results_found = '{{ T "No-results-found" | safeJS }}';
- window.T_N_results_found = '{{ T "N-results-found" | safeJS }}';
- {{ "// some further base stuff" | safeJS }}
- var baseUriFull='{{ trim .Site.BaseURL "/" | safeJS }}/';
+ window.relearn = window.relearn || {};
+ window.relearn.baseUriFull='{{ trim .Site.BaseURL "/" | safeJS }}/';
+ {{ "// variant stuff" | safeJS }}
{{- $quotedthemevariants := slice }}
{{- range $themevariants }}
{{- $quotedthemevariants = $quotedthemevariants | append (printf "'%s'" .) }}
{{- end }}
window.variants && variants.init( [ {{ delimit $quotedthemevariants ", " | safeJS }} ] );
+ {{ "// translations" | safeJS }}
+ {{ printf "window.T_Copy_to_clipboard = `%s`;" (T `Copy-to-clipboard`) | safeJS }}
+ {{ printf "window.T_Copied_to_clipboard = `%s`;" (T `Copied-to-clipboard`) | safeJS }}
+ {{ printf "window.T_Copy_link_to_clipboard = `%s`;" (T `Copy-link-to-clipboard`) | safeJS }}
+ {{ printf "window.T_Link_copied_to_clipboard = `%s`;" (T `Link-copied-to-clipboard`) | safeJS }}
+ {{ printf "window.T_Reset_view = `%s`;" (T `Reset-view`) | safeJS }}
+ {{ printf "window.T_View_reset = `%s`;" (T `View-reset`) | safeJS }}
+ {{ printf "window.T_No_results_found = `%s`;" (T "No-results-found") | safeJS }}
+ {{ printf "window.T_N_results_found = `%s`;" (T "N-results-found") | safeJS }}
{{- end }}
\ No newline at end of file
diff --git a/static/js/theme.js b/static/js/theme.js
index 84740437b9..7e1b0623a0 100644
--- a/static/js/theme.js
+++ b/static/js/theme.js
@@ -127,21 +127,21 @@ function switchTab(tabGroup, tabId) {
// Store the selection to make it persistent
if(window.localStorage){
- var selectionsJSON = window.localStorage.getItem(baseUriFull+"tab-selections");
+ var selectionsJSON = window.localStorage.getItem(window.relearn.baseUriFull+"tab-selections");
if(selectionsJSON){
var tabSelections = JSON.parse(selectionsJSON);
}else{
var tabSelections = {};
}
tabSelections[tabGroup] = tabId;
- window.localStorage.setItem(baseUriFull+"tab-selections", JSON.stringify(tabSelections));
+ window.localStorage.setItem(window.relearn.baseUriFull+"tab-selections", JSON.stringify(tabSelections));
}
}
}
function restoreTabSelections() {
if(window.localStorage){
- var selectionsJSON = window.localStorage.getItem(baseUriFull+"tab-selections");
+ var selectionsJSON = window.localStorage.getItem(window.relearn.baseUriFull+"tab-selections");
if(selectionsJSON){
var tabSelections = JSON.parse(selectionsJSON);
}else{
@@ -304,7 +304,7 @@ function initMermaid( update, attrs ) {
var search;
if( update ){
- search = sessionStorage.getItem( baseUriFull+'search-value' );
+ search = sessionStorage.getItem( window.relearn.baseUriFull+'search-value' );
unmark();
}
var is_initialized = ( update ? update_func( attrs ) : init_func( attrs ) );
@@ -352,7 +352,7 @@ function initMermaid( update, attrs ) {
});
}
if( update && search && search.length ){
- sessionStorage.setItem( baseUriFull+'search-value', search );
+ sessionStorage.setItem( window.relearn.baseUriFull+'search-value', search );
mark();
}
}
@@ -1121,7 +1121,7 @@ function initExpand(){
}
function clearHistory() {
- var visitedItem = baseUriFull + 'visited-url/'
+ var visitedItem = window.relearn.baseUriFull + 'visited-url/'
for( var item in sessionStorage ){
if( item.substring( 0, visitedItem.length ) === visitedItem ){
sessionStorage.removeItem( item );
@@ -1137,7 +1137,7 @@ function clearHistory() {
}
function initHistory() {
- var visitedItem = baseUriFull + 'visited-url/'
+ var visitedItem = window.relearn.baseUriFull + 'visited-url/'
sessionStorage.setItem( visitedItem+document.querySelector( 'body' ).dataset.url, 1);
// loop through the sessionStorage and see if something should be marked as visited
@@ -1192,7 +1192,7 @@ function scrollToPositions() {
return;
}
- var search = sessionStorage.getItem( baseUriFull+'search-value' );
+ var search = sessionStorage.getItem( window.relearn.baseUriFull+'search-value' );
if( search && search.length ){
search = regexEscape( search );
var found = elementContains( search, elc );
@@ -1229,7 +1229,7 @@ function mark() {
bodyInnerLinks[i].classList.add( 'highlight' );
}
- var value = sessionStorage.getItem( baseUriFull + 'search-value' );
+ var value = sessionStorage.getItem( window.relearn.baseUriFull + 'search-value' );
var highlightableElements = document.querySelectorAll( '.highlightable' );
highlight( highlightableElements, value, { element: 'mark' } );
@@ -1317,7 +1317,7 @@ function highlightNode( node, re, nodeName, className ){
};
function unmark() {
- sessionStorage.removeItem( baseUriFull + 'search-value' );
+ sessionStorage.removeItem( window.relearn.baseUriFull + 'search-value' );
var markedElements = document.querySelectorAll( 'mark' );
for( var i = 0; i < markedElements.length; i++ ){
var parent = markedElements[i].parentNode;
@@ -1383,7 +1383,7 @@ function elementContains( txt, e ){
function searchInputHandler( value ){
unmark();
if( value.length ){
- sessionStorage.setItem( baseUriFull+'search-value', value );
+ sessionStorage.setItem( window.relearn.baseUriFull+'search-value', value );
mark();
}
}
@@ -1395,7 +1395,7 @@ function initSearch() {
e.addEventListener( 'keydown', function( event ){
if( event.key == 'Escape' ){
var input = event.target;
- var search = sessionStorage.getItem( baseUriFull+'search-value' );
+ var search = sessionStorage.getItem( window.relearn.baseUriFull+'search-value' );
if( !search || !search.length ){
input.blur();
}
@@ -1435,13 +1435,13 @@ function initSearch() {
var urlParams = new URLSearchParams( window.location.search );
var value = urlParams.get( 'search-by' );
if( value ){
- sessionStorage.setItem( baseUriFull+'search-value', value );
+ sessionStorage.setItem( window.relearn.baseUriFull+'search-value', value );
}
mark();
// set initial search value for inputs on page load
- if( sessionStorage.getItem( baseUriFull+'search-value' ) ){
- var search = sessionStorage.getItem( baseUriFull+'search-value' );
+ if( sessionStorage.getItem( window.relearn.baseUriFull+'search-value' ) ){
+ var search = sessionStorage.getItem( window.relearn.baseUriFull+'search-value' );
inputs.forEach( function( e ){
e.value = search;
var event = document.createEvent( 'Event' );
diff --git a/static/js/variant.js b/static/js/variant.js
index 15d75f1509..33a274b921 100644
--- a/static/js/variant.js
+++ b/static/js/variant.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 );