forked from fancyapps/fancybox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.fancybox.js
4110 lines (2716 loc) · 108 KB
/
jquery.fancybox.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
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
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ==================================================
// fancyBox v3.0.34
//
// Licensed GPLv3 for open source use
// or fancyBox Commercial License for commercial use
//
// http://fancyapps.com/fancybox/
// Copyright 2017 fancyApps
//
// ==================================================
;(function (window, document, $, undefined) {
'use strict';
// If there's no jQuery, fancyBox can't work
// =========================================
if ( !$ ) {
return undefined;
}
// Private default settings
// ========================
var defaults = {
// Animation duration in ms
speed : 330,
// Enable infinite gallery navigation
loop : true,
// Should zoom animation change opacity, too
// If opacity is 'auto', then fade-out if image and thumbnail have different aspect ratios
opacity : 'auto',
// Space around image, ignored if zoomed-in or viewport smaller than 800px
margin : [44, 0],
// Horizontal space between slides
gutter : 30,
// Should display toolbars
infobar : true,
buttons : true,
// What buttons should appear in the toolbar
slideShow : true,
fullScreen : true,
thumbs : true,
closeBtn : true,
// Should apply small close button at top right corner of the content
// If 'auto' - will be set for content having type 'html', 'inline' or 'ajax'
smallBtn : 'auto',
image : {
// Wait for images to load before displaying
// Requires predefined image dimensions
// If 'auto' - will zoom in thumbnail if 'width' and 'height' attributes are found
preload : "auto",
// Protect an image from downloading by right-click
protect : false
},
ajax : {
// Object containing settings for ajax request
settings : {
// This helps to indicate that request comes from the modal
// Feel free to change naming
data : {
fancybox : true
}
}
},
iframe : {
// Iframe template
tpl : '<iframe id="fancybox-frame{rnd}" name="fancybox-frame{rnd}" class="fancybox-iframe" frameborder="0" vspace="0" hspace="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen allowtransparency="true" src=""></iframe>',
// Preload iframe before displaying it
// This allows to calculate iframe content width and height
// (note: Due to "Same Origin Policy", you can't get cross domain data).
preload : true,
// Scrolling attribute for iframe tag
scrolling : 'no',
// Custom CSS styling for iframe wrapping element
css : {}
},
// Custom CSS class for layout
baseClass : '',
// Custom CSS class for slide element
slideClass : '',
// Base template for layout
baseTpl : '<div class="fancybox-container" role="dialog" tabindex="-1">' +
'<div class="fancybox-bg"></div>' +
'<div class="fancybox-controls">' +
'<div class="fancybox-infobar">' +
'<button data-fancybox-previous class="fancybox-button fancybox-button--left" title="Previous"></button>' +
'<div class="fancybox-infobar__body">' +
'<span class="js-fancybox-index"></span> / <span class="js-fancybox-count"></span>' +
'</div>' +
'<button data-fancybox-next class="fancybox-button fancybox-button--right" title="Next"></button>' +
'</div>' +
'<div class="fancybox-buttons">' +
'<button data-fancybox-close class="fancybox-button fancybox-button--close" title="Close (Esc)"></button>' +
'</div>' +
'</div>' +
'<div class="fancybox-slider-wrap">' +
'<div class="fancybox-slider"></div>' +
'</div>' +
'<div class="fancybox-caption-wrap"><div class="fancybox-caption"></div></div>' +
'</div>',
// Loading indicator template
spinnerTpl : '<div class="fancybox-loading"></div>',
// Error message template
errorTpl : '<div class="fancybox-error"><p>The requested content cannot be loaded. <br /> Please try again later.<p></div>',
// This will be appended to html content, if "smallBtn" option is not set to false
closeTpl : '<button data-fancybox-close class="fancybox-close-small">×</button>',
// Container is injected into this element
parentEl : 'body',
// Enable gestures (tap, zoom, pan and pinch)
touch : true,
// Enable keyboard navigation
keyboard : true,
// Try to focus on first focusable element after opening
focus : true,
// Close when clicked outside of the content
closeClickOutside : true,
// Callbacks
beforeLoad : $.noop,
afterLoad : $.noop,
beforeMove : $.noop,
afterMove : $.noop,
onComplete : $.noop,
onInit : $.noop,
beforeClose : $.noop,
afterClose : $.noop,
onActivate : $.noop,
onDeactivate : $.noop
};
var $W = $(window);
var $D = $(document);
var called = 0;
// Check if an object is a jQuery object and not a native JavaScript object
// ========================================================================
var isQuery = function (obj) {
return obj && obj.hasOwnProperty && obj instanceof $;
};
// Handle multiple browsers for requestAnimationFrame()
// ====================================================
var requestAFrame = (function() {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
function( callback ) {
window.setTimeout(callback, 1000 / 60); };
})();
// Check if element is inside the viewport by at least 1 pixel
// ===========================================================
var isElementInViewport = function( el ) {
var rect;
if ( typeof $ === "function" && el instanceof $ ) {
el = el[0];
}
rect = el.getBoundingClientRect();
return rect.bottom > 0 &&
rect.right > 0 &&
rect.left < (window.innerWidth || document.documentElement.clientWidth) &&
rect.top < (window.innerHeight || document.documentElement.clientHeight);
};
// Class definition
// ================
var FancyBox = function( content, opts, index ) {
var self = this;
self.opts = $.extend( true, { index : index }, defaults, opts || {} );
self.id = self.opts.id || ++called;
self.group = [];
self.currIndex = parseInt( self.opts.index, 10 ) || 0;
self.prevIndex = null;
self.prevPos = null;
self.currPos = 0;
self.firstRun = null;
// Create group elements from original item collection
self.createGroup( content );
if ( !self.group.length ) {
return;
}
// Save last active element and current scroll position
self.$lastFocus = $(document.activeElement).blur();
// Collection of interface DOM elements
self.elems = {};
// Collection of gallery objects
self.slides = {};
self.init( content );
};
$.extend(FancyBox.prototype, {
// Create DOM structure
// ====================
init : function() {
var self = this;
var testWidth;
var $container;
self.scrollTop = $W.scrollTop();
self.scrollLeft = $W.scrollLeft();
// Disable compensating on touch-enabled devices as they probably do not have scrollbars anyway
// and therefore we avoid of unnecessary layout reflow
if ( !$.fancybox.isTouch && !$( 'html' ).hasClass( 'fancybox-enabled' ) ) {
testWidth = $( 'body' ).width();
$( 'html' ).addClass( 'fancybox-enabled' );
testWidth = $( 'body' ).width() - testWidth;
// Body width has increased - compensate missing scrollbars
if ( testWidth > 1 ) {
$( '<style id="fancybox-noscroll" type="text/css">' ).html( '.compensate-for-scrollbar, .fancybox-enabled body { margin-right: ' + testWidth + 'px; }' ).appendTo( 'head' );
}
}
$container = $( self.opts.baseTpl )
.attr('id', 'fancybox-container-' + self.id)
.data( 'FancyBox', self )
.addClass( self.opts.baseClass )
.hide()
.prependTo( self.opts.parentEl );
// Create object holding references to jQuery wrapped nodes
self.$refs = {
container : $container,
bg : $container.find('.fancybox-bg'),
controls : $container.find('.fancybox-controls'),
buttons : $container.find('.fancybox-buttons'),
slider_wrap : $container.find('.fancybox-slider-wrap'),
slider : $container.find('.fancybox-slider'),
caption : $container.find('.fancybox-caption')
};
self.trigger( 'onInit' );
// Bring to front and enable events
self.activate();
// Try to avoid running multiple times
if ( self.current ) {
return;
}
self.jumpTo( self.currIndex );
},
// Create array of gally item objects
// Check if each object has valid type and content
// ===============================================
createGroup : function ( content ) {
var self = this;
var items = $.makeArray( content );
$.each(items, function( i, item ) {
var obj = {},
opts = {},
data = [],
$item,
type,
src,
srcParts;
// Step 1 - Make sure we have an object
if ( $.isPlainObject( item ) ) {
obj = item;
opts = item.opts || {};
} else if ( $.type( item ) === 'object' && $( item ).length ) {
$item = $( item );
data = $item.data();
opts = 'options' in data ? data.options : {};
opts = $.type( opts ) === 'object' ? opts : {};
obj.type = 'type' in data ? data.type : opts.type;
obj.src = 'src' in data ? data.src : ( opts.src || $item.attr( 'href' ) );
opts.width = 'width' in data ? data.width : opts.width;
opts.height = 'height' in data ? data.height : opts.height;
opts.thumb = 'thumb' in data ? data.thumb : opts.thumb;
opts.selector = 'selector' in data ? data.selector : opts.selector;
if ( 'srcset' in data ) {
opts.image = { srcset : data.srcset };
}
opts.$orig = $item;
} else {
obj = {
type : 'html',
content : item + ''
};
}
obj.opts = $.extend( true, {}, self.opts, opts );
// Step 2 - Make sure we have supported content type
type = obj.type;
src = obj.src || '';
if ( !type ) {
if ( obj.content ) {
type = 'html';
} else if ( src.match(/(^data:image\/[a-z0-9+\/=]*,)|(\.(jp(e|g|eg)|gif|png|bmp|webp|svg|ico)((\?|#).*)?$)/i) ) {
type = 'image';
} else if ( src.match(/\.(pdf)((\?|#).*)?$/i) ) {
type = 'pdf';
} else if ( src.charAt(0) === '#' ) {
type = 'inline';
}
obj.type = type;
}
// Step 3 - Some adjustments
obj.index = self.group.length;
// Check if $orig and $thumb objects exist
if ( obj.opts.$orig && !obj.opts.$orig.length ) {
delete obj.opts.$orig;
}
if ( !obj.opts.$thumb && obj.opts.$orig ) {
obj.opts.$thumb = obj.opts.$orig.find( 'img:first' );
}
if ( obj.opts.$thumb && !obj.opts.$thumb.length ) {
delete obj.opts.$thumb;
}
// Caption is a "special" option, it can be passed as a method
if ( $.type( obj.opts.caption ) === 'function' ) {
obj.opts.caption = obj.opts.caption.apply( item, [ self, obj ] );
} else if ( 'caption' in data ) {
obj.opts.caption = data.caption;
} else if ( opts.$orig ) {
obj.opts.caption = $item.attr( 'title' );
}
// Make sure we have caption as a string
obj.opts.caption = obj.opts.caption === undefined ? '' : obj.opts.caption + '';
// Check if url contains selector used to filter the content
// Example: "ajax.html #something"
if ( type === 'ajax' ) {
srcParts = src.split(/\s+/, 2);
if ( srcParts.length > 1 ) {
obj.src = srcParts.shift();
obj.opts.selector = srcParts.shift();
}
}
if ( obj.opts.smallBtn == 'auto' ) {
if ( $.inArray( type, ['html', 'inline', 'ajax'] ) > -1 ) {
obj.opts.buttons = false;
obj.opts.smallBtn = true;
} else {
obj.opts.smallBtn = false;
}
}
if ( type === 'pdf' ) {
obj.type = 'iframe';
obj.opts.closeBtn = true;
obj.opts.smallBtn = false;
obj.opts.iframe.preload = false;
}
if ( obj.opts.modal ) {
$.extend(true, obj.opts, {
infobar : 0,
buttons : 0,
keyboard : 0,
slideShow : 0,
fullScreen : 0,
closeClickOutside : 0
});
}
self.group.push( obj );
});
},
// Attach an event handler functions for:
// - navigation elements
// - browser scrolling, resizing;
// - focusing
// - keyboard
// =================
addEvents : function() {
var self = this;
var runUpdate = function () {
$W.scrollTop( self.scrollTop ).scrollLeft( self.scrollLeft );
self.$refs.slider_wrap.show();
self.update();
};
self.removeEvents();
// Make navigation elements clickable
self.$refs.container.on('click.fb-close', '[data-fancybox-close]', function(e) {
e.stopPropagation();
e.preventDefault();
self.close( e );
}).on('click.fb-previous', '[data-fancybox-previous]', function(e) {
e.stopPropagation();
e.preventDefault();
self.previous();
}).on('click.fb-next', '[data-fancybox-next]', function(e) {
e.stopPropagation();
e.preventDefault();
self.next();
});
// Handle page scrolling and browser resizing
$( window ).on('orientationchange.fb resize.fb', function(e) {
requestAFrame(function() {
if ( e && e.originalEvent && e.originalEvent.type == "orientationchange" ) {
self.$refs.slider_wrap.hide();
requestAFrame( runUpdate );
} else {
runUpdate();
}
});
});
// Trap focus
$D.on('focusin.fb', function(e) {
var instance;
if ( $.fancybox ) {
instance = $.fancybox.getInstance();
if ( instance && !$( e.target ).hasClass( 'fancybox-container' ) && !$.contains( instance.$refs.container[0], e.target ) ) {
e.stopPropagation();
instance.focus();
}
}
});
// Enable keyboard navigation
$( document ).on('keydown.fb', function (e) {
var current = self.current,
keycode = e.keyCode || e.which;
if ( !current || !current.opts.keyboard ) {
return;
}
if ( $(e.target).is('input') || $(e.target).is('textarea') ) {
return;
}
// Backspace and Esc keys
if ( keycode === 8 || keycode === 27 ) {
e.preventDefault();
self.close();
return;
}
switch ( keycode ) {
case 37: // Left arrow
case 38: // Up arrow
e.preventDefault();
self.previous();
break;
case 39: // Right arrow
case 40: // Down arrow
e.preventDefault();
self.next();
break;
case 80: // "P"
case 32: // Spacebar
e.preventDefault();
if ( self.SlideShow ) {
e.preventDefault();
self.SlideShow.toggle();
}
break;
case 70: // "F"
if ( self.FullScreen ) {
e.preventDefault();
self.FullScreen.toggle();
}
break;
case 71: // "G"
if ( self.Thumbs ) {
e.preventDefault();
self.Thumbs.toggle();
}
break;
}
});
},
// Remove events added by the core
// ===============================
removeEvents : function () {
$W.off( 'scroll.fb resize.fb orientationchange.fb' );
$D.off( 'keydown.fb focusin.fb click.fb-close' );
this.$refs.container.off('click.fb-close click.fb-previous click.fb-next');
},
// Slide to left
// ==================
previous : function( duration ) {
this.jumpTo( this.currIndex - 1, duration );
},
// Slide to right
// ===================
next : function( duration ) {
this.jumpTo( this.currIndex + 1, duration );
},
// Display current gallery item, move slider to current position
// =============================================================
jumpTo : function ( to, duration ) {
var self = this,
firstRun,
index,
pos,
loop;
firstRun = self.firstRun = ( self.firstRun === null );
index = pos = to = parseInt( to, 10 );
loop = self.current ? self.current.opts.loop : false;
if ( self.isAnimating || ( index == self.currIndex && !firstRun ) ) {
return;
}
if ( self.group.length > 1 && loop ) {
index = index % self.group.length;
index = index < 0 ? self.group.length + index : index;
// Calculate closest position of upcoming item from the current one
if ( self.group.length == 2 ) {
pos = to - self.currIndex + self.currPos;
} else {
pos = index - self.currIndex + self.currPos;
if ( Math.abs( self.currPos - ( pos + self.group.length ) ) < Math.abs( self.currPos - pos ) ) {
pos = pos + self.group.length;
} else if ( Math.abs( self.currPos - ( pos - self.group.length ) ) < Math.abs( self.currPos - pos ) ) {
pos = pos - self.group.length;
}
}
} else if ( !self.group[ index ] ) {
self.update( false, false, duration );
return;
}
if ( self.current ) {
self.current.$slide.removeClass('fancybox-slide--current fancybox-slide--complete');
self.updateSlide( self.current, true );
}
self.prevIndex = self.currIndex;
self.prevPos = self.currPos;
self.currIndex = index;
self.currPos = pos;
// Create slides
self.current = self.createSlide( pos );
if ( self.group.length > 1 ) {
if ( self.opts.loop || pos - 1 >= 0 ) {
self.createSlide( pos - 1 );
}
if ( self.opts.loop || pos + 1 < self.group.length ) {
self.createSlide( pos + 1 );
}
}
self.current.isMoved = false;
self.current.isComplete = false;
duration = parseInt( duration === undefined ? self.current.opts.speed * 1.5 : duration, 10 );
// Move slider to the next position
// Note: the content might still be loading
self.trigger( 'beforeMove' );
self.updateControls();
if ( firstRun ) {
self.current.$slide.addClass('fancybox-slide--current');
self.$refs.container.show();
requestAFrame(function() {
self.$refs.bg.css('transition-duration', self.current.opts.speed + 'ms');
self.$refs.container.addClass( 'fancybox-container--ready' );
});
}
// Set position immediately on first opening
self.update( true, false, firstRun ? 0 : duration, function() {
self.afterMove();
});
self.loadSlide( self.current );
if ( !( firstRun && self.current.$ghost ) ) {
self.preload();
}
},
// Create new "slide" element
// These are gallery items that are actually added to DOM
// =======================================================
createSlide : function( pos ) {
var self = this;
var $slide;
var index;
var found;
index = pos % self.group.length;
index = index < 0 ? self.group.length + index : index;
if ( !self.slides[ pos ] && self.group[ index ] ) {
// If we are looping and slide with that index already exists, then reuse it
if ( self.opts.loop && self.group.length > 2 ) {
for (var key in self.slides) {
if ( self.slides[ key ].index === index ) {
found = self.slides[ key ];
found.pos = pos;
self.slides[ pos ] = found;
delete self.slides[ key ];
self.updateSlide( found );
return found;
}
}
}
$slide = $('<div class="fancybox-slide"></div>').appendTo( self.$refs.slider );
self.slides[ pos ] = $.extend( true, {}, self.group[ index ], {
pos : pos,
$slide : $slide,
isMoved : false,
isLoaded : false
});
}
return self.slides[ pos ];
},
zoomInOut : function( type, duration, callback ) {
var self = this;
var current = self.current;
var $what = current.$placeholder;
var opacity = current.opts.opacity;
var $thumb = current.opts.$thumb;
var thumbPos = $thumb ? $thumb.offset() : 0;
var slidePos = current.$slide.offset();
var props;
var start;
var end;
if ( !$what || !current.isMoved || !thumbPos || !isElementInViewport( $thumb ) ) {
return false;
}
if ( type === 'In' && !self.firstRun ) {
return false;
}
$.fancybox.stop( $what );
self.isAnimating = true;
props = {
top : thumbPos.top - slidePos.top + parseFloat( $thumb.css( "border-top-width" ) || 0 ),
left : thumbPos.left - slidePos.left + parseFloat( $thumb.css( "border-left-width" ) || 0 ),
width : $thumb.width(),
height : $thumb.height(),
scaleX : 1,
scaleY : 1
};
// Check if we need to animate opacity
if ( opacity == 'auto' ) {
opacity = Math.abs( current.width / current.height - props.width / props.height ) > 0.1;
}
if ( type === 'In' ) {
start = props;
end = self.getFitPos( current );
end.scaleX = end.width / start.width;
end.scaleY = end.height / start.height;
if ( opacity ) {
start.opacity = 0.1;
end.opacity = 1;
}
} else {
start = $.fancybox.getTranslate( $what );
end = props;
// Switch to thumbnail image to improve animation performance
if ( current.$ghost ) {
current.$ghost.show();
if ( current.$image ) {
current.$image.remove();
}
}
start.scaleX = start.width / end.width;
start.scaleY = start.height / end.height;
start.width = end.width;
start.height = end.height;
if ( opacity ) {
end.opacity = 0;
}
}
self.updateCursor( end.width, end.height );
// There is no need to animate width/height properties
delete end.width;
delete end.height;
$.fancybox.setTranslate( $what, start );
$what.show();
self.trigger( 'beforeZoom' + type );
requestAFrame(function() {
$what.css( 'transition', 'all ' + duration + 'ms' );
$.fancybox.setTranslate( $what, end );
setTimeout(function() {
requestAFrame(function() {
var reset;
$what.css( 'transition', 'none' );
reset = $.fancybox.getTranslate( $what );
reset.scaleX = 1;
reset.scaleY = 1;
// Reset scalex/scaleY values; this helps for perfomance
$.fancybox.setTranslate( $what, reset );
self.trigger( 'afterZoom' + type );
callback.apply( self );
self.isAnimating = false;
});
}, duration);
});
return true;
},
// Check if image dimensions exceed parent element
// ===============================================
canPan : function() {
var self = this;
var current = self.current;
var $what = current.$placeholder;
var rez = false;
if ( $what ) {
rez = self.getFitPos( current );
rez = Math.abs( $what.width() - rez.width ) > 1 || Math.abs( $what.height() - rez.height ) > 1;
}
return rez;
},
// Check if current image dimensions are smaller than actual
// =========================================================
isScaledDown : function() {
var self = this;
var current = self.current;
var $what = current.$placeholder;
var rez = false;
if ( $what ) {
rez = $.fancybox.getTranslate( $what );
rez = rez.width < current.width || rez.height < current.height;
}
return rez;