forked from Anikkkkettt/MovieHub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (39 loc) · 1.5 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
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;