-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathloadingControlFlow.js
74 lines (68 loc) · 2.49 KB
/
loadingControlFlow.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
//Handle sites that append garbage to the url.
if (!/^https?:\/\/(?:localhost:8080|rulesguru\.org)\/\?(?:\d*(RG.+GG)?)$/.test(window.location.href)) {
const match = window.location.href.match(/^https?:\/\/(?:localhost:8080|rulesguru\.org)\/(\?(?:\d*(RG.+GG)?))/);
if (match === null) {
history.replaceState({}, "", ".");
} else {
history.replaceState({}, "", `./${match[1]}`);
}
}
//Check for searchLinks.
let goToSearchLink = false,
searchLink;
if (window.location.href.match("/\?(\d*)RG")) {
searchLink = window.location.href.slice(window.location.href.indexOf("RG") + 2, window.location.href.length - 2);
let numbermatch = window.location.href.match(/\?(\d)+/); // Case where there is a specific question and a searchlink
if (numbermatch === null) {
history.replaceState({}, "", ".");
} else {
history.replaceState({}, "", `./${numbermatch[0]}`);
}
goToSearchLink = true;
}
//Check for question id.
let goToQuestionNum = null;
if (window.location.href.match(/\?\d/)) {
goToQuestionNum = Number(window.location.href.match(/\/?(\d+)$/)[1]);
}
const maximallyPermissiveSidebarSettings = {
"level": ["0", "1", "2", "3", "Corner Case"],
"complexity": ["Simple", "Intermediate", "Complicated"],
"legality": "All of Magic",
"expansions": [],
"playableOnly": false,
"tags": [],
"tagsConjunc": "",
"rules": [],
"rulesConjunc": "",
"cards": [],
"cardsConjunc": ""
};
if (goToSearchLink) {
document.getElementById("startPage").style.display = "none";
} else if (typeof goToQuestionNum === "number") {
document.getElementById("FOUCOverlay").style.display = "none";
document.getElementById("startPage").style.display = "none";
goToQuestion(goToQuestionNum, function() {
toggleAnimation("stop");
}, maximallyPermissiveSidebarSettings);
} else {
toggleAnimation("stop");
document.getElementById("FOUCOverlay").style.display = "none";
}
//Add question numbers to the url and handle back/forward button presses.
window.addEventListener("popstate", function(event) {
if (window.location.href.includes("?") && !window.location.href.includes("?RG")) {
let questionNum = Number(window.location.href.match(/\/?(\d+)$/)[1]);
if (loadedQuestions.pastQuestions[questionNum]) {
loadedQuestions.currentQuestion = loadedQuestions.pastQuestions[questionNum];
displayCurrentQuestion();
} else {
document.getElementById("questionPage").style.transform = "scale(0)";
document.getElementById("startPage").style.transform = "scale(0)";
goToQuestion(questionNum);
}
} else {
returnToHome(false);
}
});