forked from alchemyiedc/alchemyiedc.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSuperGallery.js
150 lines (130 loc) · 4.87 KB
/
SuperGallery.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
// SuperGallery JS V1.0 is copyrighted to Havis V H under the brand HVH
// But Have fun Using it!! :D
const styles = [
'color: white',
'font-size: 30px',
'font-family:"Outfit", sans-serif ',
'font-weight: bold',
].join(';');
const styles2 = [
'color: #5656f6',
'background: #111',
'font-size: 30px',
'border-radius: 12px 0px 12px 0px',
'padding: 10px',
'font-family:"Outfit", sans-serif ',
'font-weight: bold',
'margin:12px'
].join(';');
console.log("%cHello There!!!", styles);
console.log("%cthis Website uses SuperGallery from %cHVH", styles, styles2);
document.getElementById("phoato").addEventListener("click", function (e) {
if(e.target.className == "photoCarousel"){
Carousel();
}
});
function openGallery() {
document.getElementById('galleryWindow').style.display = 'flex';
setTimeout(() => {
if (window.innerWidth > 750) {
document.getElementById('galleryWindow').style.height = '90vh';
document.getElementById('galleryWindow').style.width = '95vw';
document.getElementById('galleryWindow').style.zIndex = '51';
document.getElementById('galleryWindow').style.top = '50%';
document.getElementById('galleryWindow').style.opacity = '100%';
}
else {
document.getElementById('galleryWindow').style.height = '100vh';
document.getElementById('galleryWindow').style.width = '100vw';
document.getElementById('galleryWindow').style.top = '50%';
document.getElementById('galleryWindow').style.opacity = '100%';
}
}, 100);
}
function closeGallery() {
document.getElementById('galleryWindow').style.height = '20vh';
document.getElementById('galleryWindow').style.width = '30vw';
document.getElementById('galleryWindow').style.top = '70%';
document.getElementById('galleryWindow').style.opacity = '0%';
setTimeout(() => {
document.getElementById('galleryWindow').style.display = 'none';
}, 400);
}
_isCarouselOpen = false;
_imgIndex = 0;
var pics = []
carouseL = document.getElementById('phoato');
function imgLoader(img) {
img.onload = function () {
var originalWidth = img.naturalWidth;
var originalHeight = img.naturalHeight;
var targetWidth = 600;
if (window.innerWidth < 750) {
targetWidth = window.innerWidth - 120;
}
var aspectRatio = originalWidth / originalHeight;
var newHeight = targetWidth / aspectRatio;
document.getElementById('carouselImage').style.height = newHeight + 'px';
document.getElementById('carouselImage').style.width = targetWidth + 'px';
};
document.getElementById('imageCounter').innerHTML = (_imgIndex + 1) + '/' + pics.length;
}
function Carousel() {
if (_isCarouselOpen) {
// carouseL.style.height = '0vh';
carouseL.style.opacity = '0%';
setTimeout(() => {
carouseL.style.display = 'none';
document.body.style.overflow = 'auto';
}, 400);
_isCarouselOpen = false;
} else {
carouseL.style.display = 'flex';
document.body.style.overflow = 'hidden';
setTimeout(() => {
// carouseL.style.height = '100vh';
carouseL.style.opacity = '100%';
}, 100);
_isCarouselOpen = true;
}
}
function nextImage() {
if (_imgIndex < pics.length - 1) {
_imgIndex++;
document.getElementById('carouselImage').style.background = 'url(' + pics[_imgIndex] + ') no-repeat center center';
document.getElementById('carouselImage').style.backgroundSize = 'contain';
var img = new Image();
img.src = pics[_imgIndex];
imgLoader(img);
}
}
function prevImage() {
if (_imgIndex > 0) {
_imgIndex--;
document.getElementById('carouselImage').style.background = 'url(' + pics[_imgIndex] + ') no-repeat center center';
document.getElementById('carouselImage').style.backgroundSize = 'contain';
var img = new Image();
img.src = pics[_imgIndex];
imgLoader(img);
}
}
function trigger(action){
picsJson = JSON.parse(atob(localStorage.getItem('msg')));
if (action == 'loaded') {
pics = picsJson.data;
document.getElementById('carouselImage').style.background = 'url(' + pics[0] + ') no-repeat center center';
document.getElementById('carouselImage').style.backgroundSize = 'contain';
var img = new Image();
img.src = pics[0];
imgLoader(img);
}
else if (action == "target") {
_imgIndex = picsJson.data;
document.getElementById('carouselImage').style.background = 'url(' + pics[_imgIndex] + ') no-repeat center center';
document.getElementById('carouselImage').style.backgroundSize = 'contain';
var img = new Image();
img.src = pics[_imgIndex];
imgLoader(img);
Carousel();
}
}