Preserve last URL hash in /app to make going back easier

This commit is contained in:
Niko 2022-02-23 10:34:52 +01:00
parent 2ae794a92f
commit 06008f5a8f
4 changed files with 17 additions and 4 deletions

View File

@ -418,12 +418,18 @@ window.onload = function(e) {
window.onhashchange();
}
var prevHash = null;
window.onhashchange = function(e) {
var path = window.location.hash.substring(1).trim();
try {
window.prevHash = new URL(e.oldURL)
.hash.substr(1).trim();
} catch (e) { window.prevHash = null }
var path = window.location.hash.substr(1).trim();
var args = path.split('/');
if (args.length > 0 && args[0].trim() === '')
args = [];
window.lastHash = path;
for (var i = 0; i < app.hashHandlers.length; i++) {
const cfg = app.hashHandlers[i];
if (cfg.exact !== undefined &&

View File

@ -142,6 +142,13 @@ function loadScript(id, file, cback) {
document.body.appendChild(script);
}
function hashredir(tohash, fallback) {
fallback = fallback || '';
if (tohash === undefined || tohash === null)
tohash = fallback;
window.location.href = `#${tohash}`;
}
function printstack() { console.error(new Error().stack) }
function uuidv4() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {

View File

@ -18,10 +18,10 @@ app.pages.home = {
setTimeout(function() {
document.getElementById('app-container').innerHTML = '';
if (app.template.isLoaded('quiz.index'))
window.location.href = `#quiz/${id}`
hashredir(`quiz/${id}`);
}, 80);
if (!app.template.isLoaded('quiz.index'))
window.location.href = `#quiz/${id}`;
hashredir(`quiz/${id}`);
},
paint: function(section, json) {
json = json || app.pages.home.data[section];

View File

@ -204,7 +204,7 @@ app.pages.meet = {
},
},
exit: function() {
window.location.href = '#';
hashredir(window.prevHash);
app.overlay.hideAll();
},
carousel: {