2
* FancyBox - jQuery Plugin
3
* Simple and fancy lightbox alternative
5
* Examples and documentation at: http://fancybox.net
7
* Copyright (c) 2008 - 2010 Janis Skarnelis
9
* Version: 1.3.1 (05/03/2010)
10
* Requires: jQuery v1.3+
12
* Dual licensed under the MIT and GPL licenses:
13
* http://www.opensource.org/licenses/mit-license.php
14
* http://www.gnu.org/licenses/gpl.html
19
var tmp, loading, overlay, wrap, outer, inner, close, nav_left, nav_right,
21
selectedIndex = 0, selectedOpts = {}, selectedArray = [], currentIndex = 0, currentOpts = {}, currentArray = [],
23
ajaxLoader = null, imgPreloader = new Image(), imgRegExp = /\.(jpg|gif|png|bmp|jpeg)(.*)?$/i, swfRegExp = /[^\.]\.(swf)\s*$/i,
25
loadingTimer, loadingFrame = 1,
27
start_pos, final_pos, busy = false, shadow = 20, fx = $.extend($('<div/>')[0], { prop: 0 }), titleh = 0,
29
isIE6 = !$.support.opacity && !window.XMLHttpRequest,
35
fancybox_abort = function() {
38
imgPreloader.onerror = imgPreloader.onload = null;
47
fancybox_error = function() {
48
$.fancybox('<p id="fancybox_error">The requested content cannot be loaded.<br />Please try again later.</p>', {
51
'transitionIn' : 'none',
52
'transitionOut' : 'none'
56
fancybox_get_viewport = function() {
57
return [ $(window).width(), $(window).height(), $(document).scrollLeft(), $(document).scrollTop() ];
60
fancybox_get_zoom_to = function () {
61
var view = fancybox_get_viewport(),
64
margin = currentOpts.margin,
65
resize = currentOpts.autoScale,
67
horizontal_space = (shadow + margin) * 2,
68
vertical_space = (shadow + margin) * 2,
69
double_padding = (currentOpts.padding * 2),
73
if (currentOpts.width.toString().indexOf('%') > -1) {
74
to.width = ((view[0] * parseFloat(currentOpts.width)) / 100) - (shadow * 2) ;
78
to.width = currentOpts.width + double_padding;
81
if (currentOpts.height.toString().indexOf('%') > -1) {
82
to.height = ((view[1] * parseFloat(currentOpts.height)) / 100) - (shadow * 2);
86
to.height = currentOpts.height + double_padding;
89
if (resize && (to.width > (view[0] - horizontal_space) || to.height > (view[1] - vertical_space))) {
90
if (selectedOpts.type == 'image' || selectedOpts.type == 'swf') {
91
horizontal_space += double_padding;
92
vertical_space += double_padding;
94
ratio = Math.min(Math.min( view[0] - horizontal_space, currentOpts.width) / currentOpts.width, Math.min( view[1] - vertical_space, currentOpts.height) / currentOpts.height);
96
to.width = Math.round(ratio * (to.width - double_padding)) + double_padding;
97
to.height = Math.round(ratio * (to.height - double_padding)) + double_padding;
100
to.width = Math.min(to.width, (view[0] - horizontal_space));
101
to.height = Math.min(to.height, (view[1] - vertical_space));
105
to.top = view[3] + ((view[1] - (to.height + (shadow * 2 ))) * 0.5);
106
to.left = view[2] + ((view[0] - (to.width + (shadow * 2 ))) * 0.5);
108
if (currentOpts.autoScale === false) {
109
to.top = Math.max(view[3] + margin, to.top);
110
to.left = Math.max(view[2] + margin, to.left);
116
fancybox_format_title = function(title) {
117
if (title && title.length) {
118
switch (currentOpts.titlePosition) {
122
return '<span id="fancybox-title-over">' + title + '</span>';
124
return '<span id="fancybox-title-wrap"><span id="fancybox-title-left"></span><span id="fancybox-title-main">' + title + '</span><span id="fancybox-title-right"></span></span>';
131
fancybox_process_title = function() {
132
var title = currentOpts.title,
133
width = final_pos.width - (currentOpts.padding * 2),
134
titlec = 'fancybox-title-' + currentOpts.titlePosition;
136
$('#fancybox-title').remove();
140
if (currentOpts.titleShow === false) {
144
title = $.isFunction(currentOpts.titleFormat) ? currentOpts.titleFormat(title, currentArray, currentIndex, currentOpts) : fancybox_format_title(title);
146
if (!title || title === '') {
150
$('<div id="fancybox-title" class="' + titlec + '" />').css({
152
'paddingLeft' : currentOpts.padding,
153
'paddingRight' : currentOpts.padding
154
}).html(title).appendTo('body');
156
switch (currentOpts.titlePosition) {
158
titleh = $("#fancybox-title").outerHeight(true) - currentOpts.padding;
159
final_pos.height += titleh;
163
$('#fancybox-title').css('bottom', currentOpts.padding);
167
$('#fancybox-title').css('bottom', $("#fancybox-title").outerHeight(true) * -1);
171
$('#fancybox-title').appendTo( outer ).hide();
174
fancybox_preload_images = function() {
178
if ((currentArray.length -1) > currentIndex) {
179
href = currentArray[ currentIndex + 1 ].href;
181
if (typeof href !== 'undefined' && href.match(imgRegExp)) {
182
objNext = new Image();
187
if (currentIndex > 0) {
188
href = currentArray[ currentIndex - 1 ].href;
190
if (typeof href !== 'undefined' && href.match(imgRegExp)) {
191
objNext = new Image();
197
_finish = function () {
198
inner.css('overflow', (currentOpts.scrolling == 'auto' ? (currentOpts.type == 'image' || currentOpts.type == 'iframe' || currentOpts.type == 'swf' ? 'hidden' : 'auto') : (currentOpts.scrolling == 'yes' ? 'auto' : 'visible')));
200
if (!$.support.opacity) {
201
inner.get(0).style.removeAttribute('filter');
202
wrap.get(0).style.removeAttribute('filter');
205
$('#fancybox-title').show();
207
if (currentOpts.hideOnContentClick) {
208
inner.one('click', $.fancybox.close);
210
if (currentOpts.hideOnOverlayClick) {
211
overlay.one('click', $.fancybox.close);
214
if (currentOpts.showCloseButton) {
219
$(window).bind("resize.fb", $.fancybox.center);
221
if (currentOpts.centerOnScroll) {
222
$(window).bind("scroll.fb", $.fancybox.center);
224
$(window).unbind("scroll.fb");
227
if ($.isFunction(currentOpts.onComplete)) {
228
currentOpts.onComplete(currentArray, currentIndex, currentOpts);
233
fancybox_preload_images();
236
fancybox_draw = function(pos) {
237
var width = Math.round(start_pos.width + (final_pos.width - start_pos.width) * pos),
238
height = Math.round(start_pos.height + (final_pos.height - start_pos.height) * pos),
240
top = Math.round(start_pos.top + (final_pos.top - start_pos.top) * pos),
241
left = Math.round(start_pos.left + (final_pos.left - start_pos.left) * pos);
244
'width' : width + 'px',
245
'height' : height + 'px',
250
width = Math.max(width - currentOpts.padding * 2, 0);
251
height = Math.max(height - (currentOpts.padding * 2 + (titleh * pos)), 0);
254
'width' : width + 'px',
255
'height' : height + 'px'
258
if (typeof final_pos.opacity !== 'undefined') {
259
wrap.css('opacity', (pos < 0.5 ? 0.5 : pos));
263
fancybox_get_obj_pos = function(obj) {
264
var pos = obj.offset();
266
pos.top += parseFloat( obj.css('paddingTop') ) || 0;
267
pos.left += parseFloat( obj.css('paddingLeft') ) || 0;
269
pos.top += parseFloat( obj.css('border-top-width') ) || 0;
270
pos.left += parseFloat( obj.css('border-left-width') ) || 0;
272
pos.width = obj.width();
273
pos.height = obj.height();
278
fancybox_get_zoom_from = function() {
279
var orig = selectedOpts.orig ? $(selectedOpts.orig) : false,
284
if (orig && orig.length) {
285
pos = fancybox_get_obj_pos(orig);
288
width : (pos.width + (currentOpts.padding * 2)),
289
height : (pos.height + (currentOpts.padding * 2)),
290
top : (pos.top - currentOpts.padding - shadow),
291
left : (pos.left - currentOpts.padding - shadow)
295
view = fancybox_get_viewport();
300
top : view[3] + view[1] * 0.5,
301
left : view[2] + view[0] * 0.5
308
fancybox_show = function() {
311
if (wrap.is(":visible") && $.isFunction(currentOpts.onCleanup)) {
312
if (currentOpts.onCleanup(currentArray, currentIndex, currentOpts) === false) {
313
$.event.trigger('fancybox-cancel');
320
currentArray = selectedArray;
321
currentIndex = selectedIndex;
322
currentOpts = selectedOpts;
324
inner.get(0).scrollTop = 0;
325
inner.get(0).scrollLeft = 0;
327
if (currentOpts.overlayShow) {
329
$('select:not(#fancybox-tmp select)').filter(function() {
330
return this.style.visibility !== 'hidden';
331
}).css({'visibility':'hidden'}).one('fancybox-cleanup', function() {
332
this.style.visibility = 'inherit';
337
'background-color' : currentOpts.overlayColor,
338
'opacity' : currentOpts.overlayOpacity
342
final_pos = fancybox_get_zoom_to();
344
fancybox_process_title();
346
if (wrap.is(":visible")) {
347
$( close.add( nav_left ).add( nav_right ) ).hide();
349
var pos = wrap.position(),
355
width : wrap.width(),
356
height : wrap.height()
359
equal = (start_pos.width == final_pos.width && start_pos.height == final_pos.height);
361
inner.fadeOut(currentOpts.changeFade, function() {
362
var finish_resizing = function() {
363
inner.html( tmp.contents() ).fadeIn(currentOpts.changeFade, _finish);
366
$.event.trigger('fancybox-change');
368
inner.empty().css('overflow', 'hidden');
372
top : currentOpts.padding,
373
left : currentOpts.padding,
374
width : Math.max(final_pos.width - (currentOpts.padding * 2), 1),
375
height : Math.max(final_pos.height - (currentOpts.padding * 2) - titleh, 1)
382
top : currentOpts.padding,
383
left : currentOpts.padding,
384
width : Math.max(start_pos.width - (currentOpts.padding * 2), 1),
385
height : Math.max(start_pos.height - (currentOpts.padding * 2), 1)
390
$(fx).animate({ prop: 1 }, {
391
duration : currentOpts.changeSpeed,
392
easing : currentOpts.easingChange,
393
step : fancybox_draw,
394
complete : finish_resizing
402
wrap.css('opacity', 1);
404
if (currentOpts.transitionIn == 'elastic') {
405
start_pos = fancybox_get_zoom_from();
408
top : currentOpts.padding,
409
left : currentOpts.padding,
410
width : Math.max(start_pos.width - (currentOpts.padding * 2), 1),
411
height : Math.max(start_pos.height - (currentOpts.padding * 2), 1)
413
.html( tmp.contents() );
415
wrap.css(start_pos).show();
417
if (currentOpts.opacity) {
418
final_pos.opacity = 0;
423
$(fx).animate({ prop: 1 }, {
424
duration : currentOpts.speedIn,
425
easing : currentOpts.easingIn,
426
step : fancybox_draw,
432
top : currentOpts.padding,
433
left : currentOpts.padding,
434
width : Math.max(final_pos.width - (currentOpts.padding * 2), 1),
435
height : Math.max(final_pos.height - (currentOpts.padding * 2) - titleh, 1)
437
.html( tmp.contents() );
439
wrap.css( final_pos ).fadeIn( currentOpts.transitionIn == 'none' ? 0 : currentOpts.speedIn, _finish );
443
fancybox_process_inline = function() {
444
tmp.width( selectedOpts.width );
445
tmp.height( selectedOpts.height );
447
if (selectedOpts.width == 'auto') {
448
selectedOpts.width = tmp.width();
450
if (selectedOpts.height == 'auto') {
451
selectedOpts.height = tmp.height();
457
fancybox_process_image = function() {
460
selectedOpts.width = imgPreloader.width;
461
selectedOpts.height = imgPreloader.height;
464
'id' : 'fancybox-img',
465
'src' : imgPreloader.src,
466
'alt' : selectedOpts.title
472
fancybox_start = function() {
475
var obj = selectedArray[ selectedIndex ],
484
selectedOpts = $.extend({}, $.fn.fancybox.defaults, (typeof $(obj).data('fancybox') == 'undefined' ? selectedOpts : $(obj).data('fancybox')));
485
title = obj.title || $(obj).title || selectedOpts.title || '';
487
if (obj.nodeName && !selectedOpts.orig) {
488
selectedOpts.orig = $(obj).children("img:first").length ? $(obj).children("img:first") : $(obj);
491
if (title === '' && selectedOpts.orig) {
492
title = selectedOpts.orig.attr('alt');
495
if (obj.nodeName && (/^(?:javascript|#)/i).test(obj.href)) {
496
href = selectedOpts.href || null;
498
href = selectedOpts.href || obj.href || null;
501
if (selectedOpts.type) {
502
type = selectedOpts.type;
505
href = selectedOpts.content;
508
} else if (selectedOpts.content) {
512
if (href.match(imgRegExp)) {
515
} else if (href.match(swfRegExp)) {
518
} else if ($(obj).hasClass("iframe")) {
521
} else if (href.match(/#/)) {
522
obj = href.substr(href.indexOf("#"));
524
type = $(obj).length > 0 ? 'inline' : 'ajax';
532
selectedOpts.type = type;
533
selectedOpts.href = href;
534
selectedOpts.title = title;
536
if (selectedOpts.autoDimensions && selectedOpts.type !== 'iframe' && selectedOpts.type !== 'swf') {
537
selectedOpts.width = 'auto';
538
selectedOpts.height = 'auto';
541
if (selectedOpts.modal) {
542
selectedOpts.overlayShow = true;
543
selectedOpts.hideOnOverlayClick = false;
544
selectedOpts.hideOnContentClick = false;
545
selectedOpts.enableEscapeButton = false;
546
selectedOpts.showCloseButton = false;
549
if ($.isFunction(selectedOpts.onStart)) {
550
if (selectedOpts.onStart(selectedArray, selectedIndex, selectedOpts) === false) {
556
tmp.css('padding', (shadow + selectedOpts.padding + selectedOpts.margin));
558
$('.fancybox-inline-tmp').unbind('fancybox-cancel').bind('fancybox-change', function() {
559
$(this).replaceWith(inner.children());
564
tmp.html( selectedOpts.content );
565
fancybox_process_inline();
569
$('<div class="fancybox-inline-tmp" />').hide().insertBefore( $(obj) ).bind('fancybox-cleanup', function() {
570
$(this).replaceWith(inner.children());
571
}).bind('fancybox-cancel', function() {
572
$(this).replaceWith(tmp.children());
575
$(obj).appendTo(tmp);
577
fancybox_process_inline();
583
$.fancybox.showActivity();
585
imgPreloader = new Image();
587
imgPreloader.onerror = function() {
591
imgPreloader.onload = function() {
592
imgPreloader.onerror = null;
593
imgPreloader.onload = null;
594
fancybox_process_image();
597
imgPreloader.src = href;
602
str = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + selectedOpts.width + '" height="' + selectedOpts.height + '"><param name="movie" value="' + href + '"></param>';
605
$.each(selectedOpts.swf, function(name, val) {
606
str += '<param name="' + name + '" value="' + val + '"></param>';
607
emb += ' ' + name + '="' + val + '"';
610
str += '<embed src="' + href + '" type="application/x-shockwave-flash" width="' + selectedOpts.width + '" height="' + selectedOpts.height + '"' + emb + '></embed></object>';
614
fancybox_process_inline();
618
selector = href.split('#', 2);
619
data = selectedOpts.ajax.data || {};
621
if (selector.length > 1) {
624
if (typeof data == "string") {
625
data += '&selector=' + selector[1];
627
data.selector = selector[1];
632
$.fancybox.showActivity();
634
ajaxLoader = $.ajax($.extend(selectedOpts.ajax, {
637
error : fancybox_error,
638
success : function(data, textStatus, XMLHttpRequest) {
639
if (ajaxLoader.status == 200) {
641
fancybox_process_inline();
649
$('<iframe id="fancybox-frame" name="fancybox-frame' + new Date().getTime() + '" frameborder="0" hspace="0" scrolling="' + selectedOpts.scrolling + '" src="' + selectedOpts.href + '"></iframe>').appendTo(tmp);
655
fancybox_animate_loading = function() {
656
if (!loading.is(':visible')){
657
clearInterval(loadingTimer);
661
$('div', loading).css('top', (loadingFrame * -40) + 'px');
663
loadingFrame = (loadingFrame + 1) % 12;
666
fancybox_init = function() {
667
if ($("#fancybox-wrap").length) {
672
tmp = $('<div id="fancybox-tmp"></div>'),
673
loading = $('<div id="fancybox-loading"><div></div></div>'),
674
overlay = $('<div id="fancybox-overlay"></div>'),
675
wrap = $('<div id="fancybox-wrap"></div>')
678
if (!$.support.opacity) {
679
wrap.addClass('fancybox-ie');
680
loading.addClass('fancybox-ie');
683
outer = $('<div id="fancybox-outer"></div>')
684
.append('<div class="fancy-bg" id="fancy-bg-n"></div><div class="fancy-bg" id="fancy-bg-ne"></div><div class="fancy-bg" id="fancy-bg-e"></div><div class="fancy-bg" id="fancy-bg-se"></div><div class="fancy-bg" id="fancy-bg-s"></div><div class="fancy-bg" id="fancy-bg-sw"></div><div class="fancy-bg" id="fancy-bg-w"></div><div class="fancy-bg" id="fancy-bg-nw"></div>')
688
inner = $('<div id="fancybox-inner"></div>'),
689
close = $('<a id="fancybox-close"></a>'),
691
nav_left = $('<a href="javascript:;" id="fancybox-left"><span class="fancy-ico" id="fancybox-left-ico"></span></a>'),
692
nav_right = $('<a href="javascript:;" id="fancybox-right"><span class="fancy-ico" id="fancybox-right-ico"></span></a>')
695
close.click($.fancybox.close);
696
loading.click($.fancybox.cancel);
698
nav_left.click(function(e) {
703
nav_right.click(function(e) {
709
overlay.get(0).style.setExpression('height', "document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px'");
710
loading.get(0).style.setExpression('top', "(-20 + (document.documentElement.clientHeight ? document.documentElement.clientHeight/2 : document.body.clientHeight/2 ) + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop )) + 'px'");
712
outer.prepend('<iframe id="fancybox-hide-sel-frame" src="javascript:\'\';" scrolling="no" frameborder="0" ></iframe>');
720
$.fn.fancybox = function(options) {
722
.data('fancybox', $.extend({}, options, ($.metadata ? $(this).metadata() : {})))
723
.unbind('click.fb').bind('click.fb', function(e) {
737
var rel = $(this).attr('rel') || '';
739
if (!rel || rel == '' || rel === 'nofollow') {
740
selectedArray.push(this);
743
selectedArray = $("a[rel=" + rel + "], area[rel=" + rel + "]");
744
selectedIndex = selectedArray.index( this );
755
$.fancybox = function(obj) {
762
var opts = typeof arguments[1] !== 'undefined' ? arguments[1] : {};
765
selectedIndex = opts.index || 0;
767
if ($.isArray(obj)) {
768
for (var i = 0, j = obj.length; i < j; i++) {
769
if (typeof obj[i] == 'object') {
770
$(obj[i]).data('fancybox', $.extend({}, opts, obj[i]));
772
obj[i] = $({}).data('fancybox', $.extend({content : obj[i]}, opts));
776
selectedArray = jQuery.merge(selectedArray, obj);
779
if (typeof obj == 'object') {
780
$(obj).data('fancybox', $.extend({}, opts, obj));
782
obj = $({}).data('fancybox', $.extend({content : obj}, opts));
785
selectedArray.push(obj);
788
if (selectedIndex > selectedArray.length || selectedIndex < 0) {
795
$.fancybox.showActivity = function() {
796
clearInterval(loadingTimer);
799
loadingTimer = setInterval(fancybox_animate_loading, 66);
802
$.fancybox.hideActivity = function() {
806
$.fancybox.next = function() {
807
return $.fancybox.pos( currentIndex + 1);
810
$.fancybox.prev = function() {
811
return $.fancybox.pos( currentIndex - 1);
814
$.fancybox.pos = function(pos) {
819
pos = parseInt(pos, 10);
821
if (pos > -1 && currentArray.length > pos) {
826
if (currentOpts.cyclic && currentArray.length > 1 && pos < 0) {
827
selectedIndex = currentArray.length - 1;
831
if (currentOpts.cyclic && currentArray.length > 1 && pos >= currentArray.length) {
839
$.fancybox.cancel = function() {
846
$.event.trigger('fancybox-cancel');
850
if (selectedOpts && $.isFunction(selectedOpts.onCancel)) {
851
selectedOpts.onCancel(selectedArray, selectedIndex, selectedOpts);
857
// Note: within an iframe use - parent.$.fancybox.close();
858
$.fancybox.close = function() {
859
if (busy || wrap.is(':hidden')) {
865
if (currentOpts && $.isFunction(currentOpts.onCleanup)) {
866
if (currentOpts.onCleanup(currentArray, currentIndex, currentOpts) === false) {
874
$(close.add( nav_left ).add( nav_right )).hide();
876
$('#fancybox-title').remove();
878
wrap.add(inner).add(overlay).unbind();
880
$(window).unbind("resize.fb scroll.fb");
881
$(document).unbind('keydown.fb');
883
function _cleanup() {
884
overlay.fadeOut('fast');
888
$.event.trigger('fancybox-cleanup');
892
if ($.isFunction(currentOpts.onClosed)) {
893
currentOpts.onClosed(currentArray, currentIndex, currentOpts);
896
currentArray = selectedOpts = [];
897
currentIndex = selectedIndex = 0;
898
currentOpts = selectedOpts = {};
903
inner.css('overflow', 'hidden');
905
if (currentOpts.transitionOut == 'elastic') {
906
start_pos = fancybox_get_zoom_from();
908
var pos = wrap.position();
913
width : wrap.width(),
914
height : wrap.height()
917
if (currentOpts.opacity) {
918
final_pos.opacity = 1;
923
$(fx).animate({ prop: 0 }, {
924
duration : currentOpts.speedOut,
925
easing : currentOpts.easingOut,
926
step : fancybox_draw,
931
wrap.fadeOut( currentOpts.transitionOut == 'none' ? 0 : currentOpts.speedOut, _cleanup);
935
$.fancybox.resize = function() {
938
if (busy || wrap.is(':hidden')) {
944
c = inner.wrapInner("<div style='overflow:auto'></div>").children();
947
wrap.css({height: h + (currentOpts.padding * 2) + titleh});
948
inner.css({height: h});
950
c.replaceWith(c.children());
955
$.fancybox.center = function() {
958
var view = fancybox_get_viewport(),
959
margin = currentOpts.margin,
962
to.top = view[3] + ((view[1] - ((wrap.height() - titleh) + (shadow * 2 ))) * 0.5);
963
to.left = view[2] + ((view[0] - (wrap.width() + (shadow * 2 ))) * 0.5);
965
to.top = Math.max(view[3] + margin, to.top);
966
to.left = Math.max(view[2] + margin, to.left);
973
$.fn.fancybox.defaults = {
979
scrolling : 'auto', // 'auto', 'yes' or 'no'
985
autoDimensions : true,
986
centerOnScroll : false,
989
swf : { wmode: 'transparent' },
991
hideOnOverlayClick : true,
992
hideOnContentClick : false,
995
overlayOpacity : 0.3,
996
overlayColor : '#666',
999
titlePosition : 'outside', // 'outside', 'inside' or 'over'
1002
transitionIn : 'fade', // 'elastic', 'fade' or 'none'
1003
transitionOut : 'fade', // 'elastic', 'fade' or 'none'
1009
changeFade : 'fast',
1012
easingOut : 'swing',
1014
showCloseButton : true,
1015
showNavArrows : true,
1016
enableEscapeButton : true,
1025
$(document).ready(function() {