Preserve last URL hash in /app to make going back easier
This commit is contained in:
parent
2ae794a92f
commit
06008f5a8f
|
@ -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 &&
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -204,7 +204,7 @@ app.pages.meet = {
|
|||
},
|
||||
},
|
||||
exit: function() {
|
||||
window.location.href = '#';
|
||||
hashredir(window.prevHash);
|
||||
app.overlay.hideAll();
|
||||
},
|
||||
carousel: {
|
||||
|
|
Loading…
Reference in New Issue