-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplain.js
More file actions
executable file
·85 lines (78 loc) · 2.57 KB
/
plain.js
File metadata and controls
executable file
·85 lines (78 loc) · 2.57 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
let ready = (callback) => {
if (document.readyState != "loading") callback()
else document.addEventListener("DOMContentLoaded", callback)
}
ready(() => {
var baseUrl = "./galleryimages";
// loading and listing files
function getFiles() {
var xhr = new XMLHttpRequest();
xhr.open("GET", baseUrl, true);
xhr.responseType = 'document';
xhr.onload = () => {
if (xhr.status === 200) {
var elements = xhr.response.getElementsByTagName("a");
for (x of elements) {
let imagebox;
// Matches all .webp files
if (x.href.match(/\.(jpg)$/)) {
imagebox = document.createElement("div");
imagebox.className = "imagebox";
let img = document.createElement("img");
img.src = x.href;
imagebox.appendChild(img);
document.getElementById("viewer").appendChild(imagebox);
}
// add classes from array
let datatypes = ["landscape", "flower", "pet", "cat", "dog"]
for (var i of datatypes) {
if (x.href.indexOf(i) > -1) {
imagebox.classList.toggle(i, true)
console.log(imagebox.classList);
}
}
// navbar sorting
document.querySelectorAll('.list').forEach(list => {
list.addEventListener('click', e => {
const value = e.target.dataset.filter;
document.querySelectorAll('.imagebox').forEach(imagebox => {
if (value == 'All') {
imagebox.style.display = 'block'
} else {
imagebox.style.display = imagebox.classList.contains(value) ? 'block' : 'none';
}
});
// add/remove active class on selected item
e.target.classList.add('active');
Array.from(e.target.parentNode.children).forEach(sibling => {
if (sibling != e.target) {
sibling.classList.remove('active');
}
});
});
});
// image viewer script
const imageboxes = document.querySelectorAll(".imagebox");
const imageView = document.querySelector(".imageView");
const imageViewImage = document.querySelector(".imageViewImage").querySelector("img");
const imageViewClose = document.querySelector(".imageViewClose");
function closeBtnFunction() {
imageViewClose.addEventListener("click", () => {
imageView.classList.remove("imageView-visible");
});
}
for (let x of imageboxes)
x.addEventListener("click", () => {
imageView.classList.add("imageView-visible");
imageViewImage.src = x.childNodes[0].src;
closeBtnFunction();
});
}
} else {
alert('Request failed. Returned status of ' + xhr.status);
}
}
xhr.send();
}
getFiles();
});