Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
108 lines (99 loc) · 2.66 KB
/
Copy pathscript.js
File metadata and controls
108 lines (99 loc) · 2.66 KB
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
const hex = [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"A",
"B",
"C",
"D",
"E",
"F",
];
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min) + min);
}
function hexGenerator() {
let hexNum = "#";
let randIdx = 0;
while (hexNum.length < 7) {
randIdx = getRandomInt(0, 16);
hexNum += hex[randIdx];
}
return hexNum;
}
const root = document.getElementById("root");
root.style.backgroundColor = hexGenerator();
/*---------------------------------------------------------------filter------------------------------------------------------------------------*/
const searchBarClick = () => {
const input = document.getElementById("searchbar-input");
const allItems = document.querySelectorAll(".item");
allItems.forEach((item) => {
item.classList.remove("hidden");
if (!item.innerHTML.toLowerCase().includes(input.value)) {
item.classList.add("hidden");
}
});
};
const filterBtnClick = (cls) => {
const allItems = document.querySelectorAll(`.item`);
if (cls === "all") {
allItems.forEach((item) => item.classList.remove("hidden"));
return;
}
allItems.forEach((item) => {
item.classList.add("hidden");
});
const selectedItems = document.querySelectorAll(`.${cls}`);
selectedItems.forEach((item) => {
item.classList.remove("hidden");
});
};
/*---------------------------------------------------------------modal------------------------------------------------------------------------*/
const modal = (idx) => {
const modal = document.getElementById("myModal");
const close = document.getElementsByClassName("close")[0];
const allItems = document.querySelectorAll(".item");
const section = document.getElementById("imgSection");
const left = document.getElementById("leftP");
const right = document.getElementById("rightP");
const urls = [];
section.innerHTML = "";
modal.style.display = "block";
allItems.forEach((item) => {
urls.push(item.firstElementChild.attributes.getNamedItem("src").value);
});
section.innerHTML += `<img src="${urls[idx]}" alt="image" />`;
left.onclick = () => {
idx--;
if (idx === -1) {
idx = 5;
}
section.innerHTML = "";
section.innerHTML = `<img src="${urls[idx]}" alt="image" />`;
};
right.onclick = () => {
idx++;
if (idx === 6) {
idx = 0;
}
section.innerHTML = "";
section.innerHTML = `<img src="${urls[idx]}" alt="image" />`;
};
close.onclick = () => {
modal.style.display = "none";
};
window.onclick = (event) => {
if (event.target === modal) {
modal.style.display = "none";
}
};
};