forked from J3ranch/J3ranch.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
advanced_search_overlay.js
85 lines (65 loc) · 2.42 KB
/
advanced_search_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
document.getElementsByClassName("cancel-button")[0].addEventListener("click", function(e) {
window.parent.postMessage({
'func': 0
}, "*");
})
document.getElementsByClassName("search-button")[0].addEventListener("click", function(e) {
console.log("hi");
window.parent.postMessage({
'func': 1,
'params': createSearchObject()
}, "*");
})
function createSearchObject() {
var searchObj = getSearchTerms();
if (document.getElementById("min-award").value !== "") {
searchObj.min_award = parseInt(document.getElementById("min-award").value);
}
if (document.getElementById("max-essay").value !== "") {
searchObj.max_essays = parseInt(document.getElementById("max-essay").value);
}
if (document.getElementById("grad-year").value !== "") {
searchObj.grad_year = parseInt(document.getElementById("grad-year").value);
}
if (document.getElementById("class-year").value !== "") {
searchObj.class_level = parseInt(document.getElementById("class-year").value);
}
if (document.getElementById("degree").value !== "") {
searchObj.degree = parseInt(document.getElementById("degree").value);
}
if (document.getElementById("gpa-max").value !== "") {
searchObj.max_gpa = parseFloat(document.getElementById("gpa-max").value);
}
console.log(document.getElementById("citizenship").value);
if (document.getElementsByName("citizenship")[0].checked) {
console.log("test");
searchObj.citizenship = true;
} else if (document.getElementsByName("citizenship")[1].checked) {
searchObj.citizenship = false;
}
if (document.getElementById("major").value !== "") {
searchObj.major = document.getElementById("major").value;
}
if (document.getElementById("ethnicity").value !== "") {
searchObj.ethnicity = document.getElementById("ethnicity").value;
}
return searchObj;
}
function getSearchTerms() {
var searchbar = document.getElementById("searchbar");
var search;
search = (searchbar.value.indexOf('"') != -1) ? searchbar.value.match(/"[^"]*"|\b[^"\s]*|/g) : searchbar.value.split(/[\s,]/);
search = search.filter(Boolean);
search.forEach(function(e, i) {if (/"[^"]*"/.test(e)) {search[i] = e.substring(1, e.length - 1);} });
console.log(search);
return {keywords: search};
}
function validateSearch(searchbar) {
var obj = {};
try {
eval("obj = " + searchbar);
} catch (error) {
return false;
}
return (obj.hasOwnProperty("keywords")) && Array.isArray(obj.keywords);
}