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" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block script %}
|
{% block script %}
|
||||||
setTimeout(function() {
|
const STATE_BACK = "back";
|
||||||
/* drop first focus event, to avoid problems
|
const STATE_FORWARD = "forward";
|
||||||
(allow to go easily to newer history entries) */
|
|
||||||
window.onfocus = function() {
|
function switch_state(new_state) {
|
||||||
window.onfocus = null;
|
history.replaceState(
|
||||||
window.history.back();
|
new_state,
|
||||||
};
|
document.title,
|
||||||
}, 1000);
|
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 %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<noscript><p>Javascript isn't enabled. So you need to manually go back in history to restore this tab.</p></noscript>
|
<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 %}
|
{% endblock %}
|
||||||
|
Loading…
Reference in New Issue
Block a user