forked from J3ranch/J3ranch.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scholarship_overlay.js
144 lines (113 loc) · 4.28 KB
/
scholarship_overlay.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// Initialize Cloud Firestore through Firebase
var db = firebase.firestore();
// Disable deprecated features
db.settings({
timestampsInSnapshots: true
});
var closeModal = document.getElementById("close");
closeModal.onclick = function() {
window.parent.postMessage({
'func': 0
}, "*");
}
function getURLParameter(param) {
var url = window.location.search;
var paramString = url.substring(1);
var paramArray = paramString.split("&");
for (var i = 0; i < paramArray.length; i++) {
var keyPair = paramArray[i].split("=");
if (keyPair[0] == param) {
if (keyPair[1] != "null") {
return parseInt(keyPair[1]);
}
}
}
return -1;
}
function getData(sid) {
if (sid == -1) {
document.getElementById("loader").style.display = "none";
document.getElementById("no-data").style.display = "flex";
return;
}
db.collection("scholarships").where("sid","==", sid).limit(1)
.get()
.then(function(query) {
if(query.size == 0) {
document.getElementById("loader").style.display = "none";
document.getElementById("no-data").style.display = "flex";
}
query.forEach(function(doc) {
setDoc(doc);
});
})
.then(function() {
document.getElementById("loader").style.display = "none";
});
}
function setDoc(doc) {
var deadlineDate;
eval("deadlineDate = new Date('" + doc.data().deadline + "')");
var deadline = deadlineDate.toLocaleString("en-us", {
month: "long",
year: "numeric",
day: "numeric"
});
document.getElementById("scholarship-picture").setAttribute("src", doc.data().image);
document.getElementById("scholarship-name").innerHTML = doc.data().name;
document.getElementById("amount").innerHTML = "$" + doc.data().award.toLocaleString("en");
document.getElementById("scholarship-summary").innerHTML = doc.data().description;
document.getElementById("chance").innerHTML = doc.data().chance + "%";
document.getElementById("deadline").innerHTML = deadline;
document.getElementById("details").setAttribute("onclick", "window.open('" + doc.data().details_url + "', '_blank')")
document.getElementById("apply").setAttribute("onclick", "window.open('" + doc.data().apply_url + "', '_blank')")
addReqs(doc);
addTags(doc);
document.getElementById("details").removeAttribute("disabled");
document.getElementById("apply").removeAttribute("disabled");
document.getElementById("deadline").style.visibility = "visible";
}
function addReqs(doc) {
if (doc.data().requirements.essays > 0) {
var span = document.createElement("span");
span.setAttribute("class", "overlay-content");
span.innerHTML = doc.data().requirements.essays + ((doc.data().requirements.essays > 1) ? " Essays" : " Essay");
document.getElementById("scholarship-reqs").appendChild(span);
}
if (doc.data().requirements.interviews > 0) {
var span = document.createElement("span");
span.setAttribute("class", "overlay-content");
span.innerHTML = doc.data().requirements.interviews + ((doc.data().requirements.interviews > 1) ? " Interviews" : " Interview");
document.getElementById("scholarship-reqs").appendChild(span);
}
if (doc.data().requirements.major != "none") {
var span = document.createElement("span");
span.setAttribute("class", "overlay-content");
span.innerHTML = doc.data().requirements.major + " Majors";
document.getElementById("scholarship-reqs").appendChild(span);
}
if (doc.data().requirements.gpa !== undefined && parseFloat(doc.data().requirements.gpa) !== 0) {
var span = document.createElement("span");
span.setAttribute("class", "overlay-content");
span.innerHTML = doc.data().requirements.gpa + " GPA Min.";
document.getElementById("scholarship-reqs").appendChild(span);
}
}
function addTags(doc) {
doc.data().tags.forEach(function(element) {
var tag = document.createElement("div");
tag.setAttribute("class", "tag")
var tagHead = document.createElement("span");
tagHead.setAttribute("class", "tag-head");
var tagBody = document.createElement("span");
tagBody.setAttribute("class", "tag-body");
tagBody.innerHTML = element;
tag.appendChild(tagHead);
tag.appendChild(tagBody);
document.getElementById("scholarship-tags-container").appendChild(tag);
});
}
setTimeout(function() {
document.getElementById("long-load").style.visibility = "visible";
}, 10000);
getData(getURLParameter("sid"));