myGallery.js
22.4 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
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
$(document).ready(function(){
$('body').append('<div id="overlay"></div><div class="gallery-page"><div class="closed-form gallery-closed"></div> <div class="gallery-show-wr"><div class="gallery-show-big-wrp"><table align="center" class="gallery-show-big" width="840" height="560" cellpadding="0" cellspacing="0" border="0"></table><div class="gallery-big-left"></div><div class="gallery-big-right"></div> <div class="copy-gallery-big-left"></div> <div class="copy-gallery-big-right"></div></div><div class="galley-show-min-wrapper"><div class="gallery-show-min"></div></div><div class="gallery-min-left"></div><div class="gallery-min-right"></div><div class="copy-gallery-min-left"></div><div class="copy-gallery-min-right"></div></div></div>');
var previewImgWidth = 152;
var previewImgMargin = 20;
var minPicLenght = 5;
var timeAnimate = 500;
var newPrevScrl = previewImgWidth+previewImgMargin;
var gallery = $('.gallery-page');
var procent = 1.68;
$('.gallery-box-min').click(function(e){
e.preventDefault();
var galleryWindowShow = $(this).parent().find('.gallery-box-hidden');
if($(galleryWindowShow).hasClass('gallery-box-hidden')) {
var newHeight = procent;
var windH = $(window).height();
var gallery = $('.gallery-page');
if (windH<755){
$('#overlay').fadeIn(400,
function(){$('.gallery-page').css({display:'block', marginTop:-(gallShowHeight/2)}).animate({opacity: 1, top:'50%'}, 200);});
gallery.css({height:((windH/newHeight)+148)+'px', marginTop:-(((windH/newHeight)+148)/2)+'px'});
}
else {
var gallShowHeight = ($('.gallery-show-big-wrp').height())+($('.galley-show-min-wrapper').height());
$('#overlay').fadeIn(400,
function(){$('.gallery-page').css({display:'block', marginTop:-(gallShowHeight/2)}).animate({opacity: 1, top:'50%'}, 200);});
}
addImgToModal(this);
clickSmallImg();
$('.gallery-min-right').unbind("click");
$('.gallery-min-left').unbind("click");
$('.gallery-min-right').bind("click", arrowNaviRight());
$('.gallery-min-left').bind("click", arrowNaviLeft());
$('.gallery-big-right').unbind("click");
$('.gallery-big-left').unbind("click");
$('.gallery-big-right').bind("click", bigClickRight());
$('.gallery-big-left').bind("click", bigClickLeft());
}
});
$('.closed-form, #overlay').click( function(){
$('.gallery-page')
.animate({opacity: 0, top: 255}, 200,
function(){
$(this).css('display', 'none');
$('#overlay').fadeOut(400);
}
);
$('.gallery-big-left, .gallery-big-right').attr('style','');
$('.gallery-show-wr .gallery-show-min, .gallery-show-wr .gallery-show-big').empty();
});
function addImgToModal(label){
$('.gallery-show-wr .gallery-show-min, .gallery-show-wr .gallery-show-big').empty();
var minClickIndex = $(label).index();
$('.gallery-show-min').css({marginLeft:0});
var previewImg = $(label).parent().find('.gallery-box-preview span');
var bigImg = $(label).parent().find('.gallery-box-big span');
for(var pi=0;pi<previewImg.length; pi++) {
var previewImgLink = $(previewImg[pi]).attr('data-link');
$('.gallery-show-min').append('<img src="'+previewImgLink+'"/>');
}
$('.gallery-show-min img:first-child').addClass('gallery-active-pic');
$('.gallery-show-min img:last-child').css({marginRight:0});
$('.gallery-show-min').append('<div class="border-gallery"></div>');
for (var px = 0; px< bigImg.length; px++) {
var bigImgLink = $(bigImg[px]).attr('data-link');
$('.gallery-show-big').append('<tr><td><img data-link="' + bigImgLink + '"/></td></tr>');
}
var bigImgFirstShow = $('.gallery-show-big tr:first-child').find('img');
var newBigImgFirstShow=bigImgFirstShow.attr('data-link');
bigImgFirstShow.attr('src',newBigImgFirstShow);
var newHeight = procent;
var windH = $(window).height();
var gallery = $('.gallery-page');
if (windH<755){
$('.gallery-show-big-wrp, .gallery-show-big, .gallery-show-big tr td').css({height:(windH/newHeight)+'px'});
$('.gallery-show-big img').css({height:(windH/newHeight)+'px'});
}
sizeMinBlock();
function sizeMinBlock(){
var sizeimmin = $('.gallery-show-min img').length;
$('.gallery-show-min').css({width:(newPrevScrl*sizeimmin)-previewImgMargin});
}
var previewImgMin = $('.gallery-show-min img');
$(previewImgMin).removeClass('gallery-active-pic');
$(previewImgMin[minClickIndex]).addClass('gallery-active-pic');
$('.border-gallery').css({left:newPrevScrl*minClickIndex});
function test(){
var indexBigImg = $('.gallery-show-big tr');
$('.gallery-show-big tr').css({display:'none'});
$(indexBigImg[minClickIndex]).fadeIn(100);
var bigImgShow = $(indexBigImg[minClickIndex]).find('img');
var newBigImgShow=bigImgShow.attr('data-link');
bigImgShow.attr('src',newBigImgShow);
}
test()
if(minClickIndex==0) {
$('.gallery-big-left').css({display:'none'})
}
else {$('.gallery-big-left').css({display:'block'})}
}
function clickSmallImg(){
var img2 = $('.gallery-show-min img');
var allMinImgLenght = $('.gallery-show-min img').length;
if(allMinImgLenght<=minPicLenght){
$('.gallery-min-left, .gallery-min-right, .copy-gallery-min-left, .copy-gallery-min-right').css({display:'none'})
}
else {
$('.gallery-min-right, .copy-gallery-min-left, .copy-gallery-min-right').css({display:'block'})
$('.gallery-min-left').css({display:'none'})
}
$('.gallery-show-min img').on('click', function(){
var img3 = img2;
var wrappOffset = $('.gallery-show-min').offset().left;
img3 = ($(img3[2]).offset().left)-wrappOffset;
$('.gallery-show-min img').removeClass('gallery-active-pic');
$(this).addClass('gallery-active-pic');
var offsetParent = ($('.gallery-active-pic').offset().left)-wrappOffset;
var smallImgIndex = $('.gallery-active-pic').index();
//console.log('---------/'+offsetParent)
function test(){
var indexBigImg = $('.gallery-show-big tr');
$('.gallery-show-big tr').css({display:'none'});
$(indexBigImg[smallImgIndex]).fadeIn(100);
var bigImgShow = $(indexBigImg[smallImgIndex]).find('img');
var newBigImgShow=bigImgShow.attr('data-link');
bigImgShow.attr('src',newBigImgShow);
}
var lenghtLeft = allMinImgLenght-(smallImgIndex+1);
//console.log(lenghtLeft)
if(smallImgIndex<=3-1) {
test();
$('.border-gallery').css({left:offsetParent});
$('.gallery-show-min img').removeClass('act-list');
$('.gallery-show-min img:first-child').addClass('act-list')
$('.gallery-min-left').css({display:'none'})
}
if(smallImgIndex==3-1){
test();
$('.gallery-show-min').stop().animate({marginLeft:-(offsetParent-img3)},timeAnimate)
$('.gallery-show-min img').removeClass('act-list');
$('.gallery-show-min img:first-child').addClass('act-list')
}
if(smallImgIndex<=minPicLenght-1) {
test();
$('.border-gallery').css({left:offsetParent});
if(smallImgIndex>3) {
$('.gallery-show-min').stop().animate({marginLeft:-(offsetParent-img3)},timeAnimate)
}
}
if(smallImgIndex>=minPicLenght-1) {
$('.gallery-min-left').css({display:'block'});
if(allMinImgLenght==minPicLenght){
if(smallImgIndex==minPicLenght-1){
$('.border-gallery').css({left:offsetParent});
$('.gallery-show-min').stop().animate({marginLeft:0},timeAnimate)
}
}
if(lenghtLeft==0) {
test();
$('.border-gallery').css({left:offsetParent});
$('.gallery-show-min img').removeClass('act-list');
$(this).prev().prev().prev().prev().addClass('act-list')
setTimeout(function(){
$('.gallery-min-right').css({display:'none'})
},timeAnimate)
}
if( lenghtLeft==1) {
test();
$('.gallery-show-min').stop().animate({marginLeft:-((offsetParent-img3)-newPrevScrl)},timeAnimate, function(){
$('.gallery-min-right').css({display:'none'})
})
$('.border-gallery').css({left:offsetParent});
$('.gallery-show-min img').removeClass('act-list');
$(this).prev().prev().prev().addClass('act-list')
}
if (lenghtLeft==2) {
test();
$('.border-gallery').css({left:offsetParent});
$('.gallery-show-min').stop().animate({marginLeft:-(offsetParent-img3)},timeAnimate, function(){$('.gallery-min-right').css({display:'none'})})
$('.gallery-show-min img').removeClass('act-list');
$(this).prev().prev().addClass('act-list')
}
if (lenghtLeft>2) {
console.log('>2')
test();
$('.border-gallery').css({left:offsetParent});
$('.gallery-show-min').stop().animate({marginLeft:-(offsetParent-img3)},timeAnimate, function(){$('.gallery-min-right').css({display:'block'})})
$('.gallery-show-min img').removeClass('act-list');
$(this).prev().prev().addClass('act-list')
}
if(allMinImgLenght<=minPicLenght) {
$('.gallery-min-left').css({display:'none'})
}
}
if(allMinImgLenght>minPicLenght && lenghtLeft>2) {
$('.gallery-min-right').css({display:'block'})
}
if(smallImgIndex==4-1){
$('.gallery-show-min img').removeClass('act-list');
$(this).prev().prev().addClass('act-list')
$('.gallery-show-min').stop().animate({marginLeft:-(offsetParent-img3)},timeAnimate)
$(img2[1]).click(function(){
$('.gallery-show-min').stop().animate({marginLeft:0},timeAnimate);
});
if (allMinImgLenght<=minPicLenght) {
$('.gallery-show-min').stop().animate({marginLeft:0},timeAnimate);
}
else {
$('.gallery-min-left').attr('style', 'disply:"block"');
}
}
if(smallImgIndex>=1 && smallImgIndex<allMinImgLenght-1){
$('.gallery-big-left, .gallery-big-right').css({display:'block'})
}
if(smallImgIndex==allMinImgLenght-1) {
$('.gallery-big-right').css({display:'none'})
}
if(smallImgIndex==0) {
$('.gallery-big-left').css({display:'none'})
}
//console.log(smallImgIndex + " smallImgIndex / -" + allMinImgLenght)
});
}
function arrowNaviRight(){
var minList = $('.gallery-show-min img');
$('.gallery-show-min img').removeClass('act-list');
$('.gallery-show-min img:first-child').addClass('act-list');
$('.gallery-min-right').on('click', function(){
var actList = $('.act-list');
var actListIndex = actList.index()+1;
var newAllMinImgLenght = $('.gallery-show-min img').length;
var howLeft = newAllMinImgLenght-actListIndex;
$(this).css('display','none');
if(howLeft>=(minPicLenght*2)-1) {
$('.gallery-show-min img').removeClass('act-list');
$(minList[actListIndex+(minPicLenght-1)]).addClass('act-list');
$('.gallery-show-min').stop().animate({marginLeft:-((actListIndex+(minPicLenght-1))*newPrevScrl)},timeAnimate, function(){
$('.gallery-min-right').css('display','block')
if (howLeft<(minPicLenght*2)) {
$('.gallery-min-right').css('display','none')
}
});
}
if (howLeft<(minPicLenght*2)-1) {
var newActlistIndex = newAllMinImgLenght-(actListIndex+4);
newActlistIndex = (actListIndex+newActlistIndex)-1;
$('.gallery-show-min img').removeClass('act-list');
$(minList[newActlistIndex]).addClass('act-list');
$('.gallery-show-min').stop().animate({marginLeft:-((newActlistIndex)*newPrevScrl)},timeAnimate, function(){
//$('.copy-gallery-min-right').css('display','none')
});
}
if(actListIndex>0) {
setTimeout(function(){
$('.gallery-min-left').css({display:'block'})
},timeAnimate)
}
})
}
function arrowNaviLeft(){
var minList = $('.gallery-show-min img');
$('.gallery-show-min img').removeClass('act-list');
$('.gallery-show-min img:first-child').addClass('act-list');
$('.gallery-min-left').on('click', function(){
var actList = $('.act-list');
var actListIndex = actList.index()+1;
var howLeft = actListIndex-1;
if (howLeft>0) {
$(this).css('display','none');
if(howLeft<=minPicLenght-1) {
$('.gallery-show-min img').removeClass('act-list');
$('.gallery-show-min img:first-child').addClass('act-list');
$('.gallery-show-min').stop().animate({marginLeft:0},timeAnimate, function(){
if(actListIndex<=minPicLenght+1) {
//$('.copy-gallery-min-right').attr('style', '')
$('.gallery-min-right').css({display:'block'})
} else {
$('.gallery-min-left').css('display','block')}
});
}
if (howLeft>minPicLenght-1) {
$('.gallery-show-min img').removeClass('act-list');
$(minList[actListIndex-(minPicLenght+1)]).addClass('act-list');
$('.gallery-show-min').stop().animate({marginLeft:-((actListIndex-(minPicLenght+1))*newPrevScrl)},timeAnimate, function(){
if(actListIndex<=minPicLenght+1) {
//$('.copy-gallery-min-left').css({display:'none'})
} else {
$('.gallery-min-right').css('display','block')
$('.gallery-min-left').css('display','block')}
});
}
}
});
}
function bigClickRight() {
var allMinImgLenght = $('.gallery-show-min img').length;
var img2 = $('.gallery-show-min img');
var img3 = newPrevScrl*3;
$('.gallery-big-right').on('click', function(){
var oneClick = $('.gallery-active-pic');
var oneClickIndex = oneClick.index()+1;
var smallImgIndex = oneClickIndex;
function test(){
var indexBigImg = $('.gallery-show-big tr');
$('.gallery-show-big tr').css({display:'none'});
$(indexBigImg[smallImgIndex]).fadeIn(100);
var bigImgShow = $(indexBigImg[smallImgIndex]).find('img');
var newBigImgShow=bigImgShow.attr('data-link');
bigImgShow.attr('src',newBigImgShow);
}
if(oneClickIndex<=3-1){
$('.gallery-show-min img').removeClass('gallery-active-pic act-list');
$(img2[oneClickIndex]).addClass('gallery-active-pic');
$('.gallery-show-min img:first-child').addClass('act-list')
$('.border-gallery').css({left:(newPrevScrl*oneClickIndex)});
test();
$('.gallery-show-min').stop().animate({marginLeft:0},timeAnimate)
}
if (allMinImgLenght-oneClickIndex>0 && oneClickIndex>3-1){
$('.gallery-show-min img').removeClass('gallery-active-pic act-list');
$(img2[oneClickIndex]).addClass('gallery-active-pic');
$(img2[oneClickIndex]).prev().prev().addClass('act-list');
test();
$('.border-gallery').css({left:(newPrevScrl*oneClickIndex)});
if(allMinImgLenght-oneClickIndex>2) {
$('.gallery-show-min').stop().animate({marginLeft:-((oneClickIndex*newPrevScrl)-img3+newPrevScrl)},timeAnimate)
}
if(oneClickIndex>=minPicLenght-2) {
if(oneClickIndex>allMinImgLenght) {
setTimeout(function(){
$('.gallery-min-left').css({display:'block'})
},timeAnimate)
}
}
if(oneClickIndex>=allMinImgLenght-3) {
$('.gallery-min-right').css({display:'none'})
}
if(oneClickIndex>=3 && oneClickIndex<=allMinImgLenght-4){
$('.gallery-min-right').css({display:'block'})
}
}
if(oneClickIndex>=1) {
$('.gallery-big-left').css({display:'block'})
if(allMinImgLenght>minPicLenght){
if(oneClickIndex>3-1){
$('.gallery-min-left').css({display:'block'})
}
}
}
if(oneClickIndex+1>=allMinImgLenght) {
$('.gallery-big-right').css({display:'none'})
}
})
}
function bigClickLeft() {
var allMinImgLenght = $('.gallery-show-min img').length;
var img2 = $('.gallery-show-min img');
var img3 = newPrevScrl*3;
$('.gallery-big-left').on('click', function(){
var oneClick = $('.gallery-active-pic');
var oneClickIndex = oneClick.index()-1;
var smallImgIndex = oneClickIndex;
function test(){
var indexBigImg = $('.gallery-show-big tr');
$('.gallery-show-big tr').css({display:'none'});
$(indexBigImg[smallImgIndex]).fadeIn(100);
var bigImgShow = $(indexBigImg[smallImgIndex]).find('img');
var newBigImgShow=bigImgShow.attr('data-link');
bigImgShow.attr('src',newBigImgShow);
}
if(oneClickIndex<=3-1){
if(oneClickIndex>0){
$('.gallery-show-min img').removeClass('gallery-active-pic act-list');
$(img2[oneClickIndex]).addClass('gallery-active-pic');
$('.gallery-show-min img:first-child').addClass('act-list')
$('.border-gallery').css({left:(newPrevScrl*oneClickIndex)});
test();
$('.gallery-show-min').stop().animate({marginLeft:0},timeAnimate)
}
if(oneClickIndex==0) {
$('.gallery-show-min img').removeClass('gallery-active-pic act-list');
$(img2[0]).addClass('gallery-active-pic');
$('.gallery-show-min img:first-child').addClass('act-list')
$('.border-gallery').css({left:(newPrevScrl*oneClickIndex)});
test()
}
}
if(oneClickIndex<3){
setTimeout(function(){
$('.gallery-min-left').css({display:'none'})
},timeAnimate)
}
if (allMinImgLenght-oneClickIndex>0 && oneClickIndex>3-1){
$('.gallery-show-min img').removeClass('gallery-active-pic act-list');
$(img2[oneClickIndex]).addClass('gallery-active-pic');
$(img2[oneClickIndex]).prev().prev().addClass('act-list');
test();
$('.border-gallery').css({left:(newPrevScrl*oneClickIndex)});
if(allMinImgLenght-oneClickIndex>2) {
$('.gallery-show-min').stop().animate({marginLeft:-((oneClickIndex*newPrevScrl)-img3+newPrevScrl)},timeAnimate)
}
if(oneClickIndex>=3 && oneClickIndex<=allMinImgLenght-4){
$('.gallery-min-right').css({display:'block'})
}
}
if(oneClickIndex<1) {
$('.gallery-big-left').css({display:'none'})
}
if(oneClickIndex<=allMinImgLenght-2) {
$('.gallery-big-right').css({display:'block'})
}
})
}
var newHeight = procent;
$(window).resize(function(){
var windowHeight = ($(window).height());
if (windowHeight<755){
$('.gallery-show-big-wrp, .gallery-show-big, .gallery-show-big tr td').css({height:(windowHeight/newHeight)+'px'})
$('.gallery-show-big img').css({height:(windowHeight/newHeight)+'px'})
gallery.css({height:((windowHeight/newHeight)+148)+'px', marginTop:-(((windowHeight/newHeight)+148)/2)+'px'})
}
else {
$('.gallery-show-big-wrp, .gallery-show-big, .gallery-show-big tr td, .gallery-show-big img').css({height:560})
gallery.css({height:710, marginTop:-(710/2)+'px'})
}
})
});