diff --git a/static/js/theme.js b/static/js/theme.js index 7753ea9d51a..3aa4f4bac00 100644 --- a/static/js/theme.js +++ b/static/js/theme.js @@ -31,21 +31,21 @@ function switchTab(tabGroup, tabId) { // Store the selection to make it persistent if(window.localStorage){ - var selectionsJSON = window.localStorage.getItem("tabSelections"); + var selectionsJSON = window.localStorage.getItem(baseUriFull+"tab-selections"); if(selectionsJSON){ var tabSelections = JSON.parse(selectionsJSON); }else{ var tabSelections = {}; } tabSelections[tabGroup] = tabId; - window.localStorage.setItem("tabSelections", JSON.stringify(tabSelections)); + window.localStorage.setItem(baseUriFull+"tab-selections", JSON.stringify(tabSelections)); } } } function restoreTabSelections() { if(window.localStorage){ - var selectionsJSON = window.localStorage.getItem("tabSelections"); + var selectionsJSON = window.localStorage.getItem(baseUriFull+"tab-selections"); if(selectionsJSON){ var tabSelections = JSON.parse(selectionsJSON); }else{ @@ -439,7 +439,11 @@ jQuery(function() { initSwipeHandler(); jQuery('[data-clear-history-toggle]').on('click', function() { - sessionStorage.clear(); + for( var item in sessionStorage ){ + if( item.substring( 0, baseUriFull.length ) === baseUriFull ){ + sessionStorage.removeItem( item ); + } + } location.reload(); return false; }); @@ -453,13 +457,13 @@ jQuery(function() { if (!value.length) { $('ul.topics').removeClass('searched'); items.css('display', 'block'); - sessionStorage.removeItem('search-value'); + sessionStorage.removeItem(baseUriFull+'search-value'); $("mark").parents(".expand-marked").removeClass("expand-marked"); $(".highlightable").unhighlight({ element: 'mark' }) return; } - sessionStorage.setItem('search-value', value); + sessionStorage.setItem(baseUriFull+'search-value', value); $("mark").parents(".expand-marked").removeClass("expand-marked"); $(".highlightable").unhighlight({ element: 'mark' }).highlight(value, { element: 'mark' }); $("mark").parents(".expand").addClass("expand-marked"); @@ -468,7 +472,7 @@ jQuery(function() { jQuery('[data-search-clear]').on('click', function() { jQuery('[data-search-input]').val('').trigger('input'); - sessionStorage.removeItem('search-input'); + sessionStorage.removeItem(baseUriFull+'search-input'); $("mark").parents(".expand-marked").removeClass("expand-marked"); $(".highlightable").unhighlight({ element: 'mark' }) }); @@ -480,8 +484,8 @@ jQuery(function() { }; }); - if (sessionStorage.getItem('search-value')) { - var searchValue = sessionStorage.getItem('search-value') + if (sessionStorage.getItem(baseUriFull+'search-value')) { + var searchValue = sessionStorage.getItem(baseUriFull+'search-value') $('[data-search-input]').val(searchValue); $('[data-search-input]').trigger('input'); var searchedElem = $('#body-inner').find(':contains(' + searchValue + ')').get(0); @@ -494,17 +498,19 @@ jQuery(function() { } } - $(".highlightable").highlight(sessionStorage.getItem('search-value'), { element: 'mark' }); + $(".highlightable").highlight(sessionStorage.getItem(baseUriFull+'search-value'), { element: 'mark' }); $("mark").parents(".expand").addClass("expand-marked"); $('#topbar a:not(:has(img)):not(.btn)').addClass('highlight'); $('#body-inner a:not(:has(img)):not(.btn):not(a[rel="footnote"])').addClass('highlight'); - sessionStorage.setItem(jQuery('body').data('url'), 1); + var visitedItem = baseUriFull + 'visited-url/' + sessionStorage.setItem(visitedItem+jQuery('body').data('url'), 1); // loop through the sessionStorage and see if something should be marked as visited - for (var url in sessionStorage) { - if (sessionStorage.getItem(url) == 1){ + for( var item in sessionStorage ){ + if( item.substring( 0, visitedItem.length ) === visitedItem && sessionStorage.getItem( item ) == 1 ){ + var url = item.substring( visitedItem.length ); // in case we have `relativeURLs=true` we have to strip the // relative path to root url = url.replace( /\.\.\//g, '/' ).replace( /^\/+\//, '/' ); diff --git a/static/js/variant.js b/static/js/variant.js index 9cbfb1bf2c3..faca6546782 100644 --- a/static/js/variant.js +++ b/static/js/variant.js @@ -7,7 +7,7 @@ var variants = { init: function( variants ){ this.variants = variants; - var variant = window.localStorage.getItem( 'variant' ) || ( this.variants.length ? this.variants[0] : '' ); + var variant = window.localStorage.getItem( baseUriFull+'variant' ) || ( this.variants.length ? this.variants[0] : '' ); this.changeVariant( variant ); document.addEventListener( 'readystatechange', function(){ if( document.readyState == 'interactive' ){ @@ -22,7 +22,7 @@ var variants = { setVariant: function( variant ){ this.variant = variant; - window.localStorage.setItem( 'variant', variant ); + window.localStorage.setItem( baseUriFull+'variant', variant ); }, markSelectedVariant: function(){ @@ -49,11 +49,11 @@ var variants = { }, addCustomVariantOption: function(){ - var variantbase = window.localStorage.getItem( 'customvariantbase' ); + var variantbase = window.localStorage.getItem( baseUriFull+'customvariantbase' ); if( this.variants.indexOf( variantbase ) < 0 ){ variantbase = ''; } - if( !window.localStorage.getItem( 'customvariant' ) ){ + if( !window.localStorage.getItem( baseUriFull+'customvariant' ) ){ variantbase = ''; } if( !variantbase ){ @@ -90,15 +90,15 @@ var variants = { saveCustomVariant: function(){ if( this.getVariant() != this.customvariantname ){ - window.localStorage.setItem( 'customvariantbase', this.getVariant() ); + window.localStorage.setItem( baseUriFull+'customvariantbase', this.getVariant() ); } - window.localStorage.setItem( 'customvariant', this.generateStylesheet() ); + window.localStorage.setItem( baseUriFull+'customvariant', this.generateStylesheet() ); this.setVariant( this.customvariantname ); this.markSelectedVariant(); }, loadCustomVariant: function(){ - var stylesheet = window.localStorage.getItem( 'customvariant' ); + var stylesheet = window.localStorage.getItem( baseUriFull+'customvariant' ); // temp styles to document var head = document.querySelector( 'head' ); @@ -125,10 +125,10 @@ var variants = { }, resetVariant: function(){ - var variantbase = window.localStorage.getItem( 'customvariantbase' ); + var variantbase = window.localStorage.getItem( 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( 'customvariantbase' ); - window.localStorage.removeItem( 'customvariant' ); + window.localStorage.removeItem( baseUriFull+'customvariantbase' ); + window.localStorage.removeItem( baseUriFull+'customvariant' ); this.removeCustomVariantOption(); if( this.getVariant() == this.customvariantname ){ this.changeVariant( variantbase ); @@ -148,11 +148,11 @@ var variants = { changeVariant: function( variant ){ if( variant == this.customvariantname ){ - var variantbase = window.localStorage.getItem( 'customvariantbase' ); + var variantbase = window.localStorage.getItem( baseUriFull+'customvariantbase' ); if( this.variants.indexOf( variantbase ) < 0 ){ variant = ''; } - if( !window.localStorage.getItem( 'customvariant' ) ){ + if( !window.localStorage.getItem( baseUriFull+'customvariant' ) ){ variant = ''; } this.setVariant( variant );