lazy sessions, restore if visible, forward user after restore
This commit is contained in:
parent
9df149fe8f
commit
d29cf1ee4d
@ -1,16 +1,53 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block script %}
|
||||
setTimeout(function() {
|
||||
/* drop first focus event, to avoid problems
|
||||
(allow to go easily to newer history entries) */
|
||||
window.onfocus = function() {
|
||||
window.onfocus = null;
|
||||
window.history.back();
|
||||
};
|
||||
}, 1000);
|
||||
const STATE_BACK = "back";
|
||||
const STATE_FORWARD = "forward";
|
||||
|
||||
function switch_state(new_state) {
|
||||
history.replaceState(
|
||||
new_state,
|
||||
document.title,
|
||||
location.pathname+location.hash);
|
||||
}
|
||||
|
||||
function go_back() {
|
||||
switch_state(STATE_FORWARD);
|
||||
history.back();
|
||||
}
|
||||
function go_forward() {
|
||||
switch_state(STATE_BACK);
|
||||
history.forward();
|
||||
}
|
||||
|
||||
// there are three states
|
||||
// default: register focus listener,
|
||||
// on focus: go back and switch to the state forward
|
||||
// back: user came from a later history entry
|
||||
// -> switch to the state forward,
|
||||
// forward him to the previous history entry
|
||||
// forward: user came from a previous history entry
|
||||
// -> switch to the state back,
|
||||
// forward him to the next history entry
|
||||
switch (history.state) {
|
||||
case STATE_BACK:
|
||||
go_back();
|
||||
break;
|
||||
case STATE_FORWARD:
|
||||
go_forward();
|
||||
break;
|
||||
default:
|
||||
if (!document.hidden) {
|
||||
go_back();
|
||||
break;
|
||||
}
|
||||
|
||||
document.addEventListener("visibilitychange", go_back);
|
||||
break;
|
||||
}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<noscript><p>Javascript isn't enabled. So you need to manually go back in history to restore this tab.</p></noscript>
|
||||
<p>If you see this site something went wrong or you reached the end of the history or you disabled javascript.</p>
|
||||
{% endblock %}
|
||||
|
Loading…
Reference in New Issue
Block a user