[theme] rename baseUriFull to absBaseUri #813

This commit is contained in:
Sören Weber 2024-03-18 21:58:26 +01:00
parent 5f40e57d17
commit 94ce982039
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
3 changed files with 28 additions and 28 deletions

View file

@ -30,8 +30,8 @@
<script src="{{"js/variant.js" | relURL}}{{ if not .Site.Params.disableAssetsBusting }}?{{ now.Unix }}{{ end }}"></script>
<script>
window.relearn = window.relearn || {};
window.relearn.baseUriFull='{{ replaceRE "/*$" "" .Site.BaseURL | safeJS }}';
window.relearn.relBasePath='{{ partial "relBasePath.hugo" $page | safeJS }}';
window.relearn.absBaseUri='{{ replaceRE "/*$" "" .Site.BaseURL | safeJS }}';
{{- 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 }}
window.index_json_url={{ "index.json" | relLangURL }};

View file

@ -127,21 +127,21 @@ function switchTab(tabGroup, tabId) {
// Store the selection to make it persistent
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){
var tabSelections = JSON.parse(selectionsJSON);
}else{
var tabSelections = {};
}
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() {
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){
var tabSelections = JSON.parse(selectionsJSON);
}else{
@ -299,7 +299,7 @@ function initMermaid( update, attrs ) {
var search;
if( update ){
search = sessionStorage.getItem( window.relearn.baseUriFull+'/search-value' );
search = sessionStorage.getItem( window.relearn.absBaseUri+'/search-value' );
unmark();
}
var is_initialized = ( update ? update_func( attrs ) : init_func( attrs ) );
@ -351,7 +351,7 @@ function initMermaid( update, attrs ) {
});
}
if( update && search && search.length ){
sessionStorage.setItem( window.relearn.baseUriFull+'/search-value', search );
sessionStorage.setItem( window.relearn.absBaseUri+'/search-value', search );
mark();
}
}
@ -1142,7 +1142,7 @@ function initExpand(){
}
function clearHistory() {
var visitedItem = window.relearn.baseUriFull + '/visited-url/'
var visitedItem = window.relearn.absBaseUri + '/visited-url/'
for( var item in sessionStorage ){
if( item.substring( 0, visitedItem.length ) === visitedItem ){
sessionStorage.removeItem( item );
@ -1158,7 +1158,7 @@ function clearHistory() {
}
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);
// loop through the sessionStorage and see if something should be marked as visited
@ -1225,7 +1225,7 @@ function scrollToPositions() {
return;
}
var search = sessionStorage.getItem( window.relearn.baseUriFull+'/search-value' );
var search = sessionStorage.getItem( window.relearn.absBaseUri+'/search-value' );
if( search && search.length ){
search = regexEscape( search );
var found = elementContains( search, elc );
@ -1271,7 +1271,7 @@ function mark() {
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' );
highlight( highlightableElements, value, { element: 'mark' } );
@ -1359,7 +1359,7 @@ function highlightNode( node, re, nodeName, className ){
};
function unmark() {
sessionStorage.removeItem( window.relearn.baseUriFull + '/search-value' );
sessionStorage.removeItem( window.relearn.absBaseUri + '/search-value' );
var markedElements = document.querySelectorAll( 'mark' );
for( var i = 0; i < markedElements.length; i++ ){
var parent = markedElements[i].parentNode;
@ -1425,7 +1425,7 @@ function elementContains( txt, e ){
function searchInputHandler( value ){
unmark();
if( value.length ){
sessionStorage.setItem( window.relearn.baseUriFull+'/search-value', value );
sessionStorage.setItem( window.relearn.absBaseUri+'/search-value', value );
mark();
}
}
@ -1437,7 +1437,7 @@ function initSearch() {
e.addEventListener( 'keydown', function( event ){
if( event.key == 'Escape' ){
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 ){
input.blur();
}
@ -1477,13 +1477,13 @@ function initSearch() {
var urlParams = new URLSearchParams( window.location.search );
var value = urlParams.get( 'search-by' );
if( value ){
sessionStorage.setItem( window.relearn.baseUriFull+'/search-value', value );
sessionStorage.setItem( window.relearn.absBaseUri+'/search-value', value );
}
mark();
// set initial search value for inputs on page load
if( sessionStorage.getItem( window.relearn.baseUriFull+'/search-value' ) ){
var search = sessionStorage.getItem( window.relearn.baseUriFull+'/search-value' );
if( sessionStorage.getItem( window.relearn.absBaseUri+'/search-value' ) ){
var search = sessionStorage.getItem( window.relearn.absBaseUri+'/search-value' );
inputs.forEach( function( e ){
e.value = search;
var event = document.createEvent( 'Event' );

View file

@ -42,7 +42,7 @@ var variants = {
init: function( 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 );
document.addEventListener( 'readystatechange', function(){
if( document.readyState == 'interactive' ){
@ -57,7 +57,7 @@ var variants = {
setVariant: function( variant ){
this.variant = variant;
window.localStorage.setItem( window.relearn.baseUriFull+'/variant', variant );
window.localStorage.setItem( window.relearn.absBaseUri+'/variant', variant );
},
isVariantLoaded: function(){
@ -95,11 +95,11 @@ var variants = {
},
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 ){
variantbase = '';
}
if( !window.localStorage.getItem( window.relearn.baseUriFull+'/customvariant' ) ){
if( !window.localStorage.getItem( window.relearn.absBaseUri+'/customvariant' ) ){
variantbase = '';
}
if( !variantbase ){
@ -136,15 +136,15 @@ var variants = {
saveCustomVariant: function(){
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.markSelectedVariant();
},
loadCustomVariant: function(){
var stylesheet = window.localStorage.getItem( window.relearn.baseUriFull+'/customvariant' );
var stylesheet = window.localStorage.getItem( window.relearn.absBaseUri+'/customvariant' );
// temp styles to document
var head = document.querySelector( 'head' );
@ -170,10 +170,10 @@ var variants = {
},
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?' ) ){
window.localStorage.removeItem( window.relearn.baseUriFull+'/customvariantbase' );
window.localStorage.removeItem( window.relearn.baseUriFull+'/customvariant' );
window.localStorage.removeItem( window.relearn.absBaseUri+'/customvariantbase' );
window.localStorage.removeItem( window.relearn.absBaseUri+'/customvariant' );
this.removeCustomVariantOption();
if( this.getVariant() == this.customvariantname ){
this.changeVariant( variantbase );
@ -205,11 +205,11 @@ var variants = {
changeVariant: function( variant ){
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 ){
variant = '';
}
if( !window.localStorage.getItem( window.relearn.baseUriFull+'/customvariant' ) ){
if( !window.localStorage.getItem( window.relearn.absBaseUri+'/customvariant' ) ){
variant = '';
}
this.setVariant( variant );