mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-23 07:47:54 +00:00
[theme] rename baseUriFull to absBaseUri #813
This commit is contained in:
parent
5f40e57d17
commit
94ce982039
3 changed files with 28 additions and 28 deletions
|
@ -30,8 +30,8 @@
|
||||||
<script src="{{"js/variant.js" | relURL}}{{ if not .Site.Params.disableAssetsBusting }}?{{ now.Unix }}{{ end }}"></script>
|
<script src="{{"js/variant.js" | relURL}}{{ if not .Site.Params.disableAssetsBusting }}?{{ now.Unix }}{{ end }}"></script>
|
||||||
<script>
|
<script>
|
||||||
window.relearn = window.relearn || {};
|
window.relearn = window.relearn || {};
|
||||||
window.relearn.baseUriFull='{{ replaceRE "/*$" "" .Site.BaseURL | safeJS }}';
|
|
||||||
window.relearn.relBasePath='{{ partial "relBasePath.hugo" $page | safeJS }}';
|
window.relearn.relBasePath='{{ partial "relBasePath.hugo" $page | safeJS }}';
|
||||||
|
window.relearn.absBaseUri='{{ replaceRE "/*$" "" .Site.BaseURL | safeJS }}';
|
||||||
{{- with .Site.Home.OutputFormats.Get "json" }}
|
{{- with .Site.Home.OutputFormats.Get "json" }}
|
||||||
{{- warnf "%q: DEPRECATED usage of 'json' output format found, use 'search' instead; see https://mcshelby.github.io/hugo-theme-relearn/basics/customization#activate-search" $page.File.Filename }}
|
{{- warnf "%q: DEPRECATED usage of 'json' output format found, use 'search' instead; see https://mcshelby.github.io/hugo-theme-relearn/basics/customization#activate-search" $page.File.Filename }}
|
||||||
window.index_json_url={{ "index.json" | relLangURL }};
|
window.index_json_url={{ "index.json" | relLangURL }};
|
||||||
|
|
|
@ -127,21 +127,21 @@ function switchTab(tabGroup, tabId) {
|
||||||
|
|
||||||
// Store the selection to make it persistent
|
// Store the selection to make it persistent
|
||||||
if(window.localStorage){
|
if(window.localStorage){
|
||||||
var selectionsJSON = window.localStorage.getItem(window.relearn.baseUriFull+"/tab-selections");
|
var selectionsJSON = window.localStorage.getItem(window.relearn.absBaseUri+"/tab-selections");
|
||||||
if(selectionsJSON){
|
if(selectionsJSON){
|
||||||
var tabSelections = JSON.parse(selectionsJSON);
|
var tabSelections = JSON.parse(selectionsJSON);
|
||||||
}else{
|
}else{
|
||||||
var tabSelections = {};
|
var tabSelections = {};
|
||||||
}
|
}
|
||||||
tabSelections[tabGroup] = tabId;
|
tabSelections[tabGroup] = tabId;
|
||||||
window.localStorage.setItem(window.relearn.baseUriFull+"/tab-selections", JSON.stringify(tabSelections));
|
window.localStorage.setItem(window.relearn.absBaseUri+"/tab-selections", JSON.stringify(tabSelections));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function restoreTabSelections() {
|
function restoreTabSelections() {
|
||||||
if(window.localStorage){
|
if(window.localStorage){
|
||||||
var selectionsJSON = window.localStorage.getItem(window.relearn.baseUriFull+"/tab-selections");
|
var selectionsJSON = window.localStorage.getItem(window.relearn.absBaseUri+"/tab-selections");
|
||||||
if(selectionsJSON){
|
if(selectionsJSON){
|
||||||
var tabSelections = JSON.parse(selectionsJSON);
|
var tabSelections = JSON.parse(selectionsJSON);
|
||||||
}else{
|
}else{
|
||||||
|
@ -299,7 +299,7 @@ function initMermaid( update, attrs ) {
|
||||||
|
|
||||||
var search;
|
var search;
|
||||||
if( update ){
|
if( update ){
|
||||||
search = sessionStorage.getItem( window.relearn.baseUriFull+'/search-value' );
|
search = sessionStorage.getItem( window.relearn.absBaseUri+'/search-value' );
|
||||||
unmark();
|
unmark();
|
||||||
}
|
}
|
||||||
var is_initialized = ( update ? update_func( attrs ) : init_func( attrs ) );
|
var is_initialized = ( update ? update_func( attrs ) : init_func( attrs ) );
|
||||||
|
@ -351,7 +351,7 @@ function initMermaid( update, attrs ) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if( update && search && search.length ){
|
if( update && search && search.length ){
|
||||||
sessionStorage.setItem( window.relearn.baseUriFull+'/search-value', search );
|
sessionStorage.setItem( window.relearn.absBaseUri+'/search-value', search );
|
||||||
mark();
|
mark();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1142,7 +1142,7 @@ function initExpand(){
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearHistory() {
|
function clearHistory() {
|
||||||
var visitedItem = window.relearn.baseUriFull + '/visited-url/'
|
var visitedItem = window.relearn.absBaseUri + '/visited-url/'
|
||||||
for( var item in sessionStorage ){
|
for( var item in sessionStorage ){
|
||||||
if( item.substring( 0, visitedItem.length ) === visitedItem ){
|
if( item.substring( 0, visitedItem.length ) === visitedItem ){
|
||||||
sessionStorage.removeItem( item );
|
sessionStorage.removeItem( item );
|
||||||
|
@ -1158,7 +1158,7 @@ function clearHistory() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function initHistory() {
|
function initHistory() {
|
||||||
var visitedItem = window.relearn.baseUriFull + '/visited-url/'
|
var visitedItem = window.relearn.absBaseUri + '/visited-url/'
|
||||||
sessionStorage.setItem( visitedItem+document.querySelector( 'body' ).dataset.url, 1);
|
sessionStorage.setItem( visitedItem+document.querySelector( 'body' ).dataset.url, 1);
|
||||||
|
|
||||||
// loop through the sessionStorage and see if something should be marked as visited
|
// loop through the sessionStorage and see if something should be marked as visited
|
||||||
|
@ -1225,7 +1225,7 @@ function scrollToPositions() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var search = sessionStorage.getItem( window.relearn.baseUriFull+'/search-value' );
|
var search = sessionStorage.getItem( window.relearn.absBaseUri+'/search-value' );
|
||||||
if( search && search.length ){
|
if( search && search.length ){
|
||||||
search = regexEscape( search );
|
search = regexEscape( search );
|
||||||
var found = elementContains( search, elc );
|
var found = elementContains( search, elc );
|
||||||
|
@ -1271,7 +1271,7 @@ function mark() {
|
||||||
bodyInnerLinks[i].classList.add( 'highlight' );
|
bodyInnerLinks[i].classList.add( 'highlight' );
|
||||||
}
|
}
|
||||||
|
|
||||||
var value = sessionStorage.getItem( window.relearn.baseUriFull + '/search-value' );
|
var value = sessionStorage.getItem( window.relearn.absBaseUri + '/search-value' );
|
||||||
var highlightableElements = document.querySelectorAll( '.highlightable' );
|
var highlightableElements = document.querySelectorAll( '.highlightable' );
|
||||||
highlight( highlightableElements, value, { element: 'mark' } );
|
highlight( highlightableElements, value, { element: 'mark' } );
|
||||||
|
|
||||||
|
@ -1359,7 +1359,7 @@ function highlightNode( node, re, nodeName, className ){
|
||||||
};
|
};
|
||||||
|
|
||||||
function unmark() {
|
function unmark() {
|
||||||
sessionStorage.removeItem( window.relearn.baseUriFull + '/search-value' );
|
sessionStorage.removeItem( window.relearn.absBaseUri + '/search-value' );
|
||||||
var markedElements = document.querySelectorAll( 'mark' );
|
var markedElements = document.querySelectorAll( 'mark' );
|
||||||
for( var i = 0; i < markedElements.length; i++ ){
|
for( var i = 0; i < markedElements.length; i++ ){
|
||||||
var parent = markedElements[i].parentNode;
|
var parent = markedElements[i].parentNode;
|
||||||
|
@ -1425,7 +1425,7 @@ function elementContains( txt, e ){
|
||||||
function searchInputHandler( value ){
|
function searchInputHandler( value ){
|
||||||
unmark();
|
unmark();
|
||||||
if( value.length ){
|
if( value.length ){
|
||||||
sessionStorage.setItem( window.relearn.baseUriFull+'/search-value', value );
|
sessionStorage.setItem( window.relearn.absBaseUri+'/search-value', value );
|
||||||
mark();
|
mark();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1437,7 +1437,7 @@ function initSearch() {
|
||||||
e.addEventListener( 'keydown', function( event ){
|
e.addEventListener( 'keydown', function( event ){
|
||||||
if( event.key == 'Escape' ){
|
if( event.key == 'Escape' ){
|
||||||
var input = event.target;
|
var input = event.target;
|
||||||
var search = sessionStorage.getItem( window.relearn.baseUriFull+'/search-value' );
|
var search = sessionStorage.getItem( window.relearn.absBaseUri+'/search-value' );
|
||||||
if( !search || !search.length ){
|
if( !search || !search.length ){
|
||||||
input.blur();
|
input.blur();
|
||||||
}
|
}
|
||||||
|
@ -1477,13 +1477,13 @@ function initSearch() {
|
||||||
var urlParams = new URLSearchParams( window.location.search );
|
var urlParams = new URLSearchParams( window.location.search );
|
||||||
var value = urlParams.get( 'search-by' );
|
var value = urlParams.get( 'search-by' );
|
||||||
if( value ){
|
if( value ){
|
||||||
sessionStorage.setItem( window.relearn.baseUriFull+'/search-value', value );
|
sessionStorage.setItem( window.relearn.absBaseUri+'/search-value', value );
|
||||||
}
|
}
|
||||||
mark();
|
mark();
|
||||||
|
|
||||||
// set initial search value for inputs on page load
|
// set initial search value for inputs on page load
|
||||||
if( sessionStorage.getItem( window.relearn.baseUriFull+'/search-value' ) ){
|
if( sessionStorage.getItem( window.relearn.absBaseUri+'/search-value' ) ){
|
||||||
var search = sessionStorage.getItem( window.relearn.baseUriFull+'/search-value' );
|
var search = sessionStorage.getItem( window.relearn.absBaseUri+'/search-value' );
|
||||||
inputs.forEach( function( e ){
|
inputs.forEach( function( e ){
|
||||||
e.value = search;
|
e.value = search;
|
||||||
var event = document.createEvent( 'Event' );
|
var event = document.createEvent( 'Event' );
|
||||||
|
|
|
@ -42,7 +42,7 @@ var variants = {
|
||||||
|
|
||||||
init: function( variants ){
|
init: function( variants ){
|
||||||
this.variants = variants;
|
this.variants = variants;
|
||||||
var variant = window.localStorage.getItem( window.relearn.baseUriFull+'/variant' ) || ( this.variants.length ? this.variants[0] : '' );
|
var variant = window.localStorage.getItem( window.relearn.absBaseUri+'/variant' ) || ( this.variants.length ? this.variants[0] : '' );
|
||||||
this.changeVariant( variant );
|
this.changeVariant( variant );
|
||||||
document.addEventListener( 'readystatechange', function(){
|
document.addEventListener( 'readystatechange', function(){
|
||||||
if( document.readyState == 'interactive' ){
|
if( document.readyState == 'interactive' ){
|
||||||
|
@ -57,7 +57,7 @@ var variants = {
|
||||||
|
|
||||||
setVariant: function( variant ){
|
setVariant: function( variant ){
|
||||||
this.variant = variant;
|
this.variant = variant;
|
||||||
window.localStorage.setItem( window.relearn.baseUriFull+'/variant', variant );
|
window.localStorage.setItem( window.relearn.absBaseUri+'/variant', variant );
|
||||||
},
|
},
|
||||||
|
|
||||||
isVariantLoaded: function(){
|
isVariantLoaded: function(){
|
||||||
|
@ -95,11 +95,11 @@ var variants = {
|
||||||
},
|
},
|
||||||
|
|
||||||
addCustomVariantOption: function(){
|
addCustomVariantOption: function(){
|
||||||
var variantbase = window.localStorage.getItem( window.relearn.baseUriFull+'/customvariantbase' );
|
var variantbase = window.localStorage.getItem( window.relearn.absBaseUri+'/customvariantbase' );
|
||||||
if( this.variants.indexOf( variantbase ) < 0 ){
|
if( this.variants.indexOf( variantbase ) < 0 ){
|
||||||
variantbase = '';
|
variantbase = '';
|
||||||
}
|
}
|
||||||
if( !window.localStorage.getItem( window.relearn.baseUriFull+'/customvariant' ) ){
|
if( !window.localStorage.getItem( window.relearn.absBaseUri+'/customvariant' ) ){
|
||||||
variantbase = '';
|
variantbase = '';
|
||||||
}
|
}
|
||||||
if( !variantbase ){
|
if( !variantbase ){
|
||||||
|
@ -136,15 +136,15 @@ var variants = {
|
||||||
|
|
||||||
saveCustomVariant: function(){
|
saveCustomVariant: function(){
|
||||||
if( this.getVariant() != this.customvariantname ){
|
if( this.getVariant() != this.customvariantname ){
|
||||||
window.localStorage.setItem( window.relearn.baseUriFull+'/customvariantbase', this.getVariant() );
|
window.localStorage.setItem( window.relearn.absBaseUri+'/customvariantbase', this.getVariant() );
|
||||||
}
|
}
|
||||||
window.localStorage.setItem( window.relearn.baseUriFull+'/customvariant', this.generateStylesheet() );
|
window.localStorage.setItem( window.relearn.absBaseUri+'/customvariant', this.generateStylesheet() );
|
||||||
this.setVariant( this.customvariantname );
|
this.setVariant( this.customvariantname );
|
||||||
this.markSelectedVariant();
|
this.markSelectedVariant();
|
||||||
},
|
},
|
||||||
|
|
||||||
loadCustomVariant: function(){
|
loadCustomVariant: function(){
|
||||||
var stylesheet = window.localStorage.getItem( window.relearn.baseUriFull+'/customvariant' );
|
var stylesheet = window.localStorage.getItem( window.relearn.absBaseUri+'/customvariant' );
|
||||||
|
|
||||||
// temp styles to document
|
// temp styles to document
|
||||||
var head = document.querySelector( 'head' );
|
var head = document.querySelector( 'head' );
|
||||||
|
@ -170,10 +170,10 @@ var variants = {
|
||||||
},
|
},
|
||||||
|
|
||||||
resetVariant: function(){
|
resetVariant: function(){
|
||||||
var variantbase = window.localStorage.getItem( window.relearn.baseUriFull+'/customvariantbase' );
|
var variantbase = window.localStorage.getItem( window.relearn.absBaseUri+'/customvariantbase' );
|
||||||
if( variantbase && confirm( 'You have made changes to your custom variant. Are you sure you want to reset all changes?' ) ){
|
if( variantbase && confirm( 'You have made changes to your custom variant. Are you sure you want to reset all changes?' ) ){
|
||||||
window.localStorage.removeItem( window.relearn.baseUriFull+'/customvariantbase' );
|
window.localStorage.removeItem( window.relearn.absBaseUri+'/customvariantbase' );
|
||||||
window.localStorage.removeItem( window.relearn.baseUriFull+'/customvariant' );
|
window.localStorage.removeItem( window.relearn.absBaseUri+'/customvariant' );
|
||||||
this.removeCustomVariantOption();
|
this.removeCustomVariantOption();
|
||||||
if( this.getVariant() == this.customvariantname ){
|
if( this.getVariant() == this.customvariantname ){
|
||||||
this.changeVariant( variantbase );
|
this.changeVariant( variantbase );
|
||||||
|
@ -205,11 +205,11 @@ var variants = {
|
||||||
|
|
||||||
changeVariant: function( variant ){
|
changeVariant: function( variant ){
|
||||||
if( variant == this.customvariantname ){
|
if( variant == this.customvariantname ){
|
||||||
var variantbase = window.localStorage.getItem( window.relearn.baseUriFull+'/customvariantbase' );
|
var variantbase = window.localStorage.getItem( window.relearn.absBaseUri+'/customvariantbase' );
|
||||||
if( this.variants.indexOf( variantbase ) < 0 ){
|
if( this.variants.indexOf( variantbase ) < 0 ){
|
||||||
variant = '';
|
variant = '';
|
||||||
}
|
}
|
||||||
if( !window.localStorage.getItem( window.relearn.baseUriFull+'/customvariant' ) ){
|
if( !window.localStorage.getItem( window.relearn.absBaseUri+'/customvariant' ) ){
|
||||||
variant = '';
|
variant = '';
|
||||||
}
|
}
|
||||||
this.setVariant( variant );
|
this.setVariant( variant );
|
||||||
|
|
Loading…
Reference in a new issue