-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
157 lines (124 loc) · 4.43 KB
/
index.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
import jobs from './data.json' assert { type: 'json' };
const content = document.querySelector('#content');
const filterDiv = document.createElement('div');
const filtered = [];
const filterName = [];
function display() {
content.innerHTML = "";
content.appendChild(filterDiv);
filterDiv.classList.add('filterDiv');
for (const item of jobs) {
const section = document.createElement('section');
content.appendChild(section);
const div = document.createElement('div');
section.appendChild(div);
section.classList.add('card');
const logo = document.createElement('img');
div.appendChild(logo);
logo.src = item.logo;
const div2 = document.createElement('div');
section.appendChild(div2);
div2.classList.add('info');
const feature = document.createElement('div');
div2.appendChild(feature);
feature.classList.add('feature');
const h6 = document.createElement('h1');
h6.textContent = item.company;
feature.appendChild(h6);
h6.classList.add('heading');
const span = document.createElement('span');
feature.appendChild(span);
if (item.new === true) {
const n = document.createElement('a');
n.textContent = "NEW!";
span.appendChild(n);
n.classList.add('new');
}
if (item.featured === true) {
const f = document.createElement('a');
f.textContent = "FEATURE!";
span.appendChild(f);
f.classList.add('black');
}
const h5 = document.createElement('h5');
h5.textContent = item.position;
div2.appendChild(h5);
h5.classList.add('position');
const description = document.createElement('div');
div2.appendChild(description);
description.classList.add('description');
const postA = document.createElement('p');
const contract = document.createElement('p');
const location = document.createElement('p');
description.appendChild(postA);
postA.textContent = item.postedAt;
description.appendChild(contract);
contract.textContent = item.contract;
description.appendChild(location);
location.textContent = item.location;
const keywords = document.createElement('div');
section.appendChild(keywords);
keywords.classList.add('keywards');
const role = document.createElement('a');
role.textContent = item.role;
keywords.appendChild(role);
role.addEventListener('click', () => {
if (!filterName.includes(role.textContent)) {
filtered.push(item);
filterName.push(item.role)
}
addFilter();
filterArr(item.role)
})
const level = document.createElement('a');
level.textContent = item.level;
keywords.appendChild(level);
level.addEventListener('click', () => {
if (!filterName.includes(level.textContent)) {
filtered.push(item);
filterName.push(level.textContent);
}
addFilter();
filterArr(item.level);
})
for (const language of item.languages) {
const lang = document.createElement('a');
lang.textContent = language;
keywords.appendChild(lang);
lang.addEventListener('click', () => {
if (!filterName.includes(language)) {
filtered.push(item);
filterName.push(language)
}
addFilter();
display(filtered);
filterArr(item.language);
})
}
}
}
display(jobs);
function addFilter() {
filterDiv.textContent = '';
for (const item of filterName) {
const p = document.createElement('a');
const span = document.createElement('span');
const i = document.createElement('i');
p.textContent = item;
filterDiv.appendChild(p);
filterDiv.appendChild(span);
span.appendChild(i);
p.classList.add('filterKeyword');
i.classList.add('fa-solid', 'fa-xmark', 'cross');
}
}
function filterArr(a) {
let arr =[];
for (const item of jobs) {
if (Object.values(item).includes(a)) {
arr.push(item);
}
}
console.log(arr);
display(arr)
}