-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathajaxHistory.js
38 lines (32 loc) · 906 Bytes
/
ajaxHistory.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
var ajaxStack = [];
var currentAjax = "";
var backed = false;
function history_update(ajaxCallString) {
console.log("Updating history with " + ajaxCallString);
if (currentAjax != "" && !backed) {
console.log("Pushing previous ajax.");
ajaxStack.push(currentAjax);
console.log(ajaxStack);
console.log("Done");
}
currentAjax = ajaxCallString;
console.log("Current ajax: " + currentAjax);
backed = false;
}
function history_back() {
console.log("Going back in the history.");
if (ajaxStack.length > 0) {
var ajaxToRestore = ajaxStack.pop();
backed = true;
if (ajaxStack.length == 0) {
currentAjax = "";
} else {
currentAjax = ajaxToRestore;
}
console.log("Calling popped function: " + ajaxToRestore);
var functionFromStr = new Function(ajaxToRestore);
functionFromStr();
} else {
console.log("Ajax history is empty.");
}
}