2
* fancyBox - jQuery Plugin
3
* version: 2.1.4 (Thu, 10 Jan 2013)
4
* @requires jQuery v1.6 or later
6
* Examples at http://fancyapps.com/fancybox/
7
* License: www.fancyapps.com/fancybox/#license
9
* Copyright 2012 Janis Skarnelis - janis@fancyapps.com
13
(function (window, document, $, undefined) {
18
F = $.fancybox = function () {
19
F.open.apply( this, arguments );
21
IE = navigator.userAgent.match(/msie/),
23
isTouch = document.createTouch !== undefined,
25
isQuery = function(obj) {
26
return obj && obj.hasOwnProperty && obj instanceof $;
28
isString = function(str) {
29
return str && $.type(str) === "string";
31
isPercentage = function(str) {
32
return isString(str) && str.indexOf('%') > 0;
34
isScrollable = function(el) {
35
return (el && !(el.style.overflow && el.style.overflow === 'hidden') && ((el.clientWidth && el.scrollWidth > el.clientWidth) || (el.clientHeight && el.scrollHeight > el.clientHeight)));
37
getScalar = function(orig, dim) {
38
var value = parseInt(orig, 10) || 0;
40
if (dim && isPercentage(orig)) {
41
value = F.getViewport()[ dim ] / 100 * value;
44
return Math.ceil(value);
46
getValue = function(value, dim) {
47
return getScalar(value, dim) + 'px';
51
// The current version of fancyBox
70
autoCenter : !isTouch,
76
scrolling : 'auto', // 'auto', 'yes' or 'no'
92
headers : { 'X-fancyBox': true }
100
allowfullscreen : 'true',
101
allowscriptaccess : 'always'
106
13 : 'left', // enter
107
34 : 'up', // page down
108
39 : 'left', // right arrow
109
40 : 'up' // down arrow
112
8 : 'right', // backspace
113
33 : 'down', // page up
114
37 : 'right', // left arrow
115
38 : 'down' // up arrow
117
close : [27], // escape key
118
play : [32], // space - start/stop slideshow
119
toggle : [70] // letter "f" - toggle fullscreen
127
scrollOutside : true,
129
// Override some properties
138
wrap : '<div class="fancybox-wrap" tabIndex="-1"><div class="fancybox-skin"><div class="fancybox-outer"><div class="fancybox-inner"></div></div></div></div>',
139
image : '<img class="fancybox-image" src="{href}" alt="" />',
140
iframe : '<iframe id="fancybox-frame{rnd}" name="fancybox-frame{rnd}" class="fancybox-iframe" frameborder="0" vspace="0" hspace="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen' + (IE ? ' allowtransparency="true"' : '') + '></iframe>',
141
error : '<p class="fancybox-error">The requested content cannot be loaded.<br/>Please try again later.</p>',
142
closeBtn : '<a title="Close" class="fancybox-item fancybox-close" href="javascript:;"></a>',
143
next : '<a title="Next" class="fancybox-nav fancybox-next" href="javascript:;"><span></span></a>',
144
prev : '<a title="Previous" class="fancybox-nav fancybox-prev" href="javascript:;"><span></span></a>'
147
// Properties for each animation type
149
openEffect : 'fade', // 'elastic', 'fade' or 'none'
151
openEasing : 'swing',
153
openMethod : 'zoomIn',
156
closeEffect : 'fade', // 'elastic', 'fade' or 'none'
158
closeEasing : 'swing',
160
closeMethod : 'zoomOut',
162
// Changing next gallery item
163
nextEffect : 'elastic', // 'elastic', 'fade' or 'none'
165
nextEasing : 'swing',
166
nextMethod : 'changeIn',
168
// Changing previous gallery item
169
prevEffect : 'elastic', // 'elastic', 'fade' or 'none'
171
prevEasing : 'swing',
172
prevMethod : 'changeOut',
174
// Enable default helpers
181
onCancel : $.noop, // If canceling
182
beforeLoad : $.noop, // Before loading
183
afterLoad : $.noop, // After loading
184
beforeShow : $.noop, // Before changing in current item
185
afterShow : $.noop, // After opening
186
beforeChange : $.noop, // Before changing gallery item
187
beforeClose : $.noop, // Before closing
188
afterClose : $.noop // After closing
192
group : {}, // Selected group
193
opts : {}, // Group options
194
previous : null, // Previous element
195
coming : null, // Element being loaded
196
current : null, // Currently loaded element
197
isActive : false, // Is activated
198
isOpen : false, // Is currently open
199
isOpened : false, // Have been fully opened at least once
223
open: function (group, opts) {
228
if (!$.isPlainObject(opts)) {
232
// Close if already active
233
if (false === F.close(true)) {
238
if (!$.isArray(group)) {
239
group = isQuery(group) ? $(group).get() : [group];
242
// Recheck if the type of each element is `object` and set content type (image, ajax, etc)
243
$.each(group, function(i, element) {
253
if ($.type(element) === "object") {
254
// Check if is DOM element
255
if (element.nodeType) {
256
element = $(element);
259
if (isQuery(element)) {
261
href : element.data('fancybox-href') || element.attr('href'),
262
title : element.data('fancybox-title') || element.attr('title'),
268
$.extend(true, obj, element.metadata());
276
href = opts.href || obj.href || (isString(element) ? element : null);
277
title = opts.title !== undefined ? opts.title : obj.title || '';
279
content = opts.content || obj.content;
280
type = content ? 'html' : (opts.type || obj.type);
282
if (!type && obj.isDom) {
283
type = element.data('fancybox-type');
286
rez = element.prop('class').match(/fancybox\.(\w+)/);
287
type = rez ? rez[1] : null;
291
if (isString(href)) {
292
// Try to guess the content type
294
if (F.isImage(href)) {
297
} else if (F.isSWF(href)) {
300
} else if (href.charAt(0) === '#') {
303
} else if (isString(element)) {
309
// Split url into two pieces with source url and content selector, e.g,
310
// "/mypage.html #my_id" will load "/mypage.html" and display element having id "my_id"
311
if (type === 'ajax') {
312
hrefParts = href.split(/\s+/, 2);
313
href = hrefParts.shift();
314
selector = hrefParts.shift();
319
if (type === 'inline') {
321
content = $( isString(href) ? href.replace(/.*(?=#[^\s]+$)/, '') : href ); //strip for ie7
323
} else if (obj.isDom) {
327
} else if (type === 'html') {
330
} else if (!type && !href && obj.isDom) {
347
// Extend the defaults
348
F.opts = $.extend(true, {}, F.defaults, opts);
350
// All options are merged recursive except keys
351
if (opts.keys !== undefined) {
352
F.opts.keys = opts.keys ? $.extend({}, F.defaults.keys, opts.keys) : false;
357
return F._start(F.opts.index);
360
// Cancel image loading or abort ajax request
361
cancel: function () {
362
var coming = F.coming;
364
if (!coming || false === F.trigger('onCancel')) {
377
F.imgPreload.onload = F.imgPreload.onerror = null;
381
coming.wrap.stop(true, true).trigger('onReset').remove();
386
// If the first item has been canceled, then clear everything
388
F._afterZoomOut( coming );
392
// Start closing animation if is open; remove immediately if opening/closing
393
close: function (event) {
396
if (false === F.trigger('beforeClose')) {
406
if (!F.isOpen || event === true) {
407
$('.fancybox-wrap').stop(true).trigger('onReset').remove();
412
F.isOpen = F.isOpened = false;
415
$('.fancybox-item, .fancybox-nav').remove();
417
F.wrap.stop(true, true).removeClass('fancybox-opened');
419
F.transitions[ F.current.closeMethod ]();
424
// $.fancybox.play(); - toggle slideshow
425
// $.fancybox.play( true ); - start
426
// $.fancybox.play( false ); - stop
427
play: function ( action ) {
428
var clear = function () {
429
clearTimeout(F.player.timer);
434
if (F.current && F.player.isActive) {
435
F.player.timer = setTimeout(F.next, F.current.playSpeed);
441
$('body').unbind('.player');
443
F.player.isActive = false;
445
F.trigger('onPlayEnd');
447
start = function () {
448
if (F.current && (F.current.loop || F.current.index < F.group.length - 1)) {
449
F.player.isActive = true;
452
'afterShow.player onUpdate.player' : set,
453
'onCancel.player beforeClose.player' : stop,
454
'beforeLoad.player' : clear
459
F.trigger('onPlayStart');
463
if (action === true || (!F.player.isActive && action !== false)) {
470
// Navigate to next gallery item
471
next: function ( direction ) {
472
var current = F.current;
475
if (!isString(direction)) {
476
direction = current.direction.next;
479
F.jumpto(current.index + 1, direction, 'next');
483
// Navigate to previous gallery item
484
prev: function ( direction ) {
485
var current = F.current;
488
if (!isString(direction)) {
489
direction = current.direction.prev;
492
F.jumpto(current.index - 1, direction, 'prev');
496
// Navigate to gallery item by index
497
jumpto: function ( index, direction, router ) {
498
var current = F.current;
504
index = getScalar(index);
506
F.direction = direction || current.direction[ (index >= current.index ? 'next' : 'prev') ];
507
F.router = router || 'jumpto';
511
index = current.group.length + (index % current.group.length);
514
index = index % current.group.length;
517
if (current.group[ index ] !== undefined) {
524
// Center inside viewport and toggle position type to fixed or absolute if needed
525
reposition: function (e, onlyAbsolute) {
526
var current = F.current,
527
wrap = current ? current.wrap : null,
531
pos = F._getPosition(onlyAbsolute);
533
if (e && e.type === 'scroll') {
536
wrap.stop(true, true).animate(pos, 200);
541
current.pos = $.extend({}, current.dim, pos);
546
update: function (e) {
547
var type = (e && e.type),
548
anyway = !type || type === 'orientationchange';
551
clearTimeout(didUpdate);
556
if (!F.isOpen || didUpdate) {
560
didUpdate = setTimeout(function() {
561
var current = F.current;
563
if (!current || F.isClosing) {
567
F.wrap.removeClass('fancybox-tmp');
569
if (anyway || type === 'load' || (type === 'resize' && current.autoResize)) {
573
if (!(type === 'scroll' && current.canShrink)) {
577
F.trigger('onUpdate');
581
}, (anyway && !isTouch ? 0 : 300));
584
// Shrink content to fit inside viewport or restore if resized
585
toggle: function ( action ) {
587
F.current.fitToView = $.type(action) === "boolean" ? action : !F.current.fitToView;
589
// Help browser to restore document dimensions
591
F.wrap.removeAttr('style').addClass('fancybox-tmp');
593
F.trigger('onUpdate');
600
hideLoading: function () {
601
D.unbind('.loading');
603
$('#fancybox-loading').remove();
606
showLoading: function () {
611
el = $('<div id="fancybox-loading"><div></div></div>').click(F.cancel).appendTo('body');
613
// If user will press the escape-button, the request will be canceled
614
D.bind('keydown.loading', function(e) {
615
if ((e.which || e.keyCode) === 27) {
622
if (!F.defaults.fixed) {
623
viewport = F.getViewport();
626
position : 'absolute',
627
top : (viewport.h * 0.5) + viewport.y,
628
left : (viewport.w * 0.5) + viewport.x
633
getViewport: function () {
634
var locked = (F.current && F.current.locked) || false,
641
rez.w = locked[0].clientWidth;
642
rez.h = locked[0].clientHeight;
645
// See http://bugs.jquery.com/ticket/6724
646
rez.w = isTouch && window.innerWidth ? window.innerWidth : W.width();
647
rez.h = isTouch && window.innerHeight ? window.innerHeight : W.height();
653
// Unbind the keyboard / clicking actions
654
unbindEvents: function () {
655
if (F.wrap && isQuery(F.wrap)) {
656
F.wrap.unbind('.fb');
663
bindEvents: function () {
664
var current = F.current,
671
// Changing document height on iOS devices triggers a 'resize' event,
672
// that can change document height... repeating infinitely
673
W.bind('orientationchange.fb' + (isTouch ? '' : ' resize.fb') + (current.autoCenter && !current.locked ? ' scroll.fb' : ''), F.update);
678
D.bind('keydown.fb', function (e) {
679
var code = e.which || e.keyCode,
680
target = e.target || e.srcElement;
682
// Skip esc key if loading, because showLoading will cancel preloading
683
if (code === 27 && F.coming) {
687
// Ignore key combinations and key events within form elements
688
if (!e.ctrlKey && !e.altKey && !e.shiftKey && !e.metaKey && !(target && (target.type || $(target).is('[contenteditable]')))) {
689
$.each(keys, function(i, val) {
690
if (current.group.length > 1 && val[ code ] !== undefined) {
691
F[ i ]( val[ code ] );
697
if ($.inArray(code, val) > -1) {
708
if ($.fn.mousewheel && current.mouseWheel) {
709
F.wrap.bind('mousewheel.fb', function (e, delta, deltaX, deltaY) {
710
var target = e.target || null,
714
while (parent.length) {
715
if (canScroll || parent.is('.fancybox-skin') || parent.is('.fancybox-wrap')) {
719
canScroll = isScrollable( parent[0] );
720
parent = $(parent).parent();
723
if (delta !== 0 && !canScroll) {
724
if (F.group.length > 1 && !current.canShrink) {
725
if (deltaY > 0 || deltaX > 0) {
726
F.prev( deltaY > 0 ? 'down' : 'left' );
728
} else if (deltaY < 0 || deltaX < 0) {
729
F.next( deltaY < 0 ? 'up' : 'right' );
739
trigger: function (event, o) {
740
var ret, obj = o || F.coming || F.current;
746
if ($.isFunction( obj[event] )) {
747
ret = obj[event].apply(obj, Array.prototype.slice.call(arguments, 1));
755
$.each(obj.helpers, function (helper, opts) {
756
if (opts && F.helpers[helper] && $.isFunction(F.helpers[helper][event])) {
757
opts = $.extend(true, {}, F.helpers[helper].defaults, opts);
759
F.helpers[helper][event](opts, obj);
764
$.event.trigger(event + '.fb');
767
isImage: function (str) {
768
return isString(str) && str.match(/(^data:image\/.*,)|(\.(jp(e|g|eg)|gif|png|bmp|webp)((\?|#).*)?$)/i);
771
isSWF: function (str) {
772
return isString(str) && str.match(/\.(swf)((\?|#).*)?$/i);
775
_start: function (index) {
783
index = getScalar( index );
784
obj = F.group[ index ] || null;
790
coming = $.extend(true, {}, F.opts, obj);
792
// Convert margin and padding properties to array - top, right, bottom, left
793
margin = coming.margin;
794
padding = coming.padding;
796
if ($.type(margin) === 'number') {
797
coming.margin = [margin, margin, margin, margin];
800
if ($.type(padding) === 'number') {
801
coming.padding = [padding, padding, padding, padding];
804
// 'modal' propery is just a shortcut
806
$.extend(true, coming, {
821
// 'autoSize' property is a shortcut, too
822
if (coming.autoSize) {
823
coming.autoWidth = coming.autoHeight = true;
826
if (coming.width === 'auto') {
827
coming.autoWidth = true;
830
if (coming.height === 'auto') {
831
coming.autoHeight = true;
835
* Add reference to the group, so it`s possible to access from callbacks, example:
836
* afterLoad : function() {
837
* this.title = 'Image ' + (this.index + 1) + ' of ' + this.group.length + (this.title ? ' - ' + this.title : '');
841
coming.group = F.group;
842
coming.index = index;
844
// Give a chance for callback or helpers to update coming item (type, title, etc)
847
if (false === F.trigger('beforeLoad')) {
859
//If we can not determine content type then drop silently or display next/prev item if looping through gallery
860
if (F.current && F.router && F.router !== 'jumpto') {
861
F.current.index = index;
863
return F[ F.router ]( F.direction );
871
if (type === 'image' || type === 'swf') {
872
coming.autoHeight = coming.autoWidth = false;
873
coming.scrolling = 'visible';
876
if (type === 'image') {
877
coming.aspectRatio = true;
880
if (type === 'iframe' && isTouch) {
881
coming.scrolling = 'scroll';
884
// Build the neccessary markup
885
coming.wrap = $(coming.tpl.wrap).addClass('fancybox-' + (isTouch ? 'mobile' : 'desktop') + ' fancybox-type-' + type + ' fancybox-tmp ' + coming.wrapCSS).appendTo( coming.parent || 'body' );
888
skin : $('.fancybox-skin', coming.wrap),
889
outer : $('.fancybox-outer', coming.wrap),
890
inner : $('.fancybox-inner', coming.wrap)
893
$.each(["Top", "Right", "Bottom", "Left"], function(i, v) {
894
coming.skin.css('padding' + v, getValue(coming.padding[ i ]));
897
F.trigger('onReady');
899
// Check before try to load; 'inline' and 'html' types need content, others - href
900
if (type === 'inline' || type === 'html') {
901
if (!coming.content || !coming.content.length) {
902
return F._error( 'content' );
906
return F._error( 'href' );
909
if (type === 'image') {
912
} else if (type === 'ajax') {
915
} else if (type === 'iframe') {
923
_error: function ( type ) {
932
content : F.coming.tpl.error
938
_loadImage: function () {
939
// Reset preload image so it is later possible to check "complete" property
940
var img = F.imgPreload = new Image();
942
img.onload = function () {
943
this.onload = this.onerror = null;
945
F.coming.width = this.width;
946
F.coming.height = this.height;
951
img.onerror = function () {
952
this.onload = this.onerror = null;
957
img.src = F.coming.href;
959
if (img.complete !== true) {
964
_loadAjax: function () {
965
var coming = F.coming;
969
F.ajaxLoad = $.ajax($.extend({}, coming.ajax, {
971
error: function (jqXHR, textStatus) {
972
if (F.coming && textStatus !== 'abort') {
973
F._error( 'ajax', jqXHR );
979
success: function (data, textStatus) {
980
if (textStatus === 'success') {
981
coming.content = data;
989
_loadIframe: function() {
990
var coming = F.coming,
991
iframe = $(coming.tpl.iframe.replace(/\{rnd\}/g, new Date().getTime()))
992
.attr('scrolling', isTouch ? 'auto' : coming.iframe.scrolling)
993
.attr('src', coming.href);
996
$(coming.wrap).bind('onReset', function () {
998
$(this).find('iframe').hide().attr('src', '//about:blank').end().empty();
1002
if (coming.iframe.preload) {
1005
iframe.one('load', function() {
1006
$(this).data('ready', 1);
1008
// iOS will lose scrolling if we resize
1010
$(this).bind('load.fb', F.update);
1013
// Without this trick:
1014
// - iframe won't scroll on iOS devices
1015
// - IE7 sometimes displays empty iframe
1016
$(this).parents('.fancybox-wrap').width('100%').removeClass('fancybox-tmp').show();
1022
coming.content = iframe.appendTo( coming.inner );
1024
if (!coming.iframe.preload) {
1029
_preloadImages: function() {
1030
var group = F.group,
1031
current = F.current,
1033
cnt = current.preload ? Math.min(current.preload, len - 1) : 0,
1037
for (i = 1; i <= cnt; i += 1) {
1038
item = group[ (current.index + i ) % len ];
1040
if (item.type === 'image' && item.href) {
1041
new Image().src = item.href;
1046
_afterLoad: function () {
1047
var coming = F.coming,
1048
previous = F.current,
1049
placeholder = 'fancybox-placeholder',
1059
if (!coming || F.isActive === false) {
1063
if (false === F.trigger('afterLoad', coming, previous)) {
1064
coming.wrap.stop(true).trigger('onReset').remove();
1072
F.trigger('beforeChange', previous);
1074
previous.wrap.stop(true).removeClass('fancybox-opened')
1075
.find('.fancybox-item, .fancybox-nav')
1082
content = coming.content;
1084
scrolling = coming.scrolling;
1087
wrap : current.wrap,
1088
skin : current.skin,
1089
outer : current.outer,
1090
inner : current.inner,
1095
href = current.href;
1101
if (current.selector) {
1102
content = $('<div>').html(content).find(current.selector);
1104
} else if (isQuery(content)) {
1105
if (!content.data(placeholder)) {
1106
content.data(placeholder, $('<div class="' + placeholder + '"></div>').insertAfter( content ).hide() );
1109
content = content.show().detach();
1111
current.wrap.bind('onReset', function () {
1112
if ($(this).find(content).length) {
1113
content.hide().replaceAll( content.data(placeholder) ).data(placeholder, false);
1120
content = current.tpl.image.replace('{href}', href);
1124
content = '<object id="fancybox-swf" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="100%" height="100%"><param name="movie" value="' + href + '"></param>';
1127
$.each(current.swf, function(name, val) {
1128
content += '<param name="' + name + '" value="' + val + '"></param>';
1129
embed += ' ' + name + '="' + val + '"';
1132
content += '<embed src="' + href + '" type="application/x-shockwave-flash" width="100%" height="100%"' + embed + '></embed></object>';
1136
if (!(isQuery(content) && content.parent().is(current.inner))) {
1137
current.inner.append( content );
1140
// Give a chance for helpers or callbacks to update elements
1141
F.trigger('beforeShow');
1143
// Set scrolling before calculating dimensions
1144
current.inner.css('overflow', scrolling === 'yes' ? 'scroll' : (scrolling === 'no' ? 'hidden' : scrolling));
1146
// Set initial dimensions and start position
1157
$('.fancybox-wrap').not( current.wrap ).stop(true).trigger('onReset').remove();
1159
} else if (previous.prevMethod) {
1160
F.transitions[ previous.prevMethod ]();
1163
F.transitions[ F.isOpened ? current.nextMethod : current.openMethod ]();
1168
_setDimension: function () {
1169
var viewport = F.getViewport(),
1176
current = F.current,
1177
width = current.width,
1178
height = current.height,
1179
minWidth = current.minWidth,
1180
minHeight = current.minHeight,
1181
maxWidth = current.maxWidth,
1182
maxHeight = current.maxHeight,
1183
scrolling = current.scrolling,
1184
scrollOut = current.scrollOutside ? current.scrollbarWidth : 0,
1185
margin = current.margin,
1186
wMargin = getScalar(margin[1] + margin[3]),
1187
hMargin = getScalar(margin[0] + margin[2]),
1204
// Reset dimensions so we could re-check actual size
1205
wrap.add(skin).add(inner).width('auto').height('auto').removeClass('fancybox-tmp');
1207
wPadding = getScalar(skin.outerWidth(true) - skin.width());
1208
hPadding = getScalar(skin.outerHeight(true) - skin.height());
1210
// Any space between content and viewport (margin, padding, border, title)
1211
wSpace = wMargin + wPadding;
1212
hSpace = hMargin + hPadding;
1214
origWidth = isPercentage(width) ? (viewport.w - wSpace) * getScalar(width) / 100 : width;
1215
origHeight = isPercentage(height) ? (viewport.h - hSpace) * getScalar(height) / 100 : height;
1217
if (current.type === 'iframe') {
1218
iframe = current.content;
1220
if (current.autoHeight && iframe.data('ready') === 1) {
1222
if (iframe[0].contentWindow.document.location) {
1223
inner.width( origWidth ).height(9999);
1225
body = iframe.contents().find('body');
1228
body.css('overflow-x', 'hidden');
1231
origHeight = body.height();
1237
} else if (current.autoWidth || current.autoHeight) {
1238
inner.addClass( 'fancybox-tmp' );
1240
// Set width or height in case we need to calculate only one dimension
1241
if (!current.autoWidth) {
1242
inner.width( origWidth );
1245
if (!current.autoHeight) {
1246
inner.height( origHeight );
1249
if (current.autoWidth) {
1250
origWidth = inner.width();
1253
if (current.autoHeight) {
1254
origHeight = inner.height();
1257
inner.removeClass( 'fancybox-tmp' );
1260
width = getScalar( origWidth );
1261
height = getScalar( origHeight );
1263
ratio = origWidth / origHeight;
1265
// Calculations for the content
1266
minWidth = getScalar(isPercentage(minWidth) ? getScalar(minWidth, 'w') - wSpace : minWidth);
1267
maxWidth = getScalar(isPercentage(maxWidth) ? getScalar(maxWidth, 'w') - wSpace : maxWidth);
1269
minHeight = getScalar(isPercentage(minHeight) ? getScalar(minHeight, 'h') - hSpace : minHeight);
1270
maxHeight = getScalar(isPercentage(maxHeight) ? getScalar(maxHeight, 'h') - hSpace : maxHeight);
1272
// These will be used to determine if wrap can fit in the viewport
1273
origMaxWidth = maxWidth;
1274
origMaxHeight = maxHeight;
1276
if (current.fitToView) {
1277
maxWidth = Math.min(viewport.w - wSpace, maxWidth);
1278
maxHeight = Math.min(viewport.h - hSpace, maxHeight);
1281
maxWidth_ = viewport.w - wMargin;
1282
maxHeight_ = viewport.h - hMargin;
1284
if (current.aspectRatio) {
1285
if (width > maxWidth) {
1287
height = getScalar(width / ratio);
1290
if (height > maxHeight) {
1292
width = getScalar(height * ratio);
1295
if (width < minWidth) {
1297
height = getScalar(width / ratio);
1300
if (height < minHeight) {
1302
width = getScalar(height * ratio);
1306
width = Math.max(minWidth, Math.min(width, maxWidth));
1308
if (current.autoHeight && current.type !== 'iframe') {
1309
inner.width( width );
1311
height = inner.height();
1314
height = Math.max(minHeight, Math.min(height, maxHeight));
1317
// Try to fit inside viewport (including the title)
1318
if (current.fitToView) {
1319
inner.width( width ).height( height );
1321
wrap.width( width + wPadding );
1323
// Real wrap dimensions
1324
width_ = wrap.width();
1325
height_ = wrap.height();
1327
if (current.aspectRatio) {
1328
while ((width_ > maxWidth_ || height_ > maxHeight_) && width > minWidth && height > minHeight) {
1333
height = Math.max(minHeight, Math.min(maxHeight, height - 10));
1334
width = getScalar(height * ratio);
1336
if (width < minWidth) {
1338
height = getScalar(width / ratio);
1341
if (width > maxWidth) {
1343
height = getScalar(width / ratio);
1346
inner.width( width ).height( height );
1348
wrap.width( width + wPadding );
1350
width_ = wrap.width();
1351
height_ = wrap.height();
1355
width = Math.max(minWidth, Math.min(width, width - (width_ - maxWidth_)));
1356
height = Math.max(minHeight, Math.min(height, height - (height_ - maxHeight_)));
1360
if (scrollOut && scrolling === 'auto' && height < origHeight && (width + wPadding + scrollOut) < maxWidth_) {
1364
inner.width( width ).height( height );
1366
wrap.width( width + wPadding );
1368
width_ = wrap.width();
1369
height_ = wrap.height();
1371
canShrink = (width_ > maxWidth_ || height_ > maxHeight_) && width > minWidth && height > minHeight;
1372
canExpand = current.aspectRatio ? (width < origMaxWidth && height < origMaxHeight && width < origWidth && height < origHeight) : ((width < origMaxWidth || height < origMaxHeight) && (width < origWidth || height < origHeight));
1376
width : getValue( width_ ),
1377
height : getValue( height_ )
1379
origWidth : origWidth,
1380
origHeight : origHeight,
1381
canShrink : canShrink,
1382
canExpand : canExpand,
1383
wPadding : wPadding,
1384
hPadding : hPadding,
1385
wrapSpace : height_ - skin.outerHeight(true),
1386
skinSpace : skin.height() - height
1389
if (!iframe && current.autoHeight && height > minHeight && height < maxHeight && !canExpand) {
1390
inner.height('auto');
1394
_getPosition: function (onlyAbsolute) {
1395
var current = F.current,
1396
viewport = F.getViewport(),
1397
margin = current.margin,
1398
width = F.wrap.width() + margin[1] + margin[3],
1399
height = F.wrap.height() + margin[0] + margin[2],
1401
position: 'absolute',
1406
if (current.autoCenter && current.fixed && !onlyAbsolute && height <= viewport.h && width <= viewport.w) {
1407
rez.position = 'fixed';
1409
} else if (!current.locked) {
1410
rez.top += viewport.y;
1411
rez.left += viewport.x;
1414
rez.top = getValue(Math.max(rez.top, rez.top + ((viewport.h - height) * current.topRatio)));
1415
rez.left = getValue(Math.max(rez.left, rez.left + ((viewport.w - width) * current.leftRatio)));
1420
_afterZoomIn: function () {
1421
var current = F.current;
1427
F.isOpen = F.isOpened = true;
1429
F.wrap.css('overflow', 'visible').addClass('fancybox-opened');
1433
// Assign a click event
1434
if ( current.closeClick || (current.nextClick && F.group.length > 1) ) {
1435
F.inner.css('cursor', 'pointer').bind('click.fb', function(e) {
1436
if (!$(e.target).is('a') && !$(e.target).parent().is('a')) {
1439
F[ current.closeClick ? 'close' : 'next' ]();
1444
// Create a close button
1445
if (current.closeBtn) {
1446
$(current.tpl.closeBtn).appendTo(F.skin).bind('click.fb', function(e) {
1453
// Create navigation arrows
1454
if (current.arrows && F.group.length > 1) {
1455
if (current.loop || current.index > 0) {
1456
$(current.tpl.prev).appendTo(F.outer).bind('click.fb', F.prev);
1459
if (current.loop || current.index < F.group.length - 1) {
1460
$(current.tpl.next).appendTo(F.outer).bind('click.fb', F.next);
1464
F.trigger('afterShow');
1466
// Stop the slideshow if this is the last item
1467
if (!current.loop && current.index === current.group.length - 1) {
1470
} else if (F.opts.autoPlay && !F.player.isActive) {
1471
F.opts.autoPlay = false;
1477
_afterZoomOut: function ( obj ) {
1478
obj = obj || F.current;
1480
$('.fancybox-wrap').trigger('onReset').remove();
1497
F.trigger('afterClose', obj);
1502
* Default transitions
1506
getOrigPosition: function () {
1507
var current = F.current,
1508
element = current.element,
1509
orig = current.orig,
1513
hPadding = current.hPadding,
1514
wPadding = current.wPadding,
1515
viewport = F.getViewport();
1517
if (!orig && current.isDom && element.is(':visible')) {
1518
orig = element.find('img:first');
1525
if (isQuery(orig)) {
1526
pos = orig.offset();
1528
if (orig.is('img')) {
1529
width = orig.outerWidth();
1530
height = orig.outerHeight();
1534
pos.top = viewport.y + (viewport.h - height) * current.topRatio;
1535
pos.left = viewport.x + (viewport.w - width) * current.leftRatio;
1538
if (F.wrap.css('position') === 'fixed' || current.locked) {
1539
pos.top -= viewport.y;
1540
pos.left -= viewport.x;
1544
top : getValue(pos.top - hPadding * current.topRatio),
1545
left : getValue(pos.left - wPadding * current.leftRatio),
1546
width : getValue(width + wPadding),
1547
height : getValue(height + hPadding)
1553
step: function (now, fx) {
1558
current = F.current,
1559
wrapSpace = current.wrapSpace,
1560
skinSpace = current.skinSpace;
1562
if (prop === 'width' || prop === 'height') {
1563
ratio = fx.end === fx.start ? 1 : (now - fx.start) / (fx.end - fx.start);
1569
padding = prop === 'width' ? current.wPadding : current.hPadding;
1570
value = now - padding;
1572
F.skin[ prop ]( getScalar( prop === 'width' ? value : value - (wrapSpace * ratio) ) );
1573
F.inner[ prop ]( getScalar( prop === 'width' ? value : value - (wrapSpace * ratio) - (skinSpace * ratio) ) );
1577
zoomIn: function () {
1578
var current = F.current,
1579
startPos = current.pos,
1580
effect = current.openEffect,
1581
elastic = effect === 'elastic',
1582
endPos = $.extend({opacity : 1}, startPos);
1584
// Remove "position" property that breaks older IE
1585
delete endPos.position;
1588
startPos = this.getOrigPosition();
1590
if (current.openOpacity) {
1591
startPos.opacity = 0.1;
1594
} else if (effect === 'fade') {
1595
startPos.opacity = 0.1;
1598
F.wrap.css(startPos).animate(endPos, {
1599
duration : effect === 'none' ? 0 : current.openSpeed,
1600
easing : current.openEasing,
1601
step : elastic ? this.step : null,
1602
complete : F._afterZoomIn
1606
zoomOut: function () {
1607
var current = F.current,
1608
effect = current.closeEffect,
1609
elastic = effect === 'elastic',
1610
endPos = {opacity : 0.1};
1613
endPos = this.getOrigPosition();
1615
if (current.closeOpacity) {
1616
endPos.opacity = 0.1;
1620
F.wrap.animate(endPos, {
1621
duration : effect === 'none' ? 0 : current.closeSpeed,
1622
easing : current.closeEasing,
1623
step : elastic ? this.step : null,
1624
complete : F._afterZoomOut
1628
changeIn: function () {
1629
var current = F.current,
1630
effect = current.nextEffect,
1631
startPos = current.pos,
1632
endPos = { opacity : 1 },
1633
direction = F.direction,
1637
startPos.opacity = 0.1;
1639
if (effect === 'elastic') {
1640
field = direction === 'down' || direction === 'up' ? 'top' : 'left';
1642
if (direction === 'down' || direction === 'right') {
1643
startPos[ field ] = getValue(getScalar(startPos[ field ]) - distance);
1644
endPos[ field ] = '+=' + distance + 'px';
1647
startPos[ field ] = getValue(getScalar(startPos[ field ]) + distance);
1648
endPos[ field ] = '-=' + distance + 'px';
1652
// Workaround for http://bugs.jquery.com/ticket/12273
1653
if (effect === 'none') {
1657
F.wrap.css(startPos).animate(endPos, {
1658
duration : current.nextSpeed,
1659
easing : current.nextEasing,
1660
complete : F._afterZoomIn
1665
changeOut: function () {
1666
var previous = F.previous,
1667
effect = previous.prevEffect,
1668
endPos = { opacity : 0.1 },
1669
direction = F.direction,
1672
if (effect === 'elastic') {
1673
endPos[ direction === 'down' || direction === 'up' ? 'top' : 'left' ] = ( direction === 'up' || direction === 'left' ? '-' : '+' ) + '=' + distance + 'px';
1676
previous.wrap.animate(endPos, {
1677
duration : effect === 'none' ? 0 : previous.prevSpeed,
1678
easing : previous.prevEasing,
1679
complete : function () {
1680
$(this).trigger('onReset').remove();
1690
F.helpers.overlay = {
1692
closeClick : true, // if true, fancyBox will be closed when user clicks on the overlay
1693
speedOut : 200, // duration of fadeOut animation
1694
showEarly : true, // indicates if should be opened immediately or wait until the content is ready
1695
css : {}, // custom CSS properties
1696
locked : !isTouch, // if true, the content will be locked into overlay
1697
fixed : true // if false, the overlay CSS position property will not be set to "fixed"
1700
overlay : null, // current handle
1701
fixed : false, // indicates if the overlay has position "fixed"
1704
create : function(opts) {
1705
opts = $.extend({}, this.defaults, opts);
1711
this.overlay = $('<div class="fancybox-overlay"></div>').appendTo( 'body' );
1714
if (opts.fixed && F.defaults.fixed) {
1715
this.overlay.addClass('fancybox-overlay-fixed');
1721
open : function(opts) {
1724
opts = $.extend({}, this.defaults, opts);
1727
this.overlay.unbind('.overlay').width('auto').height('auto');
1734
W.bind('resize.overlay', $.proxy( this.update, this) );
1739
if (opts.closeClick) {
1740
this.overlay.bind('click.overlay', function(e) {
1741
if ($(e.target).hasClass('fancybox-overlay')) {
1751
this.overlay.css( opts.css ).show();
1754
close : function() {
1755
$('.fancybox-overlay').remove();
1757
W.unbind('resize.overlay');
1759
this.overlay = null;
1761
if (this.margin !== false) {
1762
$('body').css('margin-right', this.margin);
1764
this.margin = false;
1768
this.el.removeClass('fancybox-lock');
1772
// Private, callbacks
1774
update : function () {
1775
var width = '100%', offsetWidth;
1777
// Reset width/height so it will not mess
1778
this.overlay.width(width).height('100%');
1780
// jQuery does not return reliable result for IE
1782
offsetWidth = Math.max(document.documentElement.offsetWidth, document.body.offsetWidth);
1784
if (D.width() > offsetWidth) {
1788
} else if (D.width() > W.width()) {
1792
this.overlay.width(width).height(D.height());
1795
// This is where we can manipulate DOM, because later it would cause iframes to reload
1796
onReady : function (opts, obj) {
1797
$('.fancybox-overlay').stop(true, true);
1799
if (!this.overlay) {
1800
this.margin = D.height() > W.height() || $('body').css('overflow-y') === 'scroll' ? $('body').css('margin-right') : false;
1801
this.el = document.all && !document.querySelector ? $('html') : $('body');
1806
if (opts.locked && this.fixed) {
1807
obj.locked = this.overlay.append( obj.wrap );
1811
if (opts.showEarly === true) {
1812
this.beforeShow.apply(this, arguments);
1816
beforeShow : function(opts, obj) {
1818
this.el.addClass('fancybox-lock');
1820
if (this.margin !== false) {
1821
$('body').css('margin-right', getScalar( this.margin ) + obj.scrollbarWidth);
1828
onUpdate : function() {
1834
afterClose: function (opts) {
1835
// Remove overlay if exists and fancyBox is not opening
1836
// (e.g., it is not being open using afterClose callback)
1837
if (this.overlay && !F.isActive) {
1838
this.overlay.fadeOut(opts.speedOut, $.proxy( this.close, this ));
1849
type : 'float', // 'float', 'inside', 'outside' or 'over',
1850
position : 'bottom' // 'top' or 'bottom'
1853
beforeShow: function (opts) {
1854
var current = F.current,
1855
text = current.title,
1860
if ($.isFunction(text)) {
1861
text = text.call(current.element, current);
1864
if (!isString(text) || $.trim(text) === '') {
1868
title = $('<div class="fancybox-title fancybox-title-' + type + '-wrap">' + text + '</div>');
1886
title.appendTo('body');
1889
title.width( title.width() );
1892
title.wrapInner('<span class="child"></span>');
1894
//Increase bottom margin so this title will also fit into viewport
1895
F.current.margin[2] += Math.abs( getScalar(title.css('margin-bottom')) );
1899
title[ (opts.position === 'top' ? 'prependTo' : 'appendTo') ](target);
1903
// jQuery plugin initialization
1904
$.fn.fancybox = function (options) {
1907
selector = this.selector || '',
1909
var what = $(this).blur(), idx = index, relType, relVal;
1911
if (!(e.ctrlKey || e.altKey || e.shiftKey || e.metaKey) && !what.is('.fancybox-wrap')) {
1912
relType = options.groupAttr || 'data-fancybox-group';
1913
relVal = what.attr(relType);
1917
relVal = what.get(0)[ relType ];
1920
if (relVal && relVal !== '' && relVal !== 'nofollow') {
1921
what = selector.length ? $(selector) : that;
1922
what = what.filter('[' + relType + '="' + relVal + '"]');
1923
idx = what.index(this);
1926
options.index = idx;
1928
// Stop an event from bubbling if everything is fine
1929
if (F.open(what, options) !== false) {
1935
options = options || {};
1936
index = options.index || 0;
1938
if (!selector || options.live === false) {
1939
that.unbind('click.fb-start').bind('click.fb-start', run);
1942
D.undelegate(selector, 'click.fb-start').delegate(selector + ":not('.fancybox-item, .fancybox-nav')", 'click.fb-start', run);
1945
this.filter('[data-fancybox-start=1]').trigger('click');
1950
// Tests that need a body at doc ready
1951
D.ready(function() {
1952
if ( $.scrollbarWidth === undefined ) {
1953
// http://benalman.com/projects/jquery-misc-plugins/#scrollbarwidth
1954
$.scrollbarWidth = function() {
1955
var parent = $('<div style="width:50px;height:50px;overflow:auto"><div/></div>').appendTo('body'),
1956
child = parent.children(),
1957
width = child.innerWidth() - child.height( 99 ).innerWidth();
1965
if ( $.support.fixedPosition === undefined ) {
1966
$.support.fixedPosition = (function() {
1967
var elem = $('<div style="position:fixed;top:20px;"></div>').appendTo('body'),
1968
fixed = ( elem[0].offsetTop === 20 || elem[0].offsetTop === 15 );
1976
$.extend(F.defaults, {
1977
scrollbarWidth : $.scrollbarWidth(),
1978
fixed : $.support.fixedPosition,
1983
}(window, document, jQuery));
b'\\ No newline at end of file'