forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhistory_go.js
91 lines (75 loc) · 2.39 KB
/
history_go.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Adds event listeners and populates on-load-div.
window.onload = function() {
window.addEventListener('popstate', onPopstate);
window.addEventListener('hashchange', onHashChange);
updateOnLoadText('OnLoadText');
};
// Populates pop-state-received-div and state-object-div upon a popstate event.
var onPopstate = function(e) {
updatePopStateReceivedText(true);
var stateText = e.state ? e.state : '(NO STATE OBJECT)';
updateStateObjectText(stateText);
};
// Populates hash-change-received-div upon receiving of a hashchange event.
var onHashChange = function(e) {
updateHashChangeReceivedText(true);
}
var updateOnLoadText = function(text) {
document.getElementById('on-load-div').innerHTML = text;
}
var updateNoOpText = function(text) {
document.getElementById('no-op-div').innerHTML = text;
}
var updatePopStateReceivedText = function(received) {
var text = received ? 'PopStateReceived' : '';
document.getElementById('pop-state-received-div').innerHTML = text;
}
var updateStateObjectText = function(state) {
document.getElementById('state-object-div').innerHTML = state;
}
var updateHashChangeReceivedText = function(received) {
var text = received ? 'HashChangeReceived' : '';
document.getElementById('hash-change-received-div').innerHTML = text;
}
// Clears all div text an starts a timer that updates no-op-div with "NoOpText"
// after 1s. This allows tests to verify that no nagivations occur after a
// no-op JavaScript call.
var onButtonTapped = function() {
updateOnLoadText('');
updateNoOpText('');
updatePopStateReceivedText(false);
updateStateObjectText('');
updateHashChangeReceivedText(false);
setTimeout("updateNoOpText('NoOpText')", 1000);
}
var goNoParameter = function() {
onButtonTapped();
window.history.go();
}
var goZero = function() {
onButtonTapped();
window.history.go(0);
}
var goBack = function() {
onButtonTapped();
window.history.back();
}
var goForward = function() {
onButtonTapped();
window.history.forward();
}
var go2 = function() {
onButtonTapped();
window.history.go(2);
}
var goBack2 = function() {
onButtonTapped();
window.history.go(-2);
}
var pushStateWithHash = function() {
onButtonTapped();
window.history.pushState('STATE_OBJECT', 'Title', '#hash');
}