-
Notifications
You must be signed in to change notification settings - Fork 106
/
index.js
82 lines (66 loc) · 2.23 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
function darkMode() {
jQuery("body").addClass("night").removeClass("day");
jQuery("h1.gallery-head").addClass("night").removeClass("day");
jQuery("p.lead").addClass("night").removeClass("day");
document.documentElement.classList.add("dark");
}
function lightMode() {
jQuery("body").addClass("day").removeClass("night");
jQuery("h1.gallery-head").addClass("day").removeClass("night");
jQuery("p.lead").addClass("day").removeClass("night");
document.documentElement.classList.remove("dark");
}
$("#color-switch").on("change", function (e) {
if (this.checked) {
darkMode();
} else {
lightMode();
}
});
const totop = document.querySelector(".backToTop");
window.addEventListener("scroll", () =>{
if(window.pageYOffset > 100){
totop.classList.add("active");
} else{
totop.classList.remove("active");
}
});
const setNormalView = (isNormalView) => {
if (isNormalView) {
document.querySelector('#normal-view').classList.add('selected');
document.querySelector('#compact-view').classList.remove('selected');
document.querySelectorAll(".card-body").forEach((cardBody) => {
cardBody.classList.remove("hidden");
});
document.querySelectorAll(".row>div").forEach((ele) => {
ele.classList.replace("col-lg-2", "col-lg-4");
});
} else {
document.querySelector('#compact-view').classList.add('selected');
document.querySelector('#normal-view').classList.remove('selected');
document.querySelectorAll(".card-body").forEach((cardBody) => {
cardBody.classList.add("hidden");
});
document.querySelectorAll(".row>div").forEach((ele) => {
ele.classList.replace("col-lg-4", "col-lg-2");
});
}
};
setNormalView(true); // By default normal view is enabled.
document.querySelector('#normal-view').addEventListener('mousedown', () => {
setNormalView(true);
});
document.querySelector('#compact-view').addEventListener('mousedown', () => {
setNormalView(false);
});
const fixBrokenImages = () => {
const fallbackURL = 'images/fallback_image.png'
const img = document.getElementsByTagName('img');
for (let i = 0; i < img.length; i++) {
let t = img[i];
if (t.naturalWidth === 0) {
t.src = fallbackURL;
}
}
};
window.onload = fixBrokenImages;