bgneal@26: /* bgneal@26: * FancyBox - jQuery Plugin bgneal@26: * Simple and fancy lightbox alternative bgneal@26: * bgneal@26: * Examples and documentation at: http://fancybox.net bgneal@26: * bgneal@26: * Copyright (c) 2008 - 2010 Janis Skarnelis bgneal@26: * bgneal@26: * Version: 1.3.1 (05/03/2010) bgneal@26: * Requires: jQuery v1.3+ bgneal@26: * bgneal@26: * Dual licensed under the MIT and GPL licenses: bgneal@26: * http://www.opensource.org/licenses/mit-license.php bgneal@26: * http://www.gnu.org/licenses/gpl.html bgneal@26: */ bgneal@26: bgneal@26: (function($) { bgneal@26: bgneal@26: var tmp, loading, overlay, wrap, outer, inner, close, nav_left, nav_right, bgneal@26: bgneal@26: selectedIndex = 0, selectedOpts = {}, selectedArray = [], currentIndex = 0, currentOpts = {}, currentArray = [], bgneal@26: bgneal@26: ajaxLoader = null, imgPreloader = new Image(), imgRegExp = /\.(jpg|gif|png|bmp|jpeg)(.*)?$/i, swfRegExp = /[^\.]\.(swf)\s*$/i, bgneal@26: bgneal@26: loadingTimer, loadingFrame = 1, bgneal@26: bgneal@26: start_pos, final_pos, busy = false, shadow = 20, fx = $.extend($('
')[0], { prop: 0 }), titleh = 0, bgneal@26: bgneal@26: isIE6 = !$.support.opacity && !window.XMLHttpRequest, bgneal@26: bgneal@26: /* bgneal@26: * Private methods bgneal@26: */ bgneal@26: bgneal@26: fancybox_abort = function() { bgneal@26: loading.hide(); bgneal@26: bgneal@26: imgPreloader.onerror = imgPreloader.onload = null; bgneal@26: bgneal@26: if (ajaxLoader) { bgneal@26: ajaxLoader.abort(); bgneal@26: } bgneal@26: bgneal@26: tmp.empty(); bgneal@26: }, bgneal@26: bgneal@26: fancybox_error = function() { bgneal@26: $.fancybox('

The requested content cannot be loaded.
Please try again later.

', { bgneal@26: 'scrolling' : 'no', bgneal@26: 'padding' : 20, bgneal@26: 'transitionIn' : 'none', bgneal@26: 'transitionOut' : 'none' bgneal@26: }); bgneal@26: }, bgneal@26: bgneal@26: fancybox_get_viewport = function() { bgneal@26: return [ $(window).width(), $(window).height(), $(document).scrollLeft(), $(document).scrollTop() ]; bgneal@26: }, bgneal@26: bgneal@26: fancybox_get_zoom_to = function () { bgneal@26: var view = fancybox_get_viewport(), bgneal@26: to = {}, bgneal@26: bgneal@26: margin = currentOpts.margin, bgneal@26: resize = currentOpts.autoScale, bgneal@26: bgneal@26: horizontal_space = (shadow + margin) * 2, bgneal@26: vertical_space = (shadow + margin) * 2, bgneal@26: double_padding = (currentOpts.padding * 2), bgneal@26: bgneal@26: ratio; bgneal@26: bgneal@26: if (currentOpts.width.toString().indexOf('%') > -1) { bgneal@26: to.width = ((view[0] * parseFloat(currentOpts.width)) / 100) - (shadow * 2) ; bgneal@26: resize = false; bgneal@26: bgneal@26: } else { bgneal@26: to.width = currentOpts.width + double_padding; bgneal@26: } bgneal@26: bgneal@26: if (currentOpts.height.toString().indexOf('%') > -1) { bgneal@26: to.height = ((view[1] * parseFloat(currentOpts.height)) / 100) - (shadow * 2); bgneal@26: resize = false; bgneal@26: bgneal@26: } else { bgneal@26: to.height = currentOpts.height + double_padding; bgneal@26: } bgneal@26: bgneal@26: if (resize && (to.width > (view[0] - horizontal_space) || to.height > (view[1] - vertical_space))) { bgneal@26: if (selectedOpts.type == 'image' || selectedOpts.type == 'swf') { bgneal@26: horizontal_space += double_padding; bgneal@26: vertical_space += double_padding; bgneal@26: bgneal@26: ratio = Math.min(Math.min( view[0] - horizontal_space, currentOpts.width) / currentOpts.width, Math.min( view[1] - vertical_space, currentOpts.height) / currentOpts.height); bgneal@26: bgneal@26: to.width = Math.round(ratio * (to.width - double_padding)) + double_padding; bgneal@26: to.height = Math.round(ratio * (to.height - double_padding)) + double_padding; bgneal@26: bgneal@26: } else { bgneal@26: to.width = Math.min(to.width, (view[0] - horizontal_space)); bgneal@26: to.height = Math.min(to.height, (view[1] - vertical_space)); bgneal@26: } bgneal@26: } bgneal@26: bgneal@26: to.top = view[3] + ((view[1] - (to.height + (shadow * 2 ))) * 0.5); bgneal@26: to.left = view[2] + ((view[0] - (to.width + (shadow * 2 ))) * 0.5); bgneal@26: bgneal@26: if (currentOpts.autoScale === false) { bgneal@26: to.top = Math.max(view[3] + margin, to.top); bgneal@26: to.left = Math.max(view[2] + margin, to.left); bgneal@26: } bgneal@26: bgneal@26: return to; bgneal@26: }, bgneal@26: bgneal@26: fancybox_format_title = function(title) { bgneal@26: if (title && title.length) { bgneal@26: switch (currentOpts.titlePosition) { bgneal@26: case 'inside': bgneal@26: return title; bgneal@26: case 'over': bgneal@26: return '' + title + ''; bgneal@26: default: bgneal@26: return '' + title + ''; bgneal@26: } bgneal@26: } bgneal@26: bgneal@26: return false; bgneal@26: }, bgneal@26: bgneal@26: fancybox_process_title = function() { bgneal@26: var title = currentOpts.title, bgneal@26: width = final_pos.width - (currentOpts.padding * 2), bgneal@26: titlec = 'fancybox-title-' + currentOpts.titlePosition; bgneal@26: bgneal@26: $('#fancybox-title').remove(); bgneal@26: bgneal@26: titleh = 0; bgneal@26: bgneal@26: if (currentOpts.titleShow === false) { bgneal@26: return; bgneal@26: } bgneal@26: bgneal@26: title = $.isFunction(currentOpts.titleFormat) ? currentOpts.titleFormat(title, currentArray, currentIndex, currentOpts) : fancybox_format_title(title); bgneal@26: bgneal@26: if (!title || title === '') { bgneal@26: return; bgneal@26: } bgneal@26: bgneal@26: $('
').css({ bgneal@26: 'width' : width, bgneal@26: 'paddingLeft' : currentOpts.padding, bgneal@26: 'paddingRight' : currentOpts.padding bgneal@26: }).html(title).appendTo('body'); bgneal@26: bgneal@26: switch (currentOpts.titlePosition) { bgneal@26: case 'inside': bgneal@26: titleh = $("#fancybox-title").outerHeight(true) - currentOpts.padding; bgneal@26: final_pos.height += titleh; bgneal@26: break; bgneal@26: bgneal@26: case 'over': bgneal@26: $('#fancybox-title').css('bottom', currentOpts.padding); bgneal@26: break; bgneal@26: bgneal@26: default: bgneal@26: $('#fancybox-title').css('bottom', $("#fancybox-title").outerHeight(true) * -1); bgneal@26: break; bgneal@26: } bgneal@26: bgneal@26: $('#fancybox-title').appendTo( outer ).hide(); bgneal@26: }, bgneal@26: bgneal@26: fancybox_set_navigation = function() { bgneal@26: $(document).unbind('keydown.fb').bind('keydown.fb', function(e) { bgneal@26: if (e.keyCode == 27 && currentOpts.enableEscapeButton) { bgneal@26: e.preventDefault(); bgneal@26: $.fancybox.close(); bgneal@26: bgneal@26: } else if (e.keyCode == 37) { bgneal@26: e.preventDefault(); bgneal@26: $.fancybox.prev(); bgneal@26: bgneal@26: } else if (e.keyCode == 39) { bgneal@26: e.preventDefault(); bgneal@26: $.fancybox.next(); bgneal@26: } bgneal@26: }); bgneal@26: bgneal@26: if ($.fn.mousewheel) { bgneal@26: wrap.unbind('mousewheel.fb'); bgneal@26: bgneal@26: if (currentArray.length > 1) { bgneal@26: wrap.bind('mousewheel.fb', function(e, delta) { bgneal@26: e.preventDefault(); bgneal@26: bgneal@26: if (busy || delta === 0) { bgneal@26: return; bgneal@26: } bgneal@26: bgneal@26: if (delta > 0) { bgneal@26: $.fancybox.prev(); bgneal@26: } else { bgneal@26: $.fancybox.next(); bgneal@26: } bgneal@26: }); bgneal@26: } bgneal@26: } bgneal@26: bgneal@26: if (!currentOpts.showNavArrows) { return; } bgneal@26: bgneal@26: if ((currentOpts.cyclic && currentArray.length > 1) || currentIndex !== 0) { bgneal@26: nav_left.show(); bgneal@26: } bgneal@26: bgneal@26: if ((currentOpts.cyclic && currentArray.length > 1) || currentIndex != (currentArray.length -1)) { bgneal@26: nav_right.show(); bgneal@26: } bgneal@26: }, bgneal@26: bgneal@26: fancybox_preload_images = function() { bgneal@26: var href, bgneal@26: objNext; bgneal@26: bgneal@26: if ((currentArray.length -1) > currentIndex) { bgneal@26: href = currentArray[ currentIndex + 1 ].href; bgneal@26: bgneal@26: if (typeof href !== 'undefined' && href.match(imgRegExp)) { bgneal@26: objNext = new Image(); bgneal@26: objNext.src = href; bgneal@26: } bgneal@26: } bgneal@26: bgneal@26: if (currentIndex > 0) { bgneal@26: href = currentArray[ currentIndex - 1 ].href; bgneal@26: bgneal@26: if (typeof href !== 'undefined' && href.match(imgRegExp)) { bgneal@26: objNext = new Image(); bgneal@26: objNext.src = href; bgneal@26: } bgneal@26: } bgneal@26: }, bgneal@26: bgneal@26: _finish = function () { bgneal@26: inner.css('overflow', (currentOpts.scrolling == 'auto' ? (currentOpts.type == 'image' || currentOpts.type == 'iframe' || currentOpts.type == 'swf' ? 'hidden' : 'auto') : (currentOpts.scrolling == 'yes' ? 'auto' : 'visible'))); bgneal@26: bgneal@26: if (!$.support.opacity) { bgneal@26: inner.get(0).style.removeAttribute('filter'); bgneal@26: wrap.get(0).style.removeAttribute('filter'); bgneal@26: } bgneal@26: bgneal@26: $('#fancybox-title').show(); bgneal@26: bgneal@26: if (currentOpts.hideOnContentClick) { bgneal@26: inner.one('click', $.fancybox.close); bgneal@26: } bgneal@26: if (currentOpts.hideOnOverlayClick) { bgneal@26: overlay.one('click', $.fancybox.close); bgneal@26: } bgneal@26: bgneal@26: if (currentOpts.showCloseButton) { bgneal@26: close.show(); bgneal@26: } bgneal@26: bgneal@26: fancybox_set_navigation(); bgneal@26: bgneal@26: $(window).bind("resize.fb", $.fancybox.center); bgneal@26: bgneal@26: if (currentOpts.centerOnScroll) { bgneal@26: $(window).bind("scroll.fb", $.fancybox.center); bgneal@26: } else { bgneal@26: $(window).unbind("scroll.fb"); bgneal@26: } bgneal@26: bgneal@26: if ($.isFunction(currentOpts.onComplete)) { bgneal@26: currentOpts.onComplete(currentArray, currentIndex, currentOpts); bgneal@26: } bgneal@26: bgneal@26: busy = false; bgneal@26: bgneal@26: fancybox_preload_images(); bgneal@26: }, bgneal@26: bgneal@26: fancybox_draw = function(pos) { bgneal@26: var width = Math.round(start_pos.width + (final_pos.width - start_pos.width) * pos), bgneal@26: height = Math.round(start_pos.height + (final_pos.height - start_pos.height) * pos), bgneal@26: bgneal@26: top = Math.round(start_pos.top + (final_pos.top - start_pos.top) * pos), bgneal@26: left = Math.round(start_pos.left + (final_pos.left - start_pos.left) * pos); bgneal@26: bgneal@26: wrap.css({ bgneal@26: 'width' : width + 'px', bgneal@26: 'height' : height + 'px', bgneal@26: 'top' : top + 'px', bgneal@26: 'left' : left + 'px' bgneal@26: }); bgneal@26: bgneal@26: width = Math.max(width - currentOpts.padding * 2, 0); bgneal@26: height = Math.max(height - (currentOpts.padding * 2 + (titleh * pos)), 0); bgneal@26: bgneal@26: inner.css({ bgneal@26: 'width' : width + 'px', bgneal@26: 'height' : height + 'px' bgneal@26: }); bgneal@26: bgneal@26: if (typeof final_pos.opacity !== 'undefined') { bgneal@26: wrap.css('opacity', (pos < 0.5 ? 0.5 : pos)); bgneal@26: } bgneal@26: }, bgneal@26: bgneal@26: fancybox_get_obj_pos = function(obj) { bgneal@26: var pos = obj.offset(); bgneal@26: bgneal@26: pos.top += parseFloat( obj.css('paddingTop') ) || 0; bgneal@26: pos.left += parseFloat( obj.css('paddingLeft') ) || 0; bgneal@26: bgneal@26: pos.top += parseFloat( obj.css('border-top-width') ) || 0; bgneal@26: pos.left += parseFloat( obj.css('border-left-width') ) || 0; bgneal@26: bgneal@26: pos.width = obj.width(); bgneal@26: pos.height = obj.height(); bgneal@26: bgneal@26: return pos; bgneal@26: }, bgneal@26: bgneal@26: fancybox_get_zoom_from = function() { bgneal@26: var orig = selectedOpts.orig ? $(selectedOpts.orig) : false, bgneal@26: from = {}, bgneal@26: pos, bgneal@26: view; bgneal@26: bgneal@26: if (orig && orig.length) { bgneal@26: pos = fancybox_get_obj_pos(orig); bgneal@26: bgneal@26: from = { bgneal@26: width : (pos.width + (currentOpts.padding * 2)), bgneal@26: height : (pos.height + (currentOpts.padding * 2)), bgneal@26: top : (pos.top - currentOpts.padding - shadow), bgneal@26: left : (pos.left - currentOpts.padding - shadow) bgneal@26: }; bgneal@26: bgneal@26: } else { bgneal@26: view = fancybox_get_viewport(); bgneal@26: bgneal@26: from = { bgneal@26: width : 1, bgneal@26: height : 1, bgneal@26: top : view[3] + view[1] * 0.5, bgneal@26: left : view[2] + view[0] * 0.5 bgneal@26: }; bgneal@26: } bgneal@26: bgneal@26: return from; bgneal@26: }, bgneal@26: bgneal@26: fancybox_show = function() { bgneal@26: loading.hide(); bgneal@26: bgneal@26: if (wrap.is(":visible") && $.isFunction(currentOpts.onCleanup)) { bgneal@26: if (currentOpts.onCleanup(currentArray, currentIndex, currentOpts) === false) { bgneal@26: $.event.trigger('fancybox-cancel'); bgneal@26: bgneal@26: busy = false; bgneal@26: return; bgneal@26: } bgneal@26: } bgneal@26: bgneal@26: currentArray = selectedArray; bgneal@26: currentIndex = selectedIndex; bgneal@26: currentOpts = selectedOpts; bgneal@26: bgneal@26: inner.get(0).scrollTop = 0; bgneal@26: inner.get(0).scrollLeft = 0; bgneal@26: bgneal@26: if (currentOpts.overlayShow) { bgneal@26: if (isIE6) { bgneal@26: $('select:not(#fancybox-tmp select)').filter(function() { bgneal@26: return this.style.visibility !== 'hidden'; bgneal@26: }).css({'visibility':'hidden'}).one('fancybox-cleanup', function() { bgneal@26: this.style.visibility = 'inherit'; bgneal@26: }); bgneal@26: } bgneal@26: bgneal@26: overlay.css({ bgneal@26: 'background-color' : currentOpts.overlayColor, bgneal@26: 'opacity' : currentOpts.overlayOpacity bgneal@26: }).unbind().show(); bgneal@26: } bgneal@26: bgneal@26: final_pos = fancybox_get_zoom_to(); bgneal@26: bgneal@26: fancybox_process_title(); bgneal@26: bgneal@26: if (wrap.is(":visible")) { bgneal@26: $( close.add( nav_left ).add( nav_right ) ).hide(); bgneal@26: bgneal@26: var pos = wrap.position(), bgneal@26: equal; bgneal@26: bgneal@26: start_pos = { bgneal@26: top : pos.top , bgneal@26: left : pos.left, bgneal@26: width : wrap.width(), bgneal@26: height : wrap.height() bgneal@26: }; bgneal@26: bgneal@26: equal = (start_pos.width == final_pos.width && start_pos.height == final_pos.height); bgneal@26: bgneal@26: inner.fadeOut(currentOpts.changeFade, function() { bgneal@26: var finish_resizing = function() { bgneal@26: inner.html( tmp.contents() ).fadeIn(currentOpts.changeFade, _finish); bgneal@26: }; bgneal@26: bgneal@26: $.event.trigger('fancybox-change'); bgneal@26: bgneal@26: inner.empty().css('overflow', 'hidden'); bgneal@26: bgneal@26: if (equal) { bgneal@26: inner.css({ bgneal@26: top : currentOpts.padding, bgneal@26: left : currentOpts.padding, bgneal@26: width : Math.max(final_pos.width - (currentOpts.padding * 2), 1), bgneal@26: height : Math.max(final_pos.height - (currentOpts.padding * 2) - titleh, 1) bgneal@26: }); bgneal@26: bgneal@26: finish_resizing(); bgneal@26: bgneal@26: } else { bgneal@26: inner.css({ bgneal@26: top : currentOpts.padding, bgneal@26: left : currentOpts.padding, bgneal@26: width : Math.max(start_pos.width - (currentOpts.padding * 2), 1), bgneal@26: height : Math.max(start_pos.height - (currentOpts.padding * 2), 1) bgneal@26: }); bgneal@26: bgneal@26: fx.prop = 0; bgneal@26: bgneal@26: $(fx).animate({ prop: 1 }, { bgneal@26: duration : currentOpts.changeSpeed, bgneal@26: easing : currentOpts.easingChange, bgneal@26: step : fancybox_draw, bgneal@26: complete : finish_resizing bgneal@26: }); bgneal@26: } bgneal@26: }); bgneal@26: bgneal@26: return; bgneal@26: } bgneal@26: bgneal@26: wrap.css('opacity', 1); bgneal@26: bgneal@26: if (currentOpts.transitionIn == 'elastic') { bgneal@26: start_pos = fancybox_get_zoom_from(); bgneal@26: bgneal@26: inner.css({ bgneal@26: top : currentOpts.padding, bgneal@26: left : currentOpts.padding, bgneal@26: width : Math.max(start_pos.width - (currentOpts.padding * 2), 1), bgneal@26: height : Math.max(start_pos.height - (currentOpts.padding * 2), 1) bgneal@26: }) bgneal@26: .html( tmp.contents() ); bgneal@26: bgneal@26: wrap.css(start_pos).show(); bgneal@26: bgneal@26: if (currentOpts.opacity) { bgneal@26: final_pos.opacity = 0; bgneal@26: } bgneal@26: bgneal@26: fx.prop = 0; bgneal@26: bgneal@26: $(fx).animate({ prop: 1 }, { bgneal@26: duration : currentOpts.speedIn, bgneal@26: easing : currentOpts.easingIn, bgneal@26: step : fancybox_draw, bgneal@26: complete : _finish bgneal@26: }); bgneal@26: bgneal@26: } else { bgneal@26: inner.css({ bgneal@26: top : currentOpts.padding, bgneal@26: left : currentOpts.padding, bgneal@26: width : Math.max(final_pos.width - (currentOpts.padding * 2), 1), bgneal@26: height : Math.max(final_pos.height - (currentOpts.padding * 2) - titleh, 1) bgneal@26: }) bgneal@26: .html( tmp.contents() ); bgneal@26: bgneal@26: wrap.css( final_pos ).fadeIn( currentOpts.transitionIn == 'none' ? 0 : currentOpts.speedIn, _finish ); bgneal@26: } bgneal@26: }, bgneal@26: bgneal@26: fancybox_process_inline = function() { bgneal@26: tmp.width( selectedOpts.width ); bgneal@26: tmp.height( selectedOpts.height ); bgneal@26: bgneal@26: if (selectedOpts.width == 'auto') { bgneal@26: selectedOpts.width = tmp.width(); bgneal@26: } bgneal@26: if (selectedOpts.height == 'auto') { bgneal@26: selectedOpts.height = tmp.height(); bgneal@26: } bgneal@26: bgneal@26: fancybox_show(); bgneal@26: }, bgneal@26: bgneal@26: fancybox_process_image = function() { bgneal@26: busy = true; bgneal@26: bgneal@26: selectedOpts.width = imgPreloader.width; bgneal@26: selectedOpts.height = imgPreloader.height; bgneal@26: bgneal@26: $("").attr({ bgneal@26: 'id' : 'fancybox-img', bgneal@26: 'src' : imgPreloader.src, bgneal@26: 'alt' : selectedOpts.title bgneal@26: }).appendTo( tmp ); bgneal@26: bgneal@26: fancybox_show(); bgneal@26: }, bgneal@26: bgneal@26: fancybox_start = function() { bgneal@26: fancybox_abort(); bgneal@26: bgneal@26: var obj = selectedArray[ selectedIndex ], bgneal@26: href, bgneal@26: type, bgneal@26: title, bgneal@26: str, bgneal@26: emb, bgneal@26: selector, bgneal@26: data; bgneal@26: bgneal@26: selectedOpts = $.extend({}, $.fn.fancybox.defaults, (typeof $(obj).data('fancybox') == 'undefined' ? selectedOpts : $(obj).data('fancybox'))); bgneal@26: title = obj.title || $(obj).title || selectedOpts.title || ''; bgneal@26: bgneal@26: if (obj.nodeName && !selectedOpts.orig) { bgneal@26: selectedOpts.orig = $(obj).children("img:first").length ? $(obj).children("img:first") : $(obj); bgneal@26: } bgneal@26: bgneal@26: if (title === '' && selectedOpts.orig) { bgneal@26: title = selectedOpts.orig.attr('alt'); bgneal@26: } bgneal@26: bgneal@26: if (obj.nodeName && (/^(?:javascript|#)/i).test(obj.href)) { bgneal@26: href = selectedOpts.href || null; bgneal@26: } else { bgneal@26: href = selectedOpts.href || obj.href || null; bgneal@26: } bgneal@26: bgneal@26: if (selectedOpts.type) { bgneal@26: type = selectedOpts.type; bgneal@26: bgneal@26: if (!href) { bgneal@26: href = selectedOpts.content; bgneal@26: } bgneal@26: bgneal@26: } else if (selectedOpts.content) { bgneal@26: type = 'html'; bgneal@26: bgneal@26: } else if (href) { bgneal@26: if (href.match(imgRegExp)) { bgneal@26: type = 'image'; bgneal@26: bgneal@26: } else if (href.match(swfRegExp)) { bgneal@26: type = 'swf'; bgneal@26: bgneal@26: } else if ($(obj).hasClass("iframe")) { bgneal@26: type = 'iframe'; bgneal@26: bgneal@26: } else if (href.match(/#/)) { bgneal@26: obj = href.substr(href.indexOf("#")); bgneal@26: bgneal@26: type = $(obj).length > 0 ? 'inline' : 'ajax'; bgneal@26: } else { bgneal@26: type = 'ajax'; bgneal@26: } bgneal@26: } else { bgneal@26: type = 'inline'; bgneal@26: } bgneal@26: bgneal@26: selectedOpts.type = type; bgneal@26: selectedOpts.href = href; bgneal@26: selectedOpts.title = title; bgneal@26: bgneal@26: if (selectedOpts.autoDimensions && selectedOpts.type !== 'iframe' && selectedOpts.type !== 'swf') { bgneal@26: selectedOpts.width = 'auto'; bgneal@26: selectedOpts.height = 'auto'; bgneal@26: } bgneal@26: bgneal@26: if (selectedOpts.modal) { bgneal@26: selectedOpts.overlayShow = true; bgneal@26: selectedOpts.hideOnOverlayClick = false; bgneal@26: selectedOpts.hideOnContentClick = false; bgneal@26: selectedOpts.enableEscapeButton = false; bgneal@26: selectedOpts.showCloseButton = false; bgneal@26: } bgneal@26: bgneal@26: if ($.isFunction(selectedOpts.onStart)) { bgneal@26: if (selectedOpts.onStart(selectedArray, selectedIndex, selectedOpts) === false) { bgneal@26: busy = false; bgneal@26: return; bgneal@26: } bgneal@26: } bgneal@26: bgneal@26: tmp.css('padding', (shadow + selectedOpts.padding + selectedOpts.margin)); bgneal@26: bgneal@26: $('.fancybox-inline-tmp').unbind('fancybox-cancel').bind('fancybox-change', function() { bgneal@26: $(this).replaceWith(inner.children()); bgneal@26: }); bgneal@26: bgneal@26: switch (type) { bgneal@26: case 'html' : bgneal@26: tmp.html( selectedOpts.content ); bgneal@26: fancybox_process_inline(); bgneal@26: break; bgneal@26: bgneal@26: case 'inline' : bgneal@26: $('
').hide().insertBefore( $(obj) ).bind('fancybox-cleanup', function() { bgneal@26: $(this).replaceWith(inner.children()); bgneal@26: }).bind('fancybox-cancel', function() { bgneal@26: $(this).replaceWith(tmp.children()); bgneal@26: }); bgneal@26: bgneal@26: $(obj).appendTo(tmp); bgneal@26: bgneal@26: fancybox_process_inline(); bgneal@26: break; bgneal@26: bgneal@26: case 'image': bgneal@26: busy = false; bgneal@26: bgneal@26: $.fancybox.showActivity(); bgneal@26: bgneal@26: imgPreloader = new Image(); bgneal@26: bgneal@26: imgPreloader.onerror = function() { bgneal@26: fancybox_error(); bgneal@26: }; bgneal@26: bgneal@26: imgPreloader.onload = function() { bgneal@26: imgPreloader.onerror = null; bgneal@26: imgPreloader.onload = null; bgneal@26: fancybox_process_image(); bgneal@26: }; bgneal@26: bgneal@26: imgPreloader.src = href; bgneal@26: bgneal@26: break; bgneal@26: bgneal@26: case 'swf': bgneal@26: str = ''; bgneal@26: emb = ''; bgneal@26: bgneal@26: $.each(selectedOpts.swf, function(name, val) { bgneal@26: str += ''; bgneal@26: emb += ' ' + name + '="' + val + '"'; bgneal@26: }); bgneal@26: bgneal@26: str += ''; bgneal@26: bgneal@26: tmp.html(str); bgneal@26: bgneal@26: fancybox_process_inline(); bgneal@26: break; bgneal@26: bgneal@26: case 'ajax': bgneal@26: selector = href.split('#', 2); bgneal@26: data = selectedOpts.ajax.data || {}; bgneal@26: bgneal@26: if (selector.length > 1) { bgneal@26: href = selector[0]; bgneal@26: bgneal@26: if (typeof data == "string") { bgneal@26: data += '&selector=' + selector[1]; bgneal@26: } else { bgneal@26: data.selector = selector[1]; bgneal@26: } bgneal@26: } bgneal@26: bgneal@26: busy = false; bgneal@26: $.fancybox.showActivity(); bgneal@26: bgneal@26: ajaxLoader = $.ajax($.extend(selectedOpts.ajax, { bgneal@26: url : href, bgneal@26: data : data, bgneal@26: error : fancybox_error, bgneal@26: success : function(data, textStatus, XMLHttpRequest) { bgneal@26: if (ajaxLoader.status == 200) { bgneal@26: tmp.html( data ); bgneal@26: fancybox_process_inline(); bgneal@26: } bgneal@26: } bgneal@26: })); bgneal@26: bgneal@26: break; bgneal@26: bgneal@26: case 'iframe' : bgneal@26: $('').appendTo(tmp); bgneal@26: fancybox_show(); bgneal@26: break; bgneal@26: } bgneal@26: }, bgneal@26: bgneal@26: fancybox_animate_loading = function() { bgneal@26: if (!loading.is(':visible')){ bgneal@26: clearInterval(loadingTimer); bgneal@26: return; bgneal@26: } bgneal@26: bgneal@26: $('div', loading).css('top', (loadingFrame * -40) + 'px'); bgneal@26: bgneal@26: loadingFrame = (loadingFrame + 1) % 12; bgneal@26: }, bgneal@26: bgneal@26: fancybox_init = function() { bgneal@26: if ($("#fancybox-wrap").length) { bgneal@26: return; bgneal@26: } bgneal@26: bgneal@26: $('body').append( bgneal@26: tmp = $('
'), bgneal@26: loading = $('
'), bgneal@26: overlay = $('
'), bgneal@26: wrap = $('
') bgneal@26: ); bgneal@26: bgneal@26: if (!$.support.opacity) { bgneal@26: wrap.addClass('fancybox-ie'); bgneal@26: loading.addClass('fancybox-ie'); bgneal@26: } bgneal@26: bgneal@26: outer = $('
') bgneal@26: .append('
') bgneal@26: .appendTo( wrap ); bgneal@26: bgneal@26: outer.append( bgneal@26: inner = $('
'), bgneal@26: close = $(''), bgneal@26: bgneal@26: nav_left = $(''), bgneal@26: nav_right = $('') bgneal@26: ); bgneal@26: bgneal@26: close.click($.fancybox.close); bgneal@26: loading.click($.fancybox.cancel); bgneal@26: bgneal@26: nav_left.click(function(e) { bgneal@26: e.preventDefault(); bgneal@26: $.fancybox.prev(); bgneal@26: }); bgneal@26: bgneal@26: nav_right.click(function(e) { bgneal@26: e.preventDefault(); bgneal@26: $.fancybox.next(); bgneal@26: }); bgneal@26: bgneal@26: if (isIE6) { bgneal@26: overlay.get(0).style.setExpression('height', "document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px'"); bgneal@26: 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'"); bgneal@26: bgneal@26: outer.prepend(''); bgneal@26: } bgneal@26: }; bgneal@26: bgneal@26: /* bgneal@26: * Public methods bgneal@26: */ bgneal@26: bgneal@26: $.fn.fancybox = function(options) { bgneal@26: $(this) bgneal@26: .data('fancybox', $.extend({}, options, ($.metadata ? $(this).metadata() : {}))) bgneal@26: .unbind('click.fb').bind('click.fb', function(e) { bgneal@26: e.preventDefault(); bgneal@26: bgneal@26: if (busy) { bgneal@26: return; bgneal@26: } bgneal@26: bgneal@26: busy = true; bgneal@26: bgneal@26: $(this).blur(); bgneal@26: bgneal@26: selectedArray = []; bgneal@26: selectedIndex = 0; bgneal@26: bgneal@26: var rel = $(this).attr('rel') || ''; bgneal@26: bgneal@26: if (!rel || rel == '' || rel === 'nofollow') { bgneal@26: selectedArray.push(this); bgneal@26: bgneal@26: } else { bgneal@26: selectedArray = $("a[rel=" + rel + "], area[rel=" + rel + "]"); bgneal@26: selectedIndex = selectedArray.index( this ); bgneal@26: } bgneal@26: bgneal@26: fancybox_start(); bgneal@26: bgneal@26: return false; bgneal@26: }); bgneal@26: bgneal@26: return this; bgneal@26: }; bgneal@26: bgneal@26: $.fancybox = function(obj) { bgneal@26: if (busy) { bgneal@26: return; bgneal@26: } bgneal@26: bgneal@26: busy = true; bgneal@26: bgneal@26: var opts = typeof arguments[1] !== 'undefined' ? arguments[1] : {}; bgneal@26: bgneal@26: selectedArray = []; bgneal@26: selectedIndex = opts.index || 0; bgneal@26: bgneal@26: if ($.isArray(obj)) { bgneal@26: for (var i = 0, j = obj.length; i < j; i++) { bgneal@26: if (typeof obj[i] == 'object') { bgneal@26: $(obj[i]).data('fancybox', $.extend({}, opts, obj[i])); bgneal@26: } else { bgneal@26: obj[i] = $({}).data('fancybox', $.extend({content : obj[i]}, opts)); bgneal@26: } bgneal@26: } bgneal@26: bgneal@26: selectedArray = jQuery.merge(selectedArray, obj); bgneal@26: bgneal@26: } else { bgneal@26: if (typeof obj == 'object') { bgneal@26: $(obj).data('fancybox', $.extend({}, opts, obj)); bgneal@26: } else { bgneal@26: obj = $({}).data('fancybox', $.extend({content : obj}, opts)); bgneal@26: } bgneal@26: bgneal@26: selectedArray.push(obj); bgneal@26: } bgneal@26: bgneal@26: if (selectedIndex > selectedArray.length || selectedIndex < 0) { bgneal@26: selectedIndex = 0; bgneal@26: } bgneal@26: bgneal@26: fancybox_start(); bgneal@26: }; bgneal@26: bgneal@26: $.fancybox.showActivity = function() { bgneal@26: clearInterval(loadingTimer); bgneal@26: bgneal@26: loading.show(); bgneal@26: loadingTimer = setInterval(fancybox_animate_loading, 66); bgneal@26: }; bgneal@26: bgneal@26: $.fancybox.hideActivity = function() { bgneal@26: loading.hide(); bgneal@26: }; bgneal@26: bgneal@26: $.fancybox.next = function() { bgneal@26: return $.fancybox.pos( currentIndex + 1); bgneal@26: }; bgneal@26: bgneal@26: $.fancybox.prev = function() { bgneal@26: return $.fancybox.pos( currentIndex - 1); bgneal@26: }; bgneal@26: bgneal@26: $.fancybox.pos = function(pos) { bgneal@26: if (busy) { bgneal@26: return; bgneal@26: } bgneal@26: bgneal@26: pos = parseInt(pos, 10); bgneal@26: bgneal@26: if (pos > -1 && currentArray.length > pos) { bgneal@26: selectedIndex = pos; bgneal@26: fancybox_start(); bgneal@26: } bgneal@26: bgneal@26: if (currentOpts.cyclic && currentArray.length > 1 && pos < 0) { bgneal@26: selectedIndex = currentArray.length - 1; bgneal@26: fancybox_start(); bgneal@26: } bgneal@26: bgneal@26: if (currentOpts.cyclic && currentArray.length > 1 && pos >= currentArray.length) { bgneal@26: selectedIndex = 0; bgneal@26: fancybox_start(); bgneal@26: } bgneal@26: bgneal@26: return; bgneal@26: }; bgneal@26: bgneal@26: $.fancybox.cancel = function() { bgneal@26: if (busy) { bgneal@26: return; bgneal@26: } bgneal@26: bgneal@26: busy = true; bgneal@26: bgneal@26: $.event.trigger('fancybox-cancel'); bgneal@26: bgneal@26: fancybox_abort(); bgneal@26: bgneal@26: if (selectedOpts && $.isFunction(selectedOpts.onCancel)) { bgneal@26: selectedOpts.onCancel(selectedArray, selectedIndex, selectedOpts); bgneal@26: } bgneal@26: bgneal@26: busy = false; bgneal@26: }; bgneal@26: bgneal@26: // Note: within an iframe use - parent.$.fancybox.close(); bgneal@26: $.fancybox.close = function() { bgneal@26: if (busy || wrap.is(':hidden')) { bgneal@26: return; bgneal@26: } bgneal@26: bgneal@26: busy = true; bgneal@26: bgneal@26: if (currentOpts && $.isFunction(currentOpts.onCleanup)) { bgneal@26: if (currentOpts.onCleanup(currentArray, currentIndex, currentOpts) === false) { bgneal@26: busy = false; bgneal@26: return; bgneal@26: } bgneal@26: } bgneal@26: bgneal@26: fancybox_abort(); bgneal@26: bgneal@26: $(close.add( nav_left ).add( nav_right )).hide(); bgneal@26: bgneal@26: $('#fancybox-title').remove(); bgneal@26: bgneal@26: wrap.add(inner).add(overlay).unbind(); bgneal@26: bgneal@26: $(window).unbind("resize.fb scroll.fb"); bgneal@26: $(document).unbind('keydown.fb'); bgneal@26: bgneal@26: function _cleanup() { bgneal@26: overlay.fadeOut('fast'); bgneal@26: bgneal@26: wrap.hide(); bgneal@26: bgneal@26: $.event.trigger('fancybox-cleanup'); bgneal@26: bgneal@26: inner.empty(); bgneal@26: bgneal@26: if ($.isFunction(currentOpts.onClosed)) { bgneal@26: currentOpts.onClosed(currentArray, currentIndex, currentOpts); bgneal@26: } bgneal@26: bgneal@26: currentArray = selectedOpts = []; bgneal@26: currentIndex = selectedIndex = 0; bgneal@26: currentOpts = selectedOpts = {}; bgneal@26: bgneal@26: busy = false; bgneal@26: } bgneal@26: bgneal@26: inner.css('overflow', 'hidden'); bgneal@26: bgneal@26: if (currentOpts.transitionOut == 'elastic') { bgneal@26: start_pos = fancybox_get_zoom_from(); bgneal@26: bgneal@26: var pos = wrap.position(); bgneal@26: bgneal@26: final_pos = { bgneal@26: top : pos.top , bgneal@26: left : pos.left, bgneal@26: width : wrap.width(), bgneal@26: height : wrap.height() bgneal@26: }; bgneal@26: bgneal@26: if (currentOpts.opacity) { bgneal@26: final_pos.opacity = 1; bgneal@26: } bgneal@26: bgneal@26: fx.prop = 1; bgneal@26: bgneal@26: $(fx).animate({ prop: 0 }, { bgneal@26: duration : currentOpts.speedOut, bgneal@26: easing : currentOpts.easingOut, bgneal@26: step : fancybox_draw, bgneal@26: complete : _cleanup bgneal@26: }); bgneal@26: bgneal@26: } else { bgneal@26: wrap.fadeOut( currentOpts.transitionOut == 'none' ? 0 : currentOpts.speedOut, _cleanup); bgneal@26: } bgneal@26: }; bgneal@26: bgneal@26: $.fancybox.resize = function() { bgneal@26: var c, h; bgneal@26: bgneal@26: if (busy || wrap.is(':hidden')) { bgneal@26: return; bgneal@26: } bgneal@26: bgneal@26: busy = true; bgneal@26: bgneal@26: c = inner.wrapInner("
").children(); bgneal@26: h = c.height(); bgneal@26: bgneal@26: wrap.css({height: h + (currentOpts.padding * 2) + titleh}); bgneal@26: inner.css({height: h}); bgneal@26: bgneal@26: c.replaceWith(c.children()); bgneal@26: bgneal@26: $.fancybox.center(); bgneal@26: }; bgneal@26: bgneal@26: $.fancybox.center = function() { bgneal@26: busy = true; bgneal@26: bgneal@26: var view = fancybox_get_viewport(), bgneal@26: margin = currentOpts.margin, bgneal@26: to = {}; bgneal@26: bgneal@26: to.top = view[3] + ((view[1] - ((wrap.height() - titleh) + (shadow * 2 ))) * 0.5); bgneal@26: to.left = view[2] + ((view[0] - (wrap.width() + (shadow * 2 ))) * 0.5); bgneal@26: bgneal@26: to.top = Math.max(view[3] + margin, to.top); bgneal@26: to.left = Math.max(view[2] + margin, to.left); bgneal@26: bgneal@26: wrap.css(to); bgneal@26: bgneal@26: busy = false; bgneal@26: }; bgneal@26: bgneal@26: $.fn.fancybox.defaults = { bgneal@26: padding : 10, bgneal@26: margin : 20, bgneal@26: opacity : false, bgneal@26: modal : false, bgneal@26: cyclic : false, bgneal@26: scrolling : 'auto', // 'auto', 'yes' or 'no' bgneal@26: bgneal@26: width : 560, bgneal@26: height : 340, bgneal@26: bgneal@26: autoScale : true, bgneal@26: autoDimensions : true, bgneal@26: centerOnScroll : false, bgneal@26: bgneal@26: ajax : {}, bgneal@26: swf : { wmode: 'transparent' }, bgneal@26: bgneal@26: hideOnOverlayClick : true, bgneal@26: hideOnContentClick : false, bgneal@26: bgneal@26: overlayShow : true, bgneal@26: overlayOpacity : 0.3, bgneal@26: overlayColor : '#666', bgneal@26: bgneal@26: titleShow : true, bgneal@26: titlePosition : 'outside', // 'outside', 'inside' or 'over' bgneal@26: titleFormat : null, bgneal@26: bgneal@26: transitionIn : 'fade', // 'elastic', 'fade' or 'none' bgneal@26: transitionOut : 'fade', // 'elastic', 'fade' or 'none' bgneal@26: bgneal@26: speedIn : 300, bgneal@26: speedOut : 300, bgneal@26: bgneal@26: changeSpeed : 300, bgneal@26: changeFade : 'fast', bgneal@26: bgneal@26: easingIn : 'swing', bgneal@26: easingOut : 'swing', bgneal@26: bgneal@26: showCloseButton : true, bgneal@26: showNavArrows : true, bgneal@26: enableEscapeButton : true, bgneal@26: bgneal@26: onStart : null, bgneal@26: onCancel : null, bgneal@26: onComplete : null, bgneal@26: onCleanup : null, bgneal@26: onClosed : null bgneal@26: }; bgneal@26: bgneal@26: $(document).ready(function() { bgneal@26: fancybox_init(); bgneal@26: }); bgneal@26: bgneal@26: })(jQuery);