-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
149 lines (126 loc) · 3.57 KB
/
index.html
File metadata and controls
149 lines (126 loc) · 3.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="./lightbox.css" />
<title>simple-lightbox</title>
<style>
body {
font-family: sans-serif;
font-size: 22px;
text-align: center;
}
#gallery-one {
box-sizing: border-box;
min-height: 300px;
}
.gallery {
padding: 5px;
}
.container {
width: 80%;
margin: 0 auto;
}
button {
cursor: pointer;
}
@media screen and (max-width: 360px) {
h1 {
font-size: 25px;
}
h2 {
font-size: 20px;
}
}
.modal {
box-sizing: border-box;
padding: 20px;
color: #fff;
border: 4px solid #fff;
background-color: #303030;
border-radius: 5px;
width: auto;
height: auto;
}
</style>
</head>
<body>
<div class="container">
<h1>
simple-lightbox <span style="color: #2a82b5;">DEMO</span>
</h1>
<h2>Gallery with sections</h2>
<button class="btn">1</button>
<button class="btn">2</button>
<div class="gallery" id="gallery-one"></div>
<h2>Gallery standalone</h2>
<div class="gallery" id="gallery-two"></div>
<h2>Modal</h2>
<button id="modal">Open Modal</button>
<button id="modal-callback">Open Modal (with 'onclose' callback)</button>
</div>
<script src="./lightbox.js"></script>
<script>
// Sections + fetch from folder (one of many approaches)
async function fetchFromFolder(directory) {
const response = await fetch(directory);
const text = await response.text();
const textAsHtml = new DOMParser().parseFromString(text, "text/html");
return [...textAsHtml.getElementsByTagName("a")]
.filter(photo => photo.href.match(/\.(jpe?g|png)$/i))
.map(photo => photo = {
"src": directory + photo.pathname,
"alt": photo.textContent.split('.')[0]
});
}
async function createGallery() {
const images_array = await fetchFromFolder("./photos/gallery-one/1");
const galleryOne = LBcreateGallery({ target: "gallery-one", images_array });
document.querySelectorAll(".btn").forEach(button => {
button.addEventListener("click", async function() {
galleryOne.changePhotos(await fetchFromFolder(`./photos/gallery-one/${this.textContent}`));
});
});
}
createGallery();
// Standalone
const imgArr = [
{
"src": "./photos/gallery-two/additional-photos/craiddo.jpg",
"alt": "craiddo"
},
{
"src": "./photos/gallery-two/additional-photos/mountain-side.jpg",
"alt": "mountain-side"
},
{
"src": "./photos/gallery-two/landscape.jpg",
"alt": "landscape"
},
{
"src": "./photos/gallery-two/river.jpg",
"alt": "river"
}
];
LBcreateGallery({
target: "gallery-two",
photos_scale: 0.4,
images_array: imgArr
});
// Modal
document.getElementById("modal").addEventListener("click", function() {
const modalElement = LButils.createTag("div", "modal")
.LBtext("This is a simple modal window!");
LButils.createLightboxComponent(modalElement);
});
// Modal with 'onclose' callback
document.getElementById("modal-callback").addEventListener("click", function() {
const modalElement = LButils.createTag("div", "modal")
.LBtext("This is a modal window with 'onclose' callback!");
LButils.createLightboxComponent(modalElement, () => alert("Closed!"));
});
</script>
</body>
</html>