-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
260 lines (235 loc) · 7.84 KB
/
index.html
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Asana | San Francisco Pet Adoption Agency</title>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="assets/styles/site.css">
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script>
$(document).ready(function(){
var dataImages = [];
var dataSources = [];
var imageList = [];
var length = 0;
var rowMaxLength = 0;
var thisIndex = 0;
var rowMax = 5;
var thisRow = 0;
var fileName = "assets/data/dogs.json";
var gallerySlideshowImages = $(".gallery-slideshow-container .image-viewer");
var gallerySlideshowImagesCounter = $(".gallery-slideshow-container .image-counter");
var gallerySlideshowNavNext = $(".gallery-slideshow-container .nav-next");
var gallerySlideshowNavPrev = $(".gallery-slideshow-container .nav-prev");
var galleryThumbImages = $(".gallery-thumb-container .image-viewer");
var galleryThumbImagesCounter = $(".gallery-thumb-container .image-counter");
var galleryThumbNavNext = $(".gallery-thumb-container .nav-next");
var galleryThumbNavPrev = $(".gallery-thumb-container .nav-prev");
var close = $(".close");
var header = $("#header");
var footer = $("#footer");
/* get header and footer */
$.get("assets/snippets/header.html", function(data) {
header.html(data);
});
$.get("assets/snippets/footer.html", function(data) {
footer.html(data);
});
/* fetch JSON from file and load images for slideshow and thumbnail galleries */
$.getJSON( fileName, function( data ) {
$.each( data.dogs, function( key, val ) {
dataImages[key] = val.image;
dataSources[key] = val.source;
});
console.log(dataImages.length + " values fetched");
// put html blocks into ImageList[]
createImageList();
addControls();
updateGallerySlideshow();
updateGalleryThumb();
});
/* get rid of border around active thumb gallery image and close gallery */
close.click(function(){
$(".active").each(function() {
$(this).removeClass("active");
});
$(this).parent().parent().hide();
});
/* go to the next image in slideshow gallery */
gallerySlideshowNavNext.click(function(){
if (thisIndex < length - 1) {
thisIndex++;
updateGallerySlideshow();
// update the thumb gallery to the next row
if (thisIndex % rowMax === 0) {
thisRow = thisIndex / rowMax;
updateGalleryThumb();
}
updateBorder();
}
});
/* go to the previous image in slideshow gallery */
gallerySlideshowNavPrev.click(function(){
if (thisIndex >= 1) {
thisIndex--;
updateGallerySlideshow();
// update the thumb gallery to the prev row
if (thisIndex % rowMax === rowMax - 1) {
thisRow = ((thisIndex + 1) / rowMax) - 1;
updateGalleryThumb();
}
updateBorder();
}
});
/* go to the next row in thumb gallery */
galleryThumbNavNext.click(function(){
if (thisRow < rowMaxLength - 1) {
thisRow++;
updateGalleryThumb();
}
});
/* go to the previous row in thumb gallery */
galleryThumbNavPrev.click(function(){
if (thisRow >= 1) {
thisRow--;
updateGalleryThumb();
}
});
/* update slideshow image if click on image in thumb gallery */
$(document).on("click", ".gallery-thumb-container .gallery-image", function(){
thisIndex = parseInt(this.id);
updateBorder($(this));
$(".gallery-slideshow-container").show();
updateGallerySlideshow();
});
/* add hyperlinks to the gallery nav controls */
function addControls() {
$(".gallery-nav .nav-prev").each(function(){
$(this).html("<a title='Get Previous'><i class='fas fa-angle-double-left'></i></a>");
});
$(".gallery-nav .nav-next").each(function(){
$(this).html("<a title='Get Next'><i class='fas fa-angle-double-right'></i></a>");
});
close.each(function(){
$(this).html("<a class='close' title='Close'><i class='far fa-times-circle'></i></a>");
});
}
/* create HTML for images and put into imageList[] */
function createImageList() {
length = dataImages.length;
rowMaxLength = length / rowMax;
for (i = 0; i < length; i++) {
var str = "<div class='gallery-image' id='" + i + "'><img src='/dog-image-gallery" + dataImages[i] + "' alt='asana: san francisco pet adoption agency' title='asana: san francisco pet adoption agency'></div>";
imageList[i] = str;
}
console.log(length + " images created");
}
/* update slideshow gallery's prev/next nav, images, and image counter */
function updateGallerySlideshow() {
checkImageIndexPosition();
updateGallerySlideshowImages();
updateGallerySlideshowCounter();
}
/* update thumb gallery's prev/next nav, images, and row counter */
function updateGalleryThumb() {
checkImageRowPosition();
updateGalleryThumbImages();
updateGalleryThumbCounter();
}
/* fetch image from ImageList[] and put into slideshow gallery */
function updateGallerySlideshowImages() {
gallerySlideshowImages.append().html(imageList[thisIndex]);
}
/* fetch images from ImageList[] and put into thumb gallery */
function updateGalleryThumbImages() {
var thisStr = "";
var startIndex = thisRow * rowMax;
maxLength = rowMax + startIndex;
for (i = startIndex; i < maxLength; i++) {
thisStr = thisStr + imageList[i];
}
galleryThumbImages.append().html(thisStr);
}
/* update the slideshow gallery's image counter to show the current image count */
function updateGallerySlideshowCounter() {
gallerySlideshowImagesCounter.text((thisIndex + 1) + " of " + length);
}
/* update the thumbnail gallery's row counter to show the current row count */
function updateGalleryThumbCounter() {
galleryThumbImagesCounter.text((thisRow + 1) + " of " + rowMaxLength);
}
/* check thisIndex to see if slideshow gallery prev/next nav should be disabled */
function checkImageIndexPosition() {
if (thisIndex === 0) {
gallerySlideshowNavPrev.addClass("disabled");
}
else if (thisIndex >= 1) {
gallerySlideshowNavPrev.removeClass("disabled");
}
if (thisIndex === length - 1) {
gallerySlideshowNavNext.addClass("disabled");
}
else if (thisIndex <= length - 2) {
gallerySlideshowNavNext.removeClass("disabled");
}
console.log("thisIndex: " + thisIndex + " length: " + length);
}
/* check thisRow to see if thumb gallery prev/next nav should be disabled */
function checkImageRowPosition() {
if (thisRow === 0) {
galleryThumbNavPrev.addClass("disabled");
}
else if (thisRow === 1) {
galleryThumbNavPrev.removeClass("disabled");
}
if (thisRow === rowMaxLength - 2) {
galleryThumbNavNext.removeClass("disabled");
}
else if (thisRow === rowMaxLength - 1) {
galleryThumbNavNext.addClass("disabled");
}
}
/* add border around active thumb gallery image */
function updateBorder() {
$(".active").removeClass("active");
$(".gallery-thumb-container #" + thisIndex).children("img").addClass("active");
}
});
</script>
</head>
<body>
<div id="container" class="site-container">
<header id="header"><noscript>Our dogs are here, I promise! Please turn on your JavaScript to find your new best friend.</noscript></header>
<main id="content">
<div class="gallery-thumb-container">
<div class="gallery-controls">
<div class="gallery-nav">
<div class="nav-prev"></div>
<div class="image-counter"></div>
<div class="nav-next"></div>
</div>
</div>
<div class="image-viewer">
</div>
</div>
<div class="gallery-slideshow-container">
<div class="gallery-controls">
<div class="gallery-nav">
<div class="nav-prev"></div>
<div class="image-counter"></div>
<div class="nav-next"></div>
</div>
<div class="close"></div>
</div>
<div class="image-viewer">
</div>
</div>
</main>
<footer id="footer">
</footer>
</div>
</body>
</html>