Skip to content

Commit

Permalink
[theme] rename baseUriFull to absBaseUri #813
Browse files Browse the repository at this point in the history
  • Loading branch information
McShelby committed Mar 18, 2024
1 parent 5f40e57 commit 94ce982
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion layouts/partials/stylesheet.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 }};
Expand Down
30 changes: 15 additions & 15 deletions static/js/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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 ) );
Expand Down Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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 );
Expand All @@ -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
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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' } );

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
Expand All @@ -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();
}
Expand Down Expand Up @@ -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' );
Expand Down
24 changes: 12 additions & 12 deletions static/js/variant.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' ){
Expand All @@ -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(){
Expand Down Expand Up @@ -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 ){
Expand Down Expand Up @@ -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' );
Expand All @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit 94ce982

Please sign in to comment.