history: don't reload page when history gets cleared #299

This commit is contained in:
Sören Weber 2022-07-03 15:40:32 +02:00
parent 3e83d03bce
commit 96aa7af4fb
No known key found for this signature in database
GPG key ID: 07D17FF580AE7589
3 changed files with 36 additions and 25 deletions

View file

@ -102,7 +102,7 @@
</a>
<script>variants.markSelectedVariant();</script>
</li>
<li class="footerVisitedLinks{{if $showvisitedlinks}} showVisitedLinks{{end}}"><a class="padding" href="#" data-clear-history-toggle=""><i class="fas fa-history fa-fw"></i> {{ T "Clear-History" }}</a></li>
<li class="footerVisitedLinks{{if $showvisitedlinks}} showVisitedLinks{{end}}"><a class="padding" onclick="clearHistory();"><i class="fas fa-history fa-fw"></i> {{ T "Clear-History" }}</a></li>
</ul>
</div>
<div id="footer" class="footerFooter{{if $showfooter}} showFooter{{end}}">

View file

@ -1379,6 +1379,10 @@ rapi-doc {
display: initial;
}
.footerVisitedLinks a {
cursor: pointer;
}
@media screen and (max-width: 47.938em) {
#breadcrumbs .links {
display: none;

View file

@ -648,6 +648,36 @@ function initSwipeHandler(){
document.querySelectorAll( '#sidebar *' ).forEach( function(e){ e.addEventListener("touchend", handleEndX); }, false);
}
function clearHistory() {
var visitedItem = baseUriFull + 'visited-url/'
for( var item in sessionStorage ){
if( item.substring( 0, visitedItem.length ) === visitedItem ){
sessionStorage.removeItem( item );
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( /^\/+\//, '/' );
jQuery('[data-nav-id="' + url + '"]').removeClass('visited');
}
}
}
function initHistory() {
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 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( /^\/+\//, '/' );
jQuery('[data-nav-id="' + url + '"]').addClass('visited');
}
}
}
function scrollToActiveMenu() {
window.setTimeout(function(){
var e = document.querySelector( '#sidebar ul.topics li.active a' );
@ -732,16 +762,7 @@ jQuery(function() {
initCodeClipboard();
restoreTabSelections();
initSwipeHandler();
jQuery('[data-clear-history-toggle]').on('click', function() {
for( var item in sessionStorage ){
if( item.substring( 0, baseUriFull.length ) === baseUriFull ){
sessionStorage.removeItem( item );
}
}
location.reload();
return false;
});
initHistory();
var ajax;
jQuery('[data-search-input]').on('input', function() {
@ -798,20 +819,6 @@ jQuery(function() {
$('#topbar a:not(:has(img)):not(.btn)').addClass('highlight');
$('#body-inner a:not(:has(img)):not(.btn):not(a[rel="footnote"])').addClass('highlight');
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 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( /^\/+\//, '/' );
jQuery('[data-nav-id="' + url + '"]').addClass('visited');
}
}
});
jQuery.extend({