-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
202 lines (175 loc) · 6.09 KB
/
script.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
//Creating the database
let statesData;
fetch("Data/states.json")
.then((response) => response.json())
.then((json) => (statesData = json));
// Function to find the country from a state
function findCountry(stateStr) {
//Converting to uppercase
stateStr = stateStr.toUpperCase();
// console.log(statesData.length)
// Testing if statesData has been imported properly
// console.log(`The length of array is : ${statesData.length}`)
// If exact match found, then return that or return the first from the list
//Searching for exact result
//iterating through all the countries
for (let i = 0; i < statesData.length; i++) {
let statesLst = statesData[i]["states"];
//Iterating through all the states
for (let j = 0; j < statesLst.length; j++) {
let state = statesLst[j]["name"].toUpperCase();
if (state == stateStr) {
return statesData[i]["name"].toUpperCase();
}
}
}
//Searching for the closest result alphabetically
//iterating through all the countries
for (let i = 0; i < statesData.length; i++) {
let statesLst = statesData[i]["states"];
//Iterating through all the states
for (let j = 0; j < statesLst.length; j++) {
let state = statesLst[j]["name"].toUpperCase();
if (state.indexOf(stateStr) >= 0) {
return statesData[i]["name"].toUpperCase();
}
}
}
}
// Function to add cards
function addCards(cardJSON, index) {
div = document.querySelector("#StartOfListing");
let template = `
<div class="card" onclick="applyBtnClicked(${index})">
<div class="position">${cardJSON["position"]}</div>
<!-- Apply Button -->
<div class="applyBtn">
<a href="" class="applyBtnText">Apply</a>
</div>
<!-- Job Info -->
<div class="jobInfo">
<div class="info">
<img src="Assets/company.PNG" alt="" class="locationImg" />
${cardJSON["company"]}
</div>
<div class="info">
<img src="Assets/red_blimp.jpeg" alt="" class="locationImg" />
${cardJSON["location"]}
</div>
<div class="info">
<img src="Assets/clock.jpg" alt="" class="locationImg" />
${cardJSON["nature"]}
</div>
</div>
<!-- **End of Job Info** -->
<!-- Job Description -->
<div class="jobDescription">
<div style = "font-size : 26px">Job Description</div>
${cardJSON["description"]}
<!--** End of Job Description **-->
`;
let reqTemplate = ` <div style = "font-size : 26px; margin-top : 2%">Job Requirements</div>
<ul class = "jobReq">`
for (let i = 0; i<cardJSON["requirements"].length; i++){
reqTemplate += `<li> ${cardJSON["requirements"][i]} </li>`
};
reqTemplate += '</ul>'
//Ending Job desctiption and card
template+= reqTemplate + '</div> </div>'
console.log(reqTemplate)
div.insertAdjacentHTML("beforeend", template);
}
//Using the database.json file to display the html of each card
fetch("Data/database.json")
.then(function (response) {
return response.json();
})
.then(function (array) {
for (let i = 0; i < array.length; i++) {
addCards(array[i], i);
}
})
.catch(function (error) {
console.error("Something went wrong");
});
// Function executed everytime a key is pressed
function searchFunction() {
let filter = document.getElementById("searchText").value.toUpperCase();
// console.log(filter);
// Getting an array of all the objects of class card
let allCards = document.getElementsByClassName("card");
let fCountry = findCountry(filter);
console.log(fCountry);
// iterating through all objects of class "card"
for (let i = 0; i < allCards.length; i++) {
//card is a changing variable that goes through each of the cards
let card = allCards[i];
// Getting an array of all elements with tag 'div' and then indexinf through them to find the required details
let position = card
.getElementsByTagName("div")[0]
.textContent.toUpperCase()
.trim();
let company = card
.getElementsByTagName("div")[3]
.textContent.toUpperCase()
.trim();
let location = card
.getElementsByTagName("div")[4]
.textContent.toUpperCase()
.trim();
let time = card
.getElementsByTagName("div")[5]
.textContent.toUpperCase()
.trim();
// console.log(position, company, location, time);
// console.log(`${position} : Index is ${position.indexOf(filter)}`)
// if index is not found then the function 'indexOf' returns -1
// Hence if it is found, then index of will return a value greater than or equal to 0
let toBeDisplayed;
//Position
if (position.indexOf(filter) >= 0) {
// console.log("Filtered Position:", position);
toBeDisplayed = true;
}
// Company
else if (company.indexOf(filter) >= 0) {
// console.log("Filtered Company:", company);
toBeDisplayed = true;
}
//Location
else if (location.indexOf(filter) >= 0 || location.indexOf(fCountry) >= 0) {
// console.log("Filtered Location:", location);
toBeDisplayed = true;
}
//Part Time or Full Time
else if (time.indexOf(filter) >= 0) {
// console.log("Filtered Nature of Job:", time);
toBeDisplayed = true;
} else {
toBeDisplayed = false;
}
if (toBeDisplayed && screen.width > 680) {
card.style.display = "grid";
} else if (toBeDisplayed && screen.width < 680) {
card.style.display = "flex";
} else {
card.style.display = "none";
}
}
}
function applyBtnClicked(index) {
let allDesc = document.getElementsByClassName("jobDescription");
if (allDesc[index].style.display == "flex") {
allDesc[index].style.display = "none";
} else {
allDesc[index].style.display = "flex";
}
for (let i = 0; i < allDesc.length; i++) {
if (i != index) {
allDesc[i].style.display = "none";
}
}
document.getElementById("StartOfListing").style.display = "flex";
document.getElementById("StartOfListing").style.flexDirection = "column";
document.getElementsByClassName("card").style.marginTop = "25px";
}