Fancybox |
;(function($) {
var tmp, loading, overlay, wrap, outer, content, close, title, nav_left, nav_right,
selectedIndex = 0, selectedOpts = {}, selectedArray = [], currentIndex = 0, currentOpts = {}, currentArray = [],
ajaxLoader = null, imgPreloader = new Image(), imgRegExp = /\.(jpg|gif|png|bmp|jpeg)(.*)?$/i, swfRegExp = /[^\.]\.(swf)\s*$/i,
loadingTimer, loadingFrame = 1,
titleHeight = 0, titleStr = '', start_pos, final_pos, busy = false, fx = $.extend($('<div/>')[0], { prop: 0 }),
isIE6 = $.browser.msie && $.browser.version < 7 && !window.XMLHttpRequest,
_abort = function() {
loading.hide();
imgPreloader.onerror = imgPreloader.onload = null;
if (ajaxLoader) {
ajaxLoader.abort();
}
tmp.empty();
},
_error = function() {
if (false === selectedOpts.onError(selectedArray, selectedIndex, selectedOpts)) {
loading.hide();
busy = false;
return;
}
selectedOpts.titleShow = false;
selectedOpts.width = 'auto';
selectedOpts.height = 'auto';
tmp.html( '<p id="fancybox-error">The requested content cannot be loaded.<br />Please try again later.</p>' );
_process_inline();
},
_start = function() {
var obj = selectedArray[ selectedIndex ],
href,
type,
title,
str,
emb,
ret;
_abort();
selectedOpts = $.extend({}, $.fn.fancybox.defaults, (typeof $(obj).data('fancybox') == 'undefined' ? selectedOpts : $(obj).data('fancybox')));
ret = selectedOpts.onStart(selectedArray, selectedIndex, selectedOpts);
if (ret === false) {
busy = false;
return;
} else if (typeof ret == 'object') {
selectedOpts = $.extend(selectedOpts, ret);
}
title = selectedOpts.title || (obj.nodeName ? $(obj).attr('title') : obj.title) || '';
if (obj.nodeName && !selectedOpts.orig) {
selectedOpts.orig = $(obj).children("img:first").length ? $(obj).children("img:first") : $(obj);
}
if (title === '' && selectedOpts.orig && selectedOpts.titleFromAlt) {
title = selectedOpts.orig.attr('alt');
}
href = selectedOpts.href || (obj.nodeName ? $(obj).attr('href') : obj.href) || null;
if ((/^(?:javascript)/i).test(href) || href == '#') {
href = null;
}
if (selectedOpts.type) {
type = selectedOpts.type;
if (!href) {
href = selectedOpts.content;
}
} else if (selectedOpts.content) {
type = 'html';
} else if (href) {
if (href.match(imgRegExp)) {
type = 'image';
} else if (href.match(swfRegExp)) {
type = 'swf';
} else if ($(obj).hasClass("iframe")) {
type = 'iframe';
} else if (href.indexOf("#") === 0) {
type = 'inline';
} else {
type = 'ajax';
}
}
if (!type) {
_error();
return;
}
if (type == 'inline') {
obj = href.substr(href.indexOf("#"));
type = $(obj).length > 0 ? 'inline' : 'ajax';
}
selectedOpts.type = type;
selectedOpts.href = href;
selectedOpts.title = title;
if (selectedOpts.autoDimensions) {
if (selectedOpts.type == 'html' || selectedOpts.type == 'inline' || selectedOpts.type == 'ajax') {
selectedOpts.width = 'auto';
selectedOpts.height = 'auto';
} else {
selectedOpts.autoDimensions = false;
}
}
if (selectedOpts.modal) {
selectedOpts.overlayShow = true;
selectedOpts.hideOnOverlayClick = false;
selectedOpts.hideOnContentClick = false;
selectedOpts.enableEscapeButton = false;
selectedOpts.showCloseButton = false;
}
selectedOpts.padding = parseInt(selectedOpts.padding, 10);
selectedOpts.margin = parseInt(selectedOpts.margin, 10);
tmp.css('padding', (selectedOpts.padding + selectedOpts.margin));
$('.fancybox-inline-tmp').unbind('fancybox-cancel').bind('fancybox-change', function() {
$(this).replaceWith(content.children());
});
switch (type) {
case 'html' :
tmp.html( selectedOpts.content );
_process_inline();
break;
case 'inline' :
if ( $(obj).parent().is('#fancybox-content') === true) {
busy = false;
return;
}
$('<div class="fancybox-inline-tmp" />')
.hide()
.insertBefore( $(obj) )
.bind('fancybox-cleanup', function() {
$(this).replaceWith(content.children());
}).bind('fancybox-cancel', function() {
$(this).replaceWith(tmp.children());
});
$(obj).appendTo(tmp);
_process_inline();
break;
case 'image':
busy = false;
$.fancybox.showActivity();
imgPreloader = new Image();
imgPreloader.onerror = function() {
_error();
};
imgPreloader.onload = function() {
busy = true;
imgPreloader.onerror = imgPreloader.onload = null;
_process_image();
};
imgPreloader.src = href;
break;
case 'swf':
selectedOpts.scrolling = 'no';
str = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + selectedOpts.width + '" height="' + selectedOpts.height + '"><param name="movie" value="' + href + '"></param>';
emb = '';
$.each(selectedOpts.swf, function(name, val) {
str += '<param name="' + name + '" value="' + val + '"></param>';
emb += ' ' + name + '="' + val + '"';
});
str += '<embed src="' + href + '" type="application/x-shockwave-flash" width="' + selectedOpts.width + '" height="' + selectedOpts.height + '"' + emb + '></embed></object>';
tmp.html(str);
_process_inline();
break;
case 'ajax':
busy = false;
$.fancybox.showActivity();
selectedOpts.ajax.win = selectedOpts.ajax.success;
ajaxLoader = $.ajax($.extend({}, selectedOpts.ajax, {
url : href,
data : selectedOpts.ajax.data || {},
error : function(XMLHttpRequest, textStatus, errorThrown) {
if ( XMLHttpRequest.status > 0 ) {
_error();
}
},
success : function(data, textStatus, XMLHttpRequest) {
var o = typeof XMLHttpRequest == 'object' ? XMLHttpRequest : ajaxLoader;
if (o.status == 200) {
if ( typeof selectedOpts.ajax.win == 'function' ) {
ret = selectedOpts.ajax.win(href, data, textStatus, XMLHttpRequest);
if (ret === false) {
loading.hide();
return;
} else if (typeof ret == 'string' || typeof ret == 'object') {
data = ret;
}
}
tmp.html( data );
_process_inline();
}
}
}));
break;
case 'iframe':
_show();
break;
}
},
_process_inline = function() {
var
w = selectedOpts.width,
h = selectedOpts.height;
if (w.toString().indexOf('%') > -1) {
w = parseInt( ($(window).width() - (selectedOpts.margin * 2)) * parseFloat(w) / 100, 10) + 'px';
} else {
w = w == 'auto' ? 'auto' : w + 'px';
}
if (h.toString().indexOf('%') > -1) {
h = parseInt( ($(window).height() - (selectedOpts.margin * 2)) * parseFloat(h) / 100, 10) + 'px';
} else {
h = h == 'auto' ? 'auto' : h + 'px';
}
tmp.wrapInner('<div style="width:' + w + ';height:' + h + ';overflow: ' + (selectedOpts.scrolling == 'auto' ? 'auto' : (selectedOpts.scrolling == 'yes' ? 'scroll' : 'hidden')) + ';position:relative;"></div>');
selectedOpts.width = tmp.width();
selectedOpts.height = tmp.height();
_show();
},
_process_image = function() {
selectedOpts.width = imgPreloader.width;
selectedOpts.height = imgPreloader.height;
$("<img />").attr({
'id' : 'fancybox-img',
'src' : imgPreloader.src,
'alt' : selectedOpts.title
}).appendTo( tmp );
_show();
},
_show = function() {
var pos, equal;
loading.hide();
if (wrap.is(":visible") && false === currentOpts.onCleanup(currentArray, currentIndex, currentOpts)) {
$.event.trigger('fancybox-cancel');
busy = false;
return;
}
busy = true;
$(content.add( overlay )).unbind();
$(window).unbind("resize.fb scroll.fb");
$(document).unbind('keydown.fb');
if (wrap.is(":visible") && currentOpts.titlePosition !== 'outside') {
wrap.css('height', wrap.height());
}
currentArray = selectedArray;
currentIndex = selectedIndex;
currentOpts = selectedOpts;
if (currentOpts.overlayShow) {
overlay.css({
'background-color' : currentOpts.overlayColor,
'opacity' : currentOpts.overlayOpacity,
'cursor' : currentOpts.hideOnOverlayClick ? 'pointer' : 'auto',
'height' : $(document).height()
});
if (!overlay.is(':visible')) {
if (isIE6) {
$('select:not(#fancybox-tmp select)').filter(function() {
return this.style.visibility !== 'hidden';
}).css({'visibility' : 'hidden'}).one('fancybox-cleanup', function() {
this.style.visibility = 'inherit';
});
}
overlay.show();
}
} else {
overlay.hide();
}
final_pos = _get_zoom_to();
_process_title();
if (wrap.is(":visible")) {
$( close.add( nav_left ).add( nav_right ) ).hide();
pos = wrap.position(),
start_pos = {
top : pos.top,
left : pos.left,
width : wrap.width(),
height : wrap.height()
};
equal = (start_pos.width == final_pos.width && start_pos.height == final_pos.height);
content.fadeTo(currentOpts.changeFade, 0.3, function() {
var finish_resizing = function() {
content.html( tmp.contents() ).fadeTo(currentOpts.changeFade, 1, _finish);
};
$.event.trigger('fancybox-change');
content
.empty()
.removeAttr('filter')
.css({
'border-width' : currentOpts.padding,
'width' : final_pos.width - currentOpts.padding * 2,
'height' : selectedOpts.autoDimensions ? 'auto' : final_pos.height - titleHeight - currentOpts.padding * 2
});
if (equal) {
finish_resizing();
} else {
fx.prop = 0;
$(fx).animate({prop: 1}, {
duration : currentOpts.changeSpeed,
easing : currentOpts.easingChange,
step : _draw,
complete : finish_resizing
});
}
});
return;
}
wrap.removeAttr("style");
content.css('border-width', currentOpts.padding);
if (currentOpts.transitionIn == 'elastic') {
start_pos = _get_zoom_from();
content.html( tmp.contents() );
wrap.show();
if (currentOpts.opacity) {
final_pos.opacity = 0;
}
fx.prop = 0;
$(fx).animate({prop: 1}, {
duration : currentOpts.speedIn,
easing : currentOpts.easingIn,
step : _draw,
complete : _finish
});
return;
}
if (currentOpts.titlePosition == 'inside' && titleHeight > 0) {
title.show();
}
content
.css({
'width' : final_pos.width - currentOpts.padding * 2,
'height' : selectedOpts.autoDimensions ? 'auto' : final_pos.height - titleHeight - currentOpts.padding * 2
})
.html( tmp.contents() );
wrap
.css(final_pos)
.fadeIn( currentOpts.transitionIn == 'none' ? 0 : currentOpts.speedIn, _finish );
},
_format_title = function(title) {
if (title && title.length) {
if (currentOpts.titlePosition == 'float') {
return '<table id="fancybox-title-float-wrap" cellpadding="0" cellspacing="0"><tr><td id="fancybox-title-float-left"></td><td id="fancybox-title-float-main">' + title + '</td><td id="fancybox-title-float-right"></td></tr></table>';
}
return '<div id="fancybox-title-' + currentOpts.titlePosition + '">' + title + '</div>';
}
return false;
},
_process_title = function() {
titleStr = currentOpts.title || '';
titleHeight = 0;
title
.empty()
.removeAttr('style')
.removeClass();
if (currentOpts.titleShow === false) {
title.hide();
return;
}
titleStr = $.isFunction(currentOpts.titleFormat) ? currentOpts.titleFormat(titleStr, currentArray, currentIndex, currentOpts) : _format_title(titleStr);
if (!titleStr || titleStr === '') {
title.hide();
return;
}
title
.addClass('fancybox-title-' + currentOpts.titlePosition)
.html( titleStr )
.appendTo( 'body' )
.show();
switch (currentOpts.titlePosition) {
case 'inside':
title
.css({
'width' : final_pos.width - (currentOpts.padding * 2),
'marginLeft' : currentOpts.padding,
'marginRight' : currentOpts.padding
});
titleHeight = title.outerHeight(true);
title.appendTo( outer );
final_pos.height += titleHeight;
break;
case 'over':
title
.css({
'marginLeft' : currentOpts.padding,
'width' : final_pos.width - (currentOpts.padding * 2),
'bottom' : currentOpts.padding
})
.appendTo( outer );
break;
case 'float':
title
.css('left', parseInt((title.width() - final_pos.width - 40)/ 2, 10) * -1)
.appendTo( wrap );
break;
default:
title
.css({
'width' : final_pos.width - (currentOpts.padding * 2),
'paddingLeft' : currentOpts.padding,
'paddingRight' : currentOpts.padding
})
.appendTo( wrap );
break;
}
title.hide();
},
_set_navigation = function() {
if (currentOpts.enableEscapeButton || currentOpts.enableKeyboardNav) {
$(document).bind('keydown.fb', function(e) {
if (e.keyCode == 27 && currentOpts.enableEscapeButton) {
e.preventDefault();
$.fancybox.close();
} else if ((e.keyCode == 37 || e.keyCode == 39) && currentOpts.enableKeyboardNav && e.target.tagName !== 'INPUT' && e.target.tagName !== 'TEXTAREA' && e.target.tagName !== 'SELECT') {
e.preventDefault();
$.fancybox[ e.keyCode == 37 ? 'prev' : 'next']();
}
});
}
if (!currentOpts.showNavArrows) {
nav_left.hide();
nav_right.hide();
return;
}
if ((currentOpts.cyclic && currentArray.length > 1) || currentIndex !== 0) {
nav_left.show();
}
if ((currentOpts.cyclic && currentArray.length > 1) || currentIndex != (currentArray.length -1)) {
nav_right.show();
}
},
_finish = function () {
if (!$.support.opacity) {
content.get(0).style.removeAttribute('filter');
wrap.get(0).style.removeAttribute('filter');
}
if (selectedOpts.autoDimensions) {
content.css('height', 'auto');
}
wrap.css('height', 'auto');
if (titleStr && titleStr.length) {
title.show();
}
if (currentOpts.showCloseButton) {
close.show();
}
_set_navigation();
if (currentOpts.hideOnContentClick) {
content.bind('click', $.fancybox.close);
}
if (currentOpts.hideOnOverlayClick) {
overlay.bind('click', $.fancybox.close);
}
$(window).bind("resize.fb", $.fancybox.resize);
if (currentOpts.centerOnScroll) {
$(window).bind("scroll.fb", $.fancybox.center);
}
if (currentOpts.type == 'iframe') {
$('<iframe id="fancybox-frame" name="fancybox-frame' + new Date().getTime() + '" frameborder="0" hspace="0" ' + ($.browser.msie ? 'allowtransparency="true""' : '') + ' scrolling="' + selectedOpts.scrolling + '" src="' + currentOpts.href + '"></iframe>').appendTo(content);
}
wrap.show();
busy = false;
$.fancybox.center();
currentOpts.onComplete(currentArray, currentIndex, currentOpts);
_preload_images();
},
_preload_images = function() {
var href,
objNext;
if ((currentArray.length -1) > currentIndex) {
href = currentArray[ currentIndex + 1 ].href;
if (typeof href !== 'undefined' && href.match(imgRegExp)) {
objNext = new Image();
objNext.src = href;
}
}
if (currentIndex > 0) {
href = currentArray[ currentIndex - 1 ].href;
if (typeof href !== 'undefined' && href.match(imgRegExp)) {
objNext = new Image();
objNext.src = href;
}
}
},
_draw = function(pos) {
var dim = {
width : parseInt(start_pos.width + (final_pos.width - start_pos.width) * pos, 10),
height : parseInt(start_pos.height + (final_pos.height - start_pos.height) * pos, 10),
top : parseInt(start_pos.top + (final_pos.top - start_pos.top) * pos, 10),
left : parseInt(start_pos.left + (final_pos.left - start_pos.left) * pos, 10)
};
if (typeof final_pos.opacity !== 'undefined') {
dim.opacity = pos < 0.5 ? 0.5 : pos;
}
wrap.css(dim);
content.css({
'width' : dim.width - currentOpts.padding * 2,
'height' : dim.height - (titleHeight * pos) - currentOpts.padding * 2
});
},
_get_viewport = function() {
return [
$(window).width() - (currentOpts.margin * 2),
$(window).height() - (currentOpts.margin * 2),
$(document).scrollLeft() + currentOpts.margin,
$(document).scrollTop() + currentOpts.margin
];
},
_get_zoom_to = function () {
var view = _get_viewport(),
to = {},
resize = currentOpts.autoScale,
double_padding = currentOpts.padding * 2,
ratio;
if (currentOpts.width.toString().indexOf('%') > -1) {
to.width = parseInt((view[0] * parseFloat(currentOpts.width)) / 100, 10);
} else {
to.width = currentOpts.width + double_padding;
}
if (currentOpts.height.toString().indexOf('%') > -1) {
to.height = parseInt((view[1] * parseFloat(currentOpts.height)) / 100, 10);
} else {
to.height = currentOpts.height + double_padding;
}
if (resize && (to.width > view[0] || to.height > view[1])) {
if (selectedOpts.type == 'image' || selectedOpts.type == 'swf') {
ratio = (currentOpts.width ) / (currentOpts.height );
if ((to.width ) > view[0]) {
to.width = view[0];
to.height = parseInt(((to.width - double_padding) / ratio) + double_padding, 10);
}
if ((to.height) > view[1]) {
to.height = view[1];
to.width = parseInt(((to.height - double_padding) * ratio) + double_padding, 10);
}
} else {
to.width = Math.min(to.width, view[0]);
to.height = Math.min(to.height, view[1]);
}
}
to.top = parseInt(Math.max(view[3] - 20, view[3] + ((view[1] - to.height - 40) * 0.5)), 10);
to.left = parseInt(Math.max(view[2] - 20, view[2] + ((view[0] - to.width - 40) * 0.5)), 10);
return to;
},
_get_obj_pos = function(obj) {
var pos = obj.offset();
pos.top += parseInt( obj.css('paddingTop'), 10 ) || 0;
pos.left += parseInt( obj.css('paddingLeft'), 10 ) || 0;
pos.top += parseInt( obj.css('border-top-width'), 10 ) || 0;
pos.left += parseInt( obj.css('border-left-width'), 10 ) || 0;
pos.width = obj.width();
pos.height = obj.height();
return pos;
},
_get_zoom_from = function() {
var orig = selectedOpts.orig ? $(selectedOpts.orig) : false,
from = {},
pos,
view;
if (orig && orig.length) {
pos = _get_obj_pos(orig);
from = {
width : pos.width + (currentOpts.padding * 2),
height : pos.height + (currentOpts.padding * 2),
top : pos.top - currentOpts.padding - 20,
left : pos.left - currentOpts.padding - 20
};
} else {
view = _get_viewport();
from = {
width : currentOpts.padding * 2,
height : currentOpts.padding * 2,
top : parseInt(view[3] + view[1] * 0.5, 10),
left : parseInt(view[2] + view[0] * 0.5, 10)
};
}
return from;
},
_animate_loading = function() {
if (!loading.is(':visible')){
clearInterval(loadingTimer);
return;
}
$('div', loading).css('top', (loadingFrame * -40) + 'px');
loadingFrame = (loadingFrame + 1) % 12;
};
$.fn.fancybox = function(options) {
if (!$(this).length) {
return this;
}
$(this)
.data('fancybox', $.extend({}, options, ($.metadata ? $(this).metadata() : {})))
.unbind('click.fb')
.bind('click.fb', function(e) {
e.preventDefault();
if (busy) {
return;
}
busy = true;
$(this).blur();
selectedArray = [];
selectedIndex = 0;
var rel = $(this).attr('rel') || '';
if (!rel || rel == '' || rel === 'nofollow') {
selectedArray.push(this);
} else {
selectedArray = $("a[rel=" + rel + "], area[rel=" + rel + "]");
selectedIndex = selectedArray.index( this );
}
_start();
return;
});
return this;
};
$.fancybox = function(obj) {
var opts;
if (busy) {
return;
}
busy = true;
opts = typeof arguments[1] !== 'undefined' ? arguments[1] : {};
selectedArray = [];
selectedIndex = parseInt(opts.index, 10) || 0;
if ($.isArray(obj)) {
for (var i = 0, j = obj.length; i < j; i++) {
if (typeof obj[i] == 'object') {
$(obj[i]).data('fancybox', $.extend({}, opts, obj[i]));
} else {
obj[i] = $({}).data('fancybox', $.extend({content : obj[i]}, opts));
}
}
selectedArray = jQuery.merge(selectedArray, obj);
} else {
if (typeof obj == 'object') {
$(obj).data('fancybox', $.extend({}, opts, obj));
} else {
obj = $({}).data('fancybox', $.extend({content : obj}, opts));
}
selectedArray.push(obj);
}
if (selectedIndex > selectedArray.length || selectedIndex < 0) {
selectedIndex = 0;
}
_start();
};
$.fancybox.showActivity = function() {
clearInterval(loadingTimer);
loading.show();
loadingTimer = setInterval(_animate_loading, 66);
};
$.fancybox.hideActivity = function() {
loading.hide();
};
$.fancybox.next = function() {
return $.fancybox.pos( currentIndex + 1);
};
$.fancybox.prev = function() {
return $.fancybox.pos( currentIndex - 1);
};
$.fancybox.pos = function(pos) {
if (busy) {
return;
}
pos = parseInt(pos);
selectedArray = currentArray;
if (pos > -1 && pos < currentArray.length) {
selectedIndex = pos;
_start();
} else if (currentOpts.cyclic && currentArray.length > 1) {
selectedIndex = pos >= currentArray.length ? 0 : currentArray.length - 1;
_start();
}
return;
};
$.fancybox.cancel = function() {
if (busy) {
return;
}
busy = true;
$.event.trigger('fancybox-cancel');
_abort();
selectedOpts.onCancel(selectedArray, selectedIndex, selectedOpts);
busy = false;
};
$.fancybox.close = function() {
if (busy || wrap.is(':hidden')) {
return;
}
busy = true;
if (currentOpts && false === currentOpts.onCleanup(currentArray, currentIndex, currentOpts)) {
busy = false;
return;
}
_abort();
$(close.add( nav_left ).add( nav_right )).hide();
$(content.add( overlay )).unbind();
$(window).unbind("resize.fb scroll.fb");
$(document).unbind('keydown.fb');
content.find('iframe').attr('src', isIE6 && /^https/i.test(window.location.href || '') ? 'javascript:void(false)' : 'about:blank');
if (currentOpts.titlePosition !== 'inside') {
title.empty();
}
wrap.stop();
function _cleanup() {
overlay.fadeOut('fast');
title.empty().hide();
wrap.hide();
$.event.trigger('fancybox-cleanup');
content.empty();
currentOpts.onClosed(currentArray, currentIndex, currentOpts);
currentArray = selectedOpts = [];
currentIndex = selectedIndex = 0;
currentOpts = selectedOpts = {};
busy = false;
}
if (currentOpts.transitionOut == 'elastic') {
start_pos = _get_zoom_from();
var pos = wrap.position();
final_pos = {
top : pos.top ,
left : pos.left,
width : wrap.width(),
height : wrap.height()
};
if (currentOpts.opacity) {
final_pos.opacity = 1;
}
title.empty().hide();
fx.prop = 1;
$(fx).animate({ prop: 0 }, {
duration : currentOpts.speedOut,
easing : currentOpts.easingOut,
step : _draw,
complete : _cleanup
});
} else {
wrap.fadeOut( currentOpts.transitionOut == 'none' ? 0 : currentOpts.speedOut, _cleanup);
}
};
$.fancybox.resize = function() {
if (overlay.is(':visible')) {
overlay.css('height', $(document).height());
}
$.fancybox.center(true);
};
$.fancybox.center = function() {
var view, align;
if (busy) {
return;
}
align = arguments[0] === true ? 1 : 0;
view = _get_viewport();
if (!align && (wrap.width() > view[0] || wrap.height() > view[1])) {
return;
}
wrap
.stop()
.animate({
'top' : parseInt(Math.max(view[3] - 20, view[3] + ((view[1] - content.height() - 40) * 0.5) - currentOpts.padding)),
'left' : parseInt(Math.max(view[2] - 20, view[2] + ((view[0] - content.width() - 40) * 0.5) - currentOpts.padding))
}, typeof arguments[0] == 'number' ? arguments[0] : 200);
};
$.fancybox.init = function() {
if ($("#fancybox-wrap").length) {
return;
}
$('body').append(
tmp = $('<div id="fancybox-tmp"></div>'),
loading = $('<div id="fancybox-loading"><div></div></div>'),
overlay = $('<div id="fancybox-overlay"></div>'),
wrap = $('<div id="fancybox-wrap"></div>')
);
outer = $('<div id="fancybox-outer"></div>')
.append('<div class="fancybox-bg" id="fancybox-bg-n"></div><div class="fancybox-bg" id="fancybox-bg-ne"></div><div class="fancybox-bg" id="fancybox-bg-e"></div><div class="fancybox-bg" id="fancybox-bg-se"></div><div class="fancybox-bg" id="fancybox-bg-s"></div><div class="fancybox-bg" id="fancybox-bg-sw"></div><div class="fancybox-bg" id="fancybox-bg-w"></div><div class="fancybox-bg" id="fancybox-bg-nw"></div>')
.appendTo( wrap );
outer.append(
content = $('<div id="fancybox-content"></div>'),
close = $('<a id="fancybox-close"></a>'),
title = $('<div id="fancybox-title"></div>'),
nav_left = $('<a href="javascript:;" id="fancybox-left"><span class="fancy-ico" id="fancybox-left-ico"></span></a>'),
nav_right = $('<a href="javascript:;" id="fancybox-right"><span class="fancy-ico" id="fancybox-right-ico"></span></a>')
);
close.click($.fancybox.close);
loading.click($.fancybox.cancel);
nav_left.click(function(e) {
e.preventDefault();
$.fancybox.prev();
});
nav_right.click(function(e) {
e.preventDefault();
$.fancybox.next();
});
if ($.fn.mousewheel) {
wrap.bind('mousewheel.fb', function(e, delta) {
if (busy) {
e.preventDefault();
} else if ($(e.target).get(0).clientHeight == 0 || $(e.target).get(0).scrollHeight === $(e.target).get(0).clientHeight) {
e.preventDefault();
$.fancybox[ delta > 0 ? 'prev' : 'next']();
}
});
}
if (!$.support.opacity) {
wrap.addClass('fancybox-ie');
}
if (isIE6) {
loading.addClass('fancybox-ie6');
wrap.addClass('fancybox-ie6');
$('<iframe id="fancybox-hide-sel-frame" src="' + (/^https/i.test(window.location.href || '') ? 'javascript:void(false)' : 'about:blank' ) + '" scrolling="no" border="0" frameborder="0" tabindex="-1"></iframe>').prependTo(outer);
}
};
$.fn.fancybox.defaults = {
padding : 10,
margin : 40,
opacity : false,
modal : false,
cyclic : false,
scrolling : 'auto',
width : 560,
height : 340,
autoScale : true,
autoDimensions : true,
centerOnScroll : false,
ajax : {},
swf : { wmode: 'transparent' },
hideOnOverlayClick : true,
hideOnContentClick : false,
overlayShow : true,
overlayOpacity : 0.7,
overlayColor : '#777',
titleShow : true,
titlePosition : 'float',
titleFormat : null,
titleFromAlt : false,
transitionIn : 'fade',
transitionOut : 'fade',
speedIn : 300,
speedOut : 300,
changeSpeed : 300,
changeFade : 'fast',
easingIn : 'swing',
easingOut : 'swing',
showCloseButton : true,
showNavArrows : true,
enableEscapeButton : true,
enableKeyboardNav : true,
onStart : function(){},
onCancel : function(){},
onComplete : function(){},
onCleanup : function(){},
onClosed : function(){},
onError : function(){}
};
$(document).ready(function() {
$.fancybox.init();
});
})(jQuery);
| ready |
Fancybox2 |
(function (window, document, $) {
var W = $(window),
D = $(document),
F = $.fancybox = function () {
F.open.apply( this, arguments );
},
didResize = false,
resizeTimer = null;
$.extend(F, {
version: '2.0',
defaults: {
padding: 15,
margin: 20,
width: 800,
height: 600,
minWidth: 200,
minHeight: 200,
maxWidth: 9999,
maxHeight: 9999,
autoSize: true,
fitToView: true,
aspectRatio: false,
topRatio: 0.5,
fixed: (!$.browser.msie || $.browser.version > 6) && $.support.boxModel,
scrolling: 'auto',
wrapCSS: 'fancybox-default',
arrows: true,
closeBtn: true,
closeClick: true,
mouseWheel: true,
autoPlay: false,
playSpeed: 3000,
loop: true,
ajax: {},
keys: {
next: [13, 32, 34, 39, 40],
prev: [8, 33, 37, 38],
close: [27]
},
index: 0,
type: null,
url: null,
content: null,
title: null,
tpl: {
wrap: '<div class="fancybox-wrap"><div class="fancybox-outer"><div class="fancybox-inner"></div></div></div>',
image: '<img class="fancybox-image" src="{url}" alt="" />',
iframe: '<iframe class="fancybox-iframe" name="fancybox-frame{rnd}" frameborder="0" hspace="0" ' + ($.browser.msie ? 'allowtransparency="true""' : '') + ' scrolling="{scrolling}" src="{url}"></iframe>',
swf: '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="100%" height="100%"><param name="wmode" value="transparent" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="{url}" /><embed src="{url}" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="100%" height="100%" wmode="transparent"></embed></object>',
error: '<p class="fancybox-error">The requested content cannot be loaded.<br/>Please try again later.</p>',
closeBtn: '<div title="Close" class="fancybox-item fancybox-close"></div>',
next: '<a title="Next" class="fancybox-item fancybox-next"><span></span></a>',
prev: '<a title="Previous" class="fancybox-item fancybox-prev"><span></span></a>'
},
openEffect: 'fade',
openSpeed: 500,
openEasing: 'swing',
openOpacity: true,
openMethod: 'zoomIn',
closeEffect: 'fade',
closeSpeed: 500,
closeEasing: 'swing',
closeOpacity: true,
closeMethod: 'zoomOut',
nextEffect: 'elastic',
nextSpeed: 300,
nextEasing: 'swing',
nextMethod: 'changeIn',
prevEffect: 'elastic',
prevSpeed: 300,
prevEasing: 'swing',
prevMethod: 'changeOut',
helpers: {
overlay: {
speedIn: 0,
speedOut: 0,
opacity: 0.85,
css: {
cursor: 'pointer',
'background-color': 'rgba(0, 0, 0, 0.85)'
},
closeClick: true
},
title: {
type: 'float'
}
},
onCancel: $.noop,
beforeLoad: $.noop,
afterLoad: $.noop,
beforeShow: $.noop,
afterShow: $.noop,
beforeClose: $.noop,
afterClose: $.noop
},
group: {},
opts: {},
coming: null,
current: null,
isOpen: false,
isOpened: false,
wrap: null,
outer: null,
inner: null,
player: {
timer: null,
isActive: false
},
ajaxLoad: null,
imgPreload: null,
transitions: {},
helpers: {},
open: function (group, opts) {
if (!$.isArray(group)) {
group = [group];
}
if (!group.length) {
return;
}
F.close(true);
F.opts = $.extend(true, {}, F.defaults, opts);
F.group = group;
F._start(F.opts.index || 0);
},
cancel: function () {
if (F.coming && false === F.trigger('onCancel')) {
return;
}
F.coming = null;
F.hideLoading();
if (F.ajaxLoad) {
F.ajaxLoad.abort();
}
F.ajaxLoad = null;
if (F.imgPreload) {
F.imgPreload.onload = F.imgPreload.onabort = F.imgPreload.onerror = null;
}
},
close: function (a) {
F.cancel();
if (!F.current || false === F.trigger('beforeClose')) {
return;
}
if (!F.isOpen || (a && a[0] === true)) {
$(".fancybox-wrap").stop().trigger('onReset').remove();
F._afterZoomOut();
} else {
F.isOpen = F.isOpened = false;
$(".fancybox-item").remove();
F.wrap.stop(true).removeClass('fancybox-opened');
F.inner.css('overflow', 'hidden');
F.transitions[F.current.closeMethod]();
}
},
play: function (a) {
var clear = function () {
clearTimeout(F.player.timer);
},
set = function () {
clear();
if (F.current && F.player.isActive) {
F.player.timer = setTimeout(F.next, F.current.playSpeed);
}
},
stop = function () {
clear();
D.unbind('.player');
F.player.isActive = false;
F.trigger('onPlayEnd');
},
start = function () {
if (F.current && (F.current.loop || F.current.index < F.group.length - 1)) {
F.player.isActive = true;
set();
D.bind({
'onCancel.player onComplete.player onUpdate.player': set,
'onClose.player': stop,
'onStart.player': clear
});
F.trigger('onPlayStart');
}
};
if (F.player.isActive || (a && a[0] === false)) {
stop();
} else {
start();
}
},
next: function () {
F.current && F.jumpto(F.current.index + 1);
},
prev: function () {
F.current && F.jumpto(F.current.index - 1);
},
jumpto: function (index) {
if (!F.current) {
return;
}
index = parseInt(index, 10);
if (F.group.length > 1 && F.current.loop) {
if (index >= F.group.length) {
index = 0;
} else if (index < 0) {
index = F.group.length - 1;
}
}
if (typeof F.group[index] !== 'undefined') {
F.cancel();
F._start(index);
}
},
reposition: function (a) {
if (F.isOpen) {
F.wrap.css(F._getPosition(a));
}
},
update: function () {
if (F.isOpen) {
if (!didResize) {
resizeTimer = setInterval(function () {
if (didResize) {
didResize = false;
clearTimeout(resizeTimer);
if (F.current) {
if (F.current.autoSize) {
F.inner.height('auto');
F.current.height = F.inner.height();
}
F._setDimension();
if (F.current.canGrow) {
F.inner.height('auto');
}
F.reposition();
F.trigger('onUpdate');
}
}
}, 100);
}
didResize = true;
}
},
toggle: function () {
if (F.isOpen) {
F.current.fitToView = !F.current.fitToView;
F.update();
}
},
hideLoading: function () {
$("#fancybox-loading").remove();
},
showLoading: function () {
F.hideLoading();
$('<div id="fancybox-loading"></div>').click(F.cancel).appendTo('body');
},
getViewport: function () {
return {
x: W.scrollLeft(),
y: W.scrollTop(),
w: W.width(),
h: W.height()
};
},
unbindEvents: function () {
D.unbind('.fb');
W.unbind('.fb');
},
bindEvents: function () {
var current = F.current,
keys = current.keys;
if (!current) {
return;
}
W.bind('resize.fb, orientationchange.fb', F.update);
if (keys) {
D.bind('keydown.fb', function (e) {
if ($.inArray(e.target.tagName.toLowerCase, ['input', 'textarea', 'select', 'button']) > -1) {
return;
}
if ($.inArray(e.keyCode, keys.close) > -1) {
F.close();
e.preventDefault();
} else if ($.inArray(e.keyCode, keys.next) > -1) {
F.next();
e.preventDefault();
} else if ($.inArray(e.keyCode, keys.prev) > -1) {
F.prev();
e.preventDefault();
}
});
}
if ($.fn.mousewheel && current.mouseWheel && F.group.length > 1) {
F.wrap.bind('mousewheel.fb', function (e, delta) {
if ($(e.target).get(0).clientHeight === 0 || $(e.target).get(0).scrollHeight === $(e.target).get(0).clientHeight) {
e.preventDefault();
F[delta > 0 ? 'prev' : 'next']();
}
});
}
},
trigger: function (event) {
var ret, obj = event === 'onCancel' || event === 'beforeLoad' ? 'coming' : 'current';
if (!F[obj]) {
return;
}
if ($.isFunction(F[obj][event])) {
ret = F[obj][event].apply(F[obj], Array.prototype.slice.call(arguments, 1));
}
if (ret === false) {
return false;
}
if (F[obj].helpers) {
$.each(F[obj].helpers, function (helper, opts) {
if (opts && typeof F.helpers[helper] !== 'undefined' && $.isFunction(F.helpers[helper][event])) {
F.helpers[helper][event](opts);
}
});
}
$.event.trigger(event + '.fb');
},
isImage: function (str) {
return str && str.match(/\.(jpg|gif|png|bmp|jpeg)(.*)?$/i);
},
isSWF: function (str) {
return str && str.match(/\.(swf)(.*)?$/i);
},
_start: function (index) {
var element = F.group[index] || null,
coming = $.extend(true, {}, F.opts, (element && $.metadata ? $(element).metadata() : {})),
isDom = false,
rez = false,
url, type;
coming.index = index;
coming.element = element;
if (typeof coming.margin === 'number') {
coming.margin = [coming.margin, coming.margin, coming.margin, coming.margin];
}
F.coming = coming;
if (false === F.trigger('beforeLoad')) {
F.coming = null;
return;
} else {
coming = F.coming;
type = coming.type;
}
if (coming.content) {
element = coming.content;
}
if (!type) {
url = coming.url;
if (typeof element === 'object') {
isDom = (element.nodeType || element instanceof $);
url = $(element).attr('href') || null;
} else {
url = element;
}
if (url) {
if (isDom) {
rez = $(element).data('fancybox-type');
if (!rez && element.className) {
rez = element.className.match(/fancybox\.(\w+)/);
rez = rez ? rez[1] : false;
}
}
if (rez) {
type = rez;
} else if (F.isImage(url)) {
type = 'image';
} else if (F.isSWF(url)) {
type = 'swf';
} else if (url.match(/^#/)) {
type = 'inline';
} else {
coming.content = url;
}
if (type === 'inline') {
coming.content = $(url);
}
}
if (!type) {
if (isDom) {
type = 'inline';
coming.content = element;
} else if (coming.content) {
type = 'html';
}
}
coming.type = type;
coming.url = url;
}
F.coming = coming;
if (type === 'image') {
F._loadImage();
} else if (type === 'ajax') {
F._loadAjax();
} else if (type) {
F._afterLoad();
} else {
return F._error();
}
},
_error: function () {
F.coming.type = 'html';
F.coming.minHeight = 0;
F.coming.autoSize = true;
F.coming.content = F.coming.tpl.error;
F._afterLoad();
},
_loadImage: function () {
F.imgPreload = new Image();
F.imgPreload.onload = function () {
this.onload = this.onerror = null;
F.coming.width = this.width;
F.coming.height = this.height;
F._afterLoad();
};
F.imgPreload.onerror = function () {
this.onload = this.onerror = null;
F._error();
};
F.imgPreload.src = F.coming.url;
if (!F.imgPreload.complete) {
F.showLoading();
}
},
_loadAjax: function () {
F.showLoading();
F.ajaxLoad = $.ajax($.extend({}, F.coming.ajax, {
url: F.coming.url,
error: function (jqXHR, textStatus, errorThrown) {
if (textStatus !== 'abort' && jqXHR.status > 0) {
F.coming.content = errorThrown;
F._error();
} else {
F.hideLoading();
}
},
success: function (data, textStatus, jqXHR) {
if (textStatus === 'success') {
F.coming.content = data;
F._afterLoad();
}
}
}));
},
_afterLoad: function () {
F.hideLoading();
if (F.current && false === F.trigger('afterLoad')) {
F.coming = false;
return;
}
if (F.isOpened) {
$(".fancybox-item").remove();
F.wrap.stop(true).removeClass('fancybox-opened');
F.transitions[F.current.prevMethod]();
} else {
$(".fancybox-wrap").stop().trigger('onReset').remove();
}
F.isOpen = false;
F.current = F.coming;
F.coming = false;
F.wrap = $(F.current.tpl.wrap).addClass(F.current.wrapCSS).appendTo('body');
F.outer = $('.fancybox-outer', F.wrap).css('padding', F.current.padding + 'px');
F.inner = $('.fancybox-inner', F.wrap);
F._setContent();
F.unbindEvents();
F.bindEvents();
F.trigger('beforeShow');
F._setDimension();
if (F.isOpened) {
F.transitions[F.current.nextMethod]();
} else {
F.transitions[F.current.openMethod]();
}
},
_setContent: function () {
var content, loadingBay, current = F.current,
type = current.type;
switch (type) {
case 'inline':
case 'ajax':
case 'html':
if (type === 'inline') {
content = current.content.show().detach();
if (content.parent().hasClass('fancybox-inner')) {
content.parents('.fancybox-wrap').trigger('onReset').remove();
}
$(F.wrap).bind('onReset', function () {
content.appendTo('body').hide();
});
} else {
content = current.content;
}
if (current.autoSize) {
loadingBay = $('<div class="fancybox-tmp"></div>').appendTo($("body")).append(content);
current.width = loadingBay.outerWidth();
current.height = loadingBay.outerHeight(true);
content = loadingBay.children().detach();
loadingBay.remove();
}
break;
case 'image':
content = current.tpl.image.replace('{url}', current.url);
current.aspectRatio = true;
break;
case 'swf':
content = current.tpl.swf.replace(/\{width\}/g, current.width).replace(/\{height\}/g, current.height).replace(/\{url\}/g, current.url);
break;
case 'iframe':
content = current.tpl.iframe.replace('{url}', current.url).replace('{scrolling}', current.scrolling).replace('{rnd}', new Date().getTime());
break;
}
if ($.inArray(type, ['image', 'swf', 'iframe']) > -1) {
current.autoSize = false;
current.scrolling = false;
}
F.current = current;
F.inner.append(content);
},
_setDimension: function () {
var viewport = F.getViewport(),
margin = F.current.margin,
padding2 = F.current.padding * 2,
width = F.current.width + padding2,
height = F.current.height + padding2,
ratio = F.current.width / F.current.height,
maxWidth = F.current.maxWidth,
maxHeight = F.current.maxHeight,
minWidth = F.current.minWidth,
minHeight = F.current.minHeight,
height_;
viewport.w -= (margin[1] + margin[3]);
viewport.h -= (margin[0] + margin[2]);
if (width.toString().indexOf('%') > -1) {
width = ((viewport.w * parseFloat(width)) / 100);
}
if (height.toString().indexOf('%') > -1) {
height = ((viewport.h * parseFloat(height)) / 100);
}
if (F.current.fitToView) {
maxWidth = Math.min(viewport.w, maxWidth);
maxHeight = Math.min(viewport.h, maxHeight);
}
maxWidth = Math.max(minWidth, maxWidth);
maxHeight = Math.max(minHeight, maxHeight);
if (F.current.aspectRatio) {
if (width > maxWidth) {
width = maxWidth;
height = ((width - padding2) / ratio) + padding2;
}
if (height > maxHeight) {
height = maxHeight;
width = ((height - padding2) * ratio) + padding2;
}
if (width < minWidth) {
width = minWidth;
height = ((width - padding2) / ratio) + padding2;
}
if (height < minHeight) {
height = minHeight;
width = ((height - padding2) * ratio) + padding2;
}
} else {
width = Math.max(minWidth, Math.min(width, maxWidth));
height = Math.max(minHeight, Math.min(height, maxHeight));
}
width = Math.round(width);
height = Math.round(height);
$(F.wrap.add(F.outer).add(F.inner)).width('auto').height('auto');
F.inner.width(width - padding2).height(height - padding2);
F.wrap.width(width);
height_ = F.wrap.height();
if (width > maxWidth || height_ > maxHeight) {
while ((width > maxWidth || height_ > maxHeight) && width > minWidth && height_ > minHeight) {
height = height - 10;
if (F.current.aspectRatio) {
width = Math.round(((height - padding2) * ratio) + padding2);
if (width < minWidth) {
width = minWidth;
height = ((width - padding2) / ratio) + padding2;
}
} else {
width = width - 10;
}
F.inner.width(width - padding2).height(height - padding2);
F.wrap.width(width);
height_ = F.wrap.height();
}
}
F.current.dim = {
width: width,
height: height_
};
F.current.canGrow = F.current.autoSize && height > minHeight && height < maxHeight;
F.current.canShrink = false;
F.current.canExpand = false;
if ((width - padding2) < F.current.width || (height - padding2) < F.current.height) {
F.current.canExpand = true;
} else if ((width > viewport.w || height_ > viewport.h) && width > minWidth && height > minHeight) {
F.current.canShrink = true;
}
},
_getPosition: function (a) {
var viewport = F.getViewport(),
margin = F.current.margin,
width = F.wrap.width() + margin[1] + margin[3],
height = F.wrap.height() + margin[0] + margin[2],
rez = {
position: 'absolute',
top: margin[0] + viewport.y,
left: margin[3] + viewport.x
};
if (F.current.fixed && (!a || a[0] === false) && height <= viewport.h && width <= viewport.w) {
rez = {
position: 'fixed',
top: margin[0],
left: margin[3]
};
}
rez.top = Math.ceil(Math.max(rez.top, rez.top + ((viewport.h - height) * F.current.topRatio))) + 'px';
rez.left = Math.ceil(Math.max(rez.left, rez.left + ((viewport.w - width) * 0.5))) + 'px';
return rez;
},
_afterZoomIn: function () {
var current = F.current;
F.isOpen = F.isOpened = true;
F.wrap.addClass('fancybox-opened').css('overflow', 'visible');
F.update();
F.inner.css('overflow', current.scrolling === 'auto' ? 'auto' : (current.scrolling === 'yes' ? 'scroll' : 'hidden'));
if (current.closeClick) {
F.inner.bind('click.fb', F.close);
}
if (current.closeBtn) {
$(F.current.tpl.closeBtn).appendTo(F.wrap).bind('click.fb', F.close);
}
if (current.arrows && F.group.length > 1) {
if (current.loop || current.index > 0) {
$(current.tpl.prev).appendTo(F.wrap).bind('click.fb', F.prev);
}
if (current.loop || current.index < F.group.length - 1) {
$(current.tpl.next).appendTo(F.wrap).bind('click.fb', F.next);
}
}
F.trigger('afterShow');
if (F.opts.autoPlay && !F.player.isActive) {
F.opts.autoPlay = false;
F.play();
}
},
_afterZoomOut: function () {
F.unbindEvents();
F.trigger('afterClose');
F.wrap.trigger('onReset').remove();
$.extend(F, {
group: {},
opts: {},
current: null,
isOpened: false,
isOpen: false,
wrap: null,
outer: null,
inner: null
});
}
});
F.transitions = {
getOrigPosition: function () {
var element = F.current.element,
pos = {},
width = 50,
height = 50,
image, viewport;
if (element && element.nodeName && $(element).is(':visible')) {
image = $(element).find('img:first');
if (image.length) {
pos = image.offset();
width = image.outerWidth();
height = image.outerHeight();
} else {
pos = $(element).offset();
}
} else {
viewport = F.getViewport();
pos.top = viewport.y + (viewport.h - height) * 0.5;
pos.left = viewport.x + (viewport.w - width) * 0.5;
}
pos = {
top: Math.ceil(pos.top) + 'px',
left: Math.ceil(pos.left) + 'px',
width: Math.ceil(width) + 'px',
height: Math.ceil(height) + 'px'
};
return pos;
},
step: function (now, fx) {
var ratio, innerValue, outerValue;
if (fx.prop === 'width' || fx.prop === 'height') {
innerValue = outerValue = Math.ceil(now - (F.current.padding * 2));
if (fx.prop === 'height') {
ratio = (now - fx.start) / (fx.end - fx.start);
if (fx.start > fx.end) {
ratio = 1 - ratio;
}
innerValue -= F.innerSpace * ratio;
outerValue -= F.outerSpace * ratio;
}
F.inner[fx.prop](innerValue);
F.outer[fx.prop](outerValue);
}
},
zoomIn: function () {
var startPos, endPos, dim = F.current.dim,
space = dim.height - (F.current.padding * 2);
F.innerSpace = space - F.inner.height();
F.outerSpace = space - F.outer.height();
if (F.current.openEffect === 'elastic') {
endPos = $.extend({}, dim, F._getPosition(true));
delete endPos.position;
startPos = this.getOrigPosition();
if (F.current.openOpacity) {
startPos.opacity = 0;
endPos.opacity = 1;
}
F.wrap.css(startPos).animate(endPos, {
duration: F.current.openSpeed,
easing: F.current.openEasing,
step: this.step,
complete: F._afterZoomIn
});
} else {
F.wrap.css($.extend({}, F.current.dim, F._getPosition()));
if (F.current.openEffect === 'fade') {
F.wrap.hide().fadeIn(F.current.openSpeed, F._afterZoomIn);
} else {
F._afterZoomIn();
}
}
},
zoomOut: function () {
var endPos, space = F.wrap.height() - (F.current.padding * 2);
if (F.current.closeEffect === 'elastic') {
if (F.wrap.css('position') === 'fixed') {
F.wrap.css(F._getPosition(true));
}
F.innerSpace = space - F.inner.height();
F.outerSpace = space - F.outer.height();
endPos = this.getOrigPosition();
if (F.current.closeOpacity) {
endPos.opacity = 0;
}
F.wrap.animate(endPos, {
duration: F.current.closeSpeed,
easing: F.current.closeEasing,
step: this.step,
complete: F._afterZoomOut
});
} else {
F.wrap.fadeOut(F.current.closeEffect === 'fade' ? F.current.Speed : 0, F._afterZoomOut);
}
},
changeIn: function () {
var startPos;
if (F.current.nextEffect === 'elastic') {
startPos = F._getPosition(true);
startPos.opacity = 0;
startPos.top = (parseInt(startPos.top, 10) - 200) + 'px';
F.wrap.css(startPos).animate({
opacity: 1,
top: '+=200px'
}, {
duration: F.current.nextSpeed,
complete: F._afterZoomIn
});
} else {
F.wrap.css(F._getPosition());
if (F.current.nextEffect === 'fade') {
F.wrap.hide().fadeIn(F.current.nextSpeed, F._afterZoomIn);
} else {
F._afterZoomIn();
}
}
},
changeOut: function () {
function cleanUp() {
$(this).trigger('onReset').remove();
}
F.wrap.removeClass('fancybox-opened');
if (F.current.prevEffect === 'elastic') {
F.wrap.animate({
'opacity': 0,
top: '+=200px'
}, {
duration: F.current.prevSpeed,
complete: cleanUp
});
} else {
F.wrap.fadeOut(F.current.prevEffect === 'fade' ? F.current.prevSpeed : 0, cleanUp);
}
}
};
F.helpers.overlay = {
overlay: null,
update: function () {
var width, scrollWidth, offsetWidth;
this.overlay.width(0).height(0);
if ($.browser.msie) {
scrollWidth = Math.max(document.documentElement.scrollWidth, document.body.scrollWidth);
offsetWidth = Math.max(document.documentElement.offsetWidth, document.body.offsetWidth);
width = scrollWidth < offsetWidth ? W.width() : scrollWidth;
} else {
width = D.width();
}
this.overlay.width(width).height(D.height());
},
beforeShow: function (opts) {
if (this.overlay) {
return;
}
this.overlay = $('<div id="fancybox-overlay"></div>').css(opts.css || {
background: 'black'
}).appendTo('body');
if (opts.closeClick) {
this.overlay.bind('click.fb', F.close);
}
W.bind("resize.fb", $.proxy(this.update, this));
this.update();
this.overlay.fadeTo(opts.speedIn || "fast", opts.opacity || 1);
},
onUpdate: function () {
this.update();
},
afterClose: function (opts) {
if (this.overlay) {
this.overlay.fadeOut(opts.speedOut || "fast", function () {
$(this).remove();
});
}
this.overlay = null;
}
};
F.helpers.title = {
beforeShow: function (opts) {
var title, text = F.current.title || F.current.element.title || '';
if (text) {
title = $('<div class="fancybox-title fancybox-title-' + opts.type + '-wrap">' + text + '</div>').appendTo('body');
if (opts.type === 'float') {
title.width(title.width());
title.wrapInner('<span class="child"></span>');
F.current.margin[2] += Math.abs(parseInt(title.css('margin-bottom'), 10));
}
title.appendTo(opts.type === 'over' ? F.inner : (opts.type === 'outside' ? F.wrap : F.outer));
}
}
};
$.fn.fancybox = function (options) {
var opts = options || {},
selector = this.selector || '';
function run(e) {
var group = [];
e.preventDefault();
if (this.rel && this.rel !== '' && this.rel !== 'nofollow') {
group = selector.length ? $(selector).filter('[rel="' + this.rel + '"]') : $('[rel="' + this.rel + '"]');
}
if (group.length) {
opts.index = group.index(this);
F(group.get(), opts);
} else {
F(this, opts);
}
return false;
}
if (selector) {
D.undelegate(selector, 'click.fb-start').delegate(selector, 'click.fb-start', run);
} else {
$(this).unbind('click.fb-start').bind('click.fb-start', run);
}
};
}(window, document, jQuery));
| ready |