This repository was archived by the owner on Feb 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodal.js
110 lines (100 loc) · 3.73 KB
/
modal.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Get the modal
if (window.self !== window.top) {
var modal = window.parent.document.getElementById("myModal");
var modalDesc = window.parent.document.getElementById("modalDesc");
var scrollContainer = window.parent.document.getElementsByClassName("img-scroll-container")[0];
} else {
var modal = document.getElementById("myModal");
var modalDesc = document.getElementById("modalDesc");
var scrollContainer = document.getElementsByClassName("img-scroll-container")[0];
};
var img_code = ""
// Get the image and insert it inside the modal - use its "alt" text as a caption
if (window.self !== window.top) {
var modalImg = window.parent.document.getElementById("img01");
var captionText = window.parent.document.getElementById("caption");
} else {
var modalImg = document.getElementById("img01");
var captionText = document.getElementById("caption");
};
function img_click(e) {
var evt = e ? e : window.event;
if (evt.stopPropagation) {evt.stopPropagation();}
else {evt.cancelBubble=true;}
}
function open_image(filename) {
modal.style.top = parent.window.scrollY;
modal.style.display = "block";
if (filename.includes("/scenarios") || filename.includes("/all_")) {
scrollContainer.style["padding-top"] = "50px";
scrollContainer.style["padding-bottom"] = "100px";
scrollContainer.style["height"] = "calc(100vh - 150px)";
} else {
scrollContainer.style["padding-top"] = "0";
scrollContainer.style["padding-bottom"] = "0";
scrollContainer.style["height"] = "100vh";
}
if (filename.includes("/summary/")) {
var innerStr = "";
innerStr += "<p>The logarithmic growth rate can be thought of as the percentage increase or decrease per day.</p>";
// modalDesc.innerHTML = innerStr;
}
if (filename.includes("/scenarios/")) {
// modalDesc.innerHTML = "b";
}
modalImg.src = "baseline_hourglass_full_white_48dp.png";
modalImg.src = filename;
}
function switch_forecast(e) {
modal.style.src.display = "block";
if (modalImg.src.includes("/summary")) {
open_image(modalImg.src.replace("/summary", "/scenarios"));
}
var evt = e ? e : window.event;
if (evt.stopPropagation) {evt.stopPropagation();}
else {evt.cancelBubble=true;}
}
function switch_summary(e) {
modal.style.display = "block";
if (modalImg.src.includes("/scenarios")) {
open_image(modalImg.src.replace("/scenarios", "/summary"));
}
var evt = e ? e : window.event;
if (evt.stopPropagation) {evt.stopPropagation();}
else {evt.cancelBubble=true;}
}
// Get the <span> element that closes the modal
if (window.self !== window.top) {
var span = window.parent.document.getElementsByClassName("modal_close")[0];
var span2 = window.parent.document.getElementsByClassName("modal_summary")[0];
var span3 = window.parent.document.getElementsByClassName("modal_forecast")[0];
} else {
var span = document.getElementsByClassName("modal_close")[0];
var span2 = document.getElementsByClassName("modal_summary")[0];
var span3 = document.getElementsByClassName("modal_forecast")[0];
};
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
span2.onclick = switch_summary;
span3.onclick = switch_forecast;
modalImg.onclick = img_click;
modal.onclick = function() {
modal.style.display = "none";
}
if (window.self !== window.top) {
window.parent.document.onkeydown = function(evt) {
evt = evt || window.event;
if (evt.keyCode == 27) {
modal.style.display = "none";
}
};
} else {
document.onkeydown = function(evt) {
evt = evt || window.event;
if (evt.keyCode == 27) {
modal.style.display = "none";
}
};
}