bgneal@5: /* bgneal@5: * FancyBox - jQuery Plugin bgneal@5: * Simple and fancy lightbox alternative bgneal@5: * bgneal@5: * Examples and documentation at: http://fancybox.net bgneal@5: * bgneal@5: * Copyright (c) 2008 - 2010 Janis Skarnelis bgneal@5: * That said, it is hardly a one-person project. Many people have submitted bugs, code, and offered their advice freely. Their support is greatly appreciated. bgneal@5: * bgneal@5: * Version: 1.3.4 (11/11/2010) bgneal@5: * Requires: jQuery v1.3+ bgneal@5: * bgneal@5: * Dual licensed under the MIT and GPL licenses: bgneal@5: * http://www.opensource.org/licenses/mit-license.php bgneal@5: * http://www.gnu.org/licenses/gpl.html bgneal@5: */ bgneal@5: bgneal@5: ;(function($) { bgneal@5: var tmp, loading, overlay, wrap, outer, content, close, title, nav_left, nav_right, bgneal@5: bgneal@5: selectedIndex = 0, selectedOpts = {}, selectedArray = [], currentIndex = 0, currentOpts = {}, currentArray = [], bgneal@5: bgneal@5: ajaxLoader = null, imgPreloader = new Image(), imgRegExp = /\.(jpg|gif|png|bmp|jpeg)(.*)?$/i, swfRegExp = /[^\.]\.(swf)\s*$/i, bgneal@5: bgneal@5: loadingTimer, loadingFrame = 1, bgneal@5: bgneal@5: titleHeight = 0, titleStr = '', start_pos, final_pos, busy = false, fx = $.extend($('
')[0], { prop: 0 }), bgneal@5: bgneal@5: isIE6 = $.browser.msie && $.browser.version < 7 && !window.XMLHttpRequest, bgneal@5: bgneal@5: /* bgneal@5: * Private methods bgneal@5: */ bgneal@5: bgneal@5: _abort = function() { bgneal@5: loading.hide(); bgneal@5: bgneal@5: imgPreloader.onerror = imgPreloader.onload = null; bgneal@5: bgneal@5: if (ajaxLoader) { bgneal@5: ajaxLoader.abort(); bgneal@5: } bgneal@5: bgneal@5: tmp.empty(); bgneal@5: }, bgneal@5: bgneal@5: _error = function() { bgneal@5: if (false === selectedOpts.onError(selectedArray, selectedIndex, selectedOpts)) { bgneal@5: loading.hide(); bgneal@5: busy = false; bgneal@5: return; bgneal@5: } bgneal@5: bgneal@5: selectedOpts.titleShow = false; bgneal@5: bgneal@5: selectedOpts.width = 'auto'; bgneal@5: selectedOpts.height = 'auto'; bgneal@5: bgneal@5: tmp.html( '

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

' ); bgneal@5: bgneal@5: _process_inline(); bgneal@5: }, bgneal@5: bgneal@5: _start = function() { bgneal@5: var obj = selectedArray[ selectedIndex ], bgneal@5: href, bgneal@5: type, bgneal@5: title, bgneal@5: str, bgneal@5: emb, bgneal@5: ret; bgneal@5: bgneal@5: _abort(); bgneal@5: bgneal@5: selectedOpts = $.extend({}, $.fn.fancybox.defaults, (typeof $(obj).data('fancybox') == 'undefined' ? selectedOpts : $(obj).data('fancybox'))); bgneal@5: bgneal@5: ret = selectedOpts.onStart(selectedArray, selectedIndex, selectedOpts); bgneal@5: bgneal@5: if (ret === false) { bgneal@5: busy = false; bgneal@5: return; bgneal@5: } else if (typeof ret == 'object') { bgneal@5: selectedOpts = $.extend(selectedOpts, ret); bgneal@5: } bgneal@5: bgneal@5: title = selectedOpts.title || (obj.nodeName ? $(obj).attr('title') : obj.title) || ''; bgneal@5: bgneal@5: if (obj.nodeName && !selectedOpts.orig) { bgneal@5: selectedOpts.orig = $(obj).children("img:first").length ? $(obj).children("img:first") : $(obj); bgneal@5: } bgneal@5: bgneal@5: if (title === '' && selectedOpts.orig && selectedOpts.titleFromAlt) { bgneal@5: title = selectedOpts.orig.attr('alt'); bgneal@5: } bgneal@5: bgneal@5: href = selectedOpts.href || (obj.nodeName ? $(obj).attr('href') : obj.href) || null; bgneal@5: bgneal@5: if ((/^(?:javascript)/i).test(href) || href == '#') { bgneal@5: href = null; bgneal@5: } bgneal@5: bgneal@5: if (selectedOpts.type) { bgneal@5: type = selectedOpts.type; bgneal@5: bgneal@5: if (!href) { bgneal@5: href = selectedOpts.content; bgneal@5: } bgneal@5: bgneal@5: } else if (selectedOpts.content) { bgneal@5: type = 'html'; bgneal@5: bgneal@5: } else if (href) { bgneal@5: if (href.match(imgRegExp)) { bgneal@5: type = 'image'; bgneal@5: bgneal@5: } else if (href.match(swfRegExp)) { bgneal@5: type = 'swf'; bgneal@5: bgneal@5: } else if ($(obj).hasClass("iframe")) { bgneal@5: type = 'iframe'; bgneal@5: bgneal@5: } else if (href.indexOf("#") === 0) { bgneal@5: type = 'inline'; bgneal@5: bgneal@5: } else { bgneal@5: type = 'ajax'; bgneal@5: } bgneal@5: } bgneal@5: bgneal@5: if (!type) { bgneal@5: _error(); bgneal@5: return; bgneal@5: } bgneal@5: bgneal@5: if (type == 'inline') { bgneal@5: obj = href.substr(href.indexOf("#")); bgneal@5: type = $(obj).length > 0 ? 'inline' : 'ajax'; bgneal@5: } bgneal@5: bgneal@5: selectedOpts.type = type; bgneal@5: selectedOpts.href = href; bgneal@5: selectedOpts.title = title; bgneal@5: bgneal@5: if (selectedOpts.autoDimensions) { bgneal@5: if (selectedOpts.type == 'html' || selectedOpts.type == 'inline' || selectedOpts.type == 'ajax') { bgneal@5: selectedOpts.width = 'auto'; bgneal@5: selectedOpts.height = 'auto'; bgneal@5: } else { bgneal@5: selectedOpts.autoDimensions = false; bgneal@5: } bgneal@5: } bgneal@5: bgneal@5: if (selectedOpts.modal) { bgneal@5: selectedOpts.overlayShow = true; bgneal@5: selectedOpts.hideOnOverlayClick = false; bgneal@5: selectedOpts.hideOnContentClick = false; bgneal@5: selectedOpts.enableEscapeButton = false; bgneal@5: selectedOpts.showCloseButton = false; bgneal@5: } bgneal@5: bgneal@5: selectedOpts.padding = parseInt(selectedOpts.padding, 10); bgneal@5: selectedOpts.margin = parseInt(selectedOpts.margin, 10); bgneal@5: bgneal@5: tmp.css('padding', (selectedOpts.padding + selectedOpts.margin)); bgneal@5: bgneal@5: $('.fancybox-inline-tmp').unbind('fancybox-cancel').bind('fancybox-change', function() { bgneal@5: $(this).replaceWith(content.children()); bgneal@5: }); bgneal@5: bgneal@5: switch (type) { bgneal@5: case 'html' : bgneal@5: tmp.html( selectedOpts.content ); bgneal@5: _process_inline(); bgneal@5: break; bgneal@5: bgneal@5: case 'inline' : bgneal@5: if ( $(obj).parent().is('#fancybox-content') === true) { bgneal@5: busy = false; bgneal@5: return; bgneal@5: } bgneal@5: bgneal@5: $('
') bgneal@5: .hide() bgneal@5: .insertBefore( $(obj) ) bgneal@5: .bind('fancybox-cleanup', function() { bgneal@5: $(this).replaceWith(content.children()); bgneal@5: }).bind('fancybox-cancel', function() { bgneal@5: $(this).replaceWith(tmp.children()); bgneal@5: }); bgneal@5: bgneal@5: $(obj).appendTo(tmp); bgneal@5: bgneal@5: _process_inline(); bgneal@5: break; bgneal@5: bgneal@5: case 'image': bgneal@5: busy = false; bgneal@5: bgneal@5: $.fancybox.showActivity(); bgneal@5: bgneal@5: imgPreloader = new Image(); bgneal@5: bgneal@5: imgPreloader.onerror = function() { bgneal@5: _error(); bgneal@5: }; bgneal@5: bgneal@5: imgPreloader.onload = function() { bgneal@5: busy = true; bgneal@5: bgneal@5: imgPreloader.onerror = imgPreloader.onload = null; bgneal@5: bgneal@5: _process_image(); bgneal@5: }; bgneal@5: bgneal@5: imgPreloader.src = href; bgneal@5: break; bgneal@5: bgneal@5: case 'swf': bgneal@5: selectedOpts.scrolling = 'no'; bgneal@5: bgneal@5: str = ''; bgneal@5: emb = ''; bgneal@5: bgneal@5: $.each(selectedOpts.swf, function(name, val) { bgneal@5: str += ''; bgneal@5: emb += ' ' + name + '="' + val + '"'; bgneal@5: }); bgneal@5: bgneal@5: str += ''; bgneal@5: bgneal@5: tmp.html(str); bgneal@5: bgneal@5: _process_inline(); bgneal@5: break; bgneal@5: bgneal@5: case 'ajax': bgneal@5: busy = false; bgneal@5: bgneal@5: $.fancybox.showActivity(); bgneal@5: bgneal@5: selectedOpts.ajax.win = selectedOpts.ajax.success; bgneal@5: bgneal@5: ajaxLoader = $.ajax($.extend({}, selectedOpts.ajax, { bgneal@5: url : href, bgneal@5: data : selectedOpts.ajax.data || {}, bgneal@5: error : function(XMLHttpRequest, textStatus, errorThrown) { bgneal@5: if ( XMLHttpRequest.status > 0 ) { bgneal@5: _error(); bgneal@5: } bgneal@5: }, bgneal@5: success : function(data, textStatus, XMLHttpRequest) { bgneal@5: var o = typeof XMLHttpRequest == 'object' ? XMLHttpRequest : ajaxLoader; bgneal@5: if (o.status == 200) { bgneal@5: if ( typeof selectedOpts.ajax.win == 'function' ) { bgneal@5: ret = selectedOpts.ajax.win(href, data, textStatus, XMLHttpRequest); bgneal@5: bgneal@5: if (ret === false) { bgneal@5: loading.hide(); bgneal@5: return; bgneal@5: } else if (typeof ret == 'string' || typeof ret == 'object') { bgneal@5: data = ret; bgneal@5: } bgneal@5: } bgneal@5: bgneal@5: tmp.html( data ); bgneal@5: _process_inline(); bgneal@5: } bgneal@5: } bgneal@5: })); bgneal@5: bgneal@5: break; bgneal@5: bgneal@5: case 'iframe': bgneal@5: _show(); bgneal@5: break; bgneal@5: } bgneal@5: }, bgneal@5: bgneal@5: _process_inline = function() { bgneal@5: var bgneal@5: w = selectedOpts.width, bgneal@5: h = selectedOpts.height; bgneal@5: bgneal@5: if (w.toString().indexOf('%') > -1) { bgneal@5: w = parseInt( ($(window).width() - (selectedOpts.margin * 2)) * parseFloat(w) / 100, 10) + 'px'; bgneal@5: bgneal@5: } else { bgneal@5: w = w == 'auto' ? 'auto' : w + 'px'; bgneal@5: } bgneal@5: bgneal@5: if (h.toString().indexOf('%') > -1) { bgneal@5: h = parseInt( ($(window).height() - (selectedOpts.margin * 2)) * parseFloat(h) / 100, 10) + 'px'; bgneal@5: bgneal@5: } else { bgneal@5: h = h == 'auto' ? 'auto' : h + 'px'; bgneal@5: } bgneal@5: bgneal@5: tmp.wrapInner('
'); bgneal@5: bgneal@5: selectedOpts.width = tmp.width(); bgneal@5: selectedOpts.height = tmp.height(); bgneal@5: bgneal@5: _show(); bgneal@5: }, bgneal@5: bgneal@5: _process_image = function() { bgneal@5: selectedOpts.width = imgPreloader.width; bgneal@5: selectedOpts.height = imgPreloader.height; bgneal@5: bgneal@5: $("").attr({ bgneal@5: 'id' : 'fancybox-img', bgneal@5: 'src' : imgPreloader.src, bgneal@5: 'alt' : selectedOpts.title bgneal@5: }).appendTo( tmp ); bgneal@5: bgneal@5: _show(); bgneal@5: }, bgneal@5: bgneal@5: _show = function() { bgneal@5: var pos, equal; bgneal@5: bgneal@5: loading.hide(); bgneal@5: bgneal@5: if (wrap.is(":visible") && false === currentOpts.onCleanup(currentArray, currentIndex, currentOpts)) { bgneal@5: $.event.trigger('fancybox-cancel'); bgneal@5: bgneal@5: busy = false; bgneal@5: return; bgneal@5: } bgneal@5: bgneal@5: busy = true; bgneal@5: bgneal@5: $(content.add( overlay )).unbind(); bgneal@5: bgneal@5: $(window).unbind("resize.fb scroll.fb"); bgneal@5: $(document).unbind('keydown.fb'); bgneal@5: bgneal@5: if (wrap.is(":visible") && currentOpts.titlePosition !== 'outside') { bgneal@5: wrap.css('height', wrap.height()); bgneal@5: } bgneal@5: bgneal@5: currentArray = selectedArray; bgneal@5: currentIndex = selectedIndex; bgneal@5: currentOpts = selectedOpts; bgneal@5: bgneal@5: if (currentOpts.overlayShow) { bgneal@5: overlay.css({ bgneal@5: 'background-color' : currentOpts.overlayColor, bgneal@5: 'opacity' : currentOpts.overlayOpacity, bgneal@5: 'cursor' : currentOpts.hideOnOverlayClick ? 'pointer' : 'auto', bgneal@5: 'height' : $(document).height() bgneal@5: }); bgneal@5: bgneal@5: if (!overlay.is(':visible')) { bgneal@5: if (isIE6) { bgneal@5: $('select:not(#fancybox-tmp select)').filter(function() { bgneal@5: return this.style.visibility !== 'hidden'; bgneal@5: }).css({'visibility' : 'hidden'}).one('fancybox-cleanup', function() { bgneal@5: this.style.visibility = 'inherit'; bgneal@5: }); bgneal@5: } bgneal@5: bgneal@5: overlay.show(); bgneal@5: } bgneal@5: } else { bgneal@5: overlay.hide(); bgneal@5: } bgneal@5: bgneal@5: final_pos = _get_zoom_to(); bgneal@5: bgneal@5: _process_title(); bgneal@5: bgneal@5: if (wrap.is(":visible")) { bgneal@5: $( close.add( nav_left ).add( nav_right ) ).hide(); bgneal@5: bgneal@5: pos = wrap.position(), bgneal@5: bgneal@5: start_pos = { bgneal@5: top : pos.top, bgneal@5: left : pos.left, bgneal@5: width : wrap.width(), bgneal@5: height : wrap.height() bgneal@5: }; bgneal@5: bgneal@5: equal = (start_pos.width == final_pos.width && start_pos.height == final_pos.height); bgneal@5: bgneal@5: content.fadeTo(currentOpts.changeFade, 0.3, function() { bgneal@5: var finish_resizing = function() { bgneal@5: content.html( tmp.contents() ).fadeTo(currentOpts.changeFade, 1, _finish); bgneal@5: }; bgneal@5: bgneal@5: $.event.trigger('fancybox-change'); bgneal@5: bgneal@5: content bgneal@5: .empty() bgneal@5: .removeAttr('filter') bgneal@5: .css({ bgneal@5: 'border-width' : currentOpts.padding, bgneal@5: 'width' : final_pos.width - currentOpts.padding * 2, bgneal@5: 'height' : selectedOpts.autoDimensions ? 'auto' : final_pos.height - titleHeight - currentOpts.padding * 2 bgneal@5: }); bgneal@5: bgneal@5: if (equal) { bgneal@5: finish_resizing(); bgneal@5: bgneal@5: } else { bgneal@5: fx.prop = 0; bgneal@5: bgneal@5: $(fx).animate({prop: 1}, { bgneal@5: duration : currentOpts.changeSpeed, bgneal@5: easing : currentOpts.easingChange, bgneal@5: step : _draw, bgneal@5: complete : finish_resizing bgneal@5: }); bgneal@5: } bgneal@5: }); bgneal@5: bgneal@5: return; bgneal@5: } bgneal@5: bgneal@5: wrap.removeAttr("style"); bgneal@5: bgneal@5: content.css('border-width', currentOpts.padding); bgneal@5: bgneal@5: if (currentOpts.transitionIn == 'elastic') { bgneal@5: start_pos = _get_zoom_from(); bgneal@5: bgneal@5: content.html( tmp.contents() ); bgneal@5: bgneal@5: wrap.show(); bgneal@5: bgneal@5: if (currentOpts.opacity) { bgneal@5: final_pos.opacity = 0; bgneal@5: } bgneal@5: bgneal@5: fx.prop = 0; bgneal@5: bgneal@5: $(fx).animate({prop: 1}, { bgneal@5: duration : currentOpts.speedIn, bgneal@5: easing : currentOpts.easingIn, bgneal@5: step : _draw, bgneal@5: complete : _finish bgneal@5: }); bgneal@5: bgneal@5: return; bgneal@5: } bgneal@5: bgneal@5: if (currentOpts.titlePosition == 'inside' && titleHeight > 0) { bgneal@5: title.show(); bgneal@5: } bgneal@5: bgneal@5: content bgneal@5: .css({ bgneal@5: 'width' : final_pos.width - currentOpts.padding * 2, bgneal@5: 'height' : selectedOpts.autoDimensions ? 'auto' : final_pos.height - titleHeight - currentOpts.padding * 2 bgneal@5: }) bgneal@5: .html( tmp.contents() ); bgneal@5: bgneal@5: wrap bgneal@5: .css(final_pos) bgneal@5: .fadeIn( currentOpts.transitionIn == 'none' ? 0 : currentOpts.speedIn, _finish ); bgneal@5: }, bgneal@5: bgneal@5: _format_title = function(title) { bgneal@5: if (title && title.length) { bgneal@5: if (currentOpts.titlePosition == 'float') { bgneal@5: return '
' + title + '
'; bgneal@5: } bgneal@5: bgneal@5: return '
' + title + '
'; bgneal@5: } bgneal@5: bgneal@5: return false; bgneal@5: }, bgneal@5: bgneal@5: _process_title = function() { bgneal@5: titleStr = currentOpts.title || ''; bgneal@5: titleHeight = 0; bgneal@5: bgneal@5: title bgneal@5: .empty() bgneal@5: .removeAttr('style') bgneal@5: .removeClass(); bgneal@5: bgneal@5: if (currentOpts.titleShow === false) { bgneal@5: title.hide(); bgneal@5: return; bgneal@5: } bgneal@5: bgneal@5: titleStr = $.isFunction(currentOpts.titleFormat) ? currentOpts.titleFormat(titleStr, currentArray, currentIndex, currentOpts) : _format_title(titleStr); bgneal@5: bgneal@5: if (!titleStr || titleStr === '') { bgneal@5: title.hide(); bgneal@5: return; bgneal@5: } bgneal@5: bgneal@5: title bgneal@5: .addClass('fancybox-title-' + currentOpts.titlePosition) bgneal@5: .html( titleStr ) bgneal@5: .appendTo( 'body' ) bgneal@5: .show(); bgneal@5: bgneal@5: switch (currentOpts.titlePosition) { bgneal@5: case 'inside': bgneal@5: title bgneal@5: .css({ bgneal@5: 'width' : final_pos.width - (currentOpts.padding * 2), bgneal@5: 'marginLeft' : currentOpts.padding, bgneal@5: 'marginRight' : currentOpts.padding bgneal@5: }); bgneal@5: bgneal@5: titleHeight = title.outerHeight(true); bgneal@5: bgneal@5: title.appendTo( outer ); bgneal@5: bgneal@5: final_pos.height += titleHeight; bgneal@5: break; bgneal@5: bgneal@5: case 'over': bgneal@5: title bgneal@5: .css({ bgneal@5: 'marginLeft' : currentOpts.padding, bgneal@5: 'width' : final_pos.width - (currentOpts.padding * 2), bgneal@5: 'bottom' : currentOpts.padding bgneal@5: }) bgneal@5: .appendTo( outer ); bgneal@5: break; bgneal@5: bgneal@5: case 'float': bgneal@5: title bgneal@5: .css('left', parseInt((title.width() - final_pos.width - 40)/ 2, 10) * -1) bgneal@5: .appendTo( wrap ); bgneal@5: break; bgneal@5: bgneal@5: default: bgneal@5: title bgneal@5: .css({ bgneal@5: 'width' : final_pos.width - (currentOpts.padding * 2), bgneal@5: 'paddingLeft' : currentOpts.padding, bgneal@5: 'paddingRight' : currentOpts.padding bgneal@5: }) bgneal@5: .appendTo( wrap ); bgneal@5: break; bgneal@5: } bgneal@5: bgneal@5: title.hide(); bgneal@5: }, bgneal@5: bgneal@5: _set_navigation = function() { bgneal@5: if (currentOpts.enableEscapeButton || currentOpts.enableKeyboardNav) { bgneal@5: $(document).bind('keydown.fb', function(e) { bgneal@5: if (e.keyCode == 27 && currentOpts.enableEscapeButton) { bgneal@5: e.preventDefault(); bgneal@5: $.fancybox.close(); bgneal@5: bgneal@5: } else if ((e.keyCode == 37 || e.keyCode == 39) && currentOpts.enableKeyboardNav && e.target.tagName !== 'INPUT' && e.target.tagName !== 'TEXTAREA' && e.target.tagName !== 'SELECT') { bgneal@5: e.preventDefault(); bgneal@5: $.fancybox[ e.keyCode == 37 ? 'prev' : 'next'](); bgneal@5: } bgneal@5: }); bgneal@5: } bgneal@5: bgneal@5: if (!currentOpts.showNavArrows) { bgneal@5: nav_left.hide(); bgneal@5: nav_right.hide(); bgneal@5: return; bgneal@5: } bgneal@5: bgneal@5: if ((currentOpts.cyclic && currentArray.length > 1) || currentIndex !== 0) { bgneal@5: nav_left.show(); bgneal@5: } bgneal@5: bgneal@5: if ((currentOpts.cyclic && currentArray.length > 1) || currentIndex != (currentArray.length -1)) { bgneal@5: nav_right.show(); bgneal@5: } bgneal@5: }, bgneal@5: bgneal@5: _finish = function () { bgneal@5: if (!$.support.opacity) { bgneal@5: content.get(0).style.removeAttribute('filter'); bgneal@5: wrap.get(0).style.removeAttribute('filter'); bgneal@5: } bgneal@5: bgneal@5: if (selectedOpts.autoDimensions) { bgneal@5: content.css('height', 'auto'); bgneal@5: } bgneal@5: bgneal@5: wrap.css('height', 'auto'); bgneal@5: bgneal@5: if (titleStr && titleStr.length) { bgneal@5: title.show(); bgneal@5: } bgneal@5: bgneal@5: if (currentOpts.showCloseButton) { bgneal@5: close.show(); bgneal@5: } bgneal@5: bgneal@5: _set_navigation(); bgneal@5: bgneal@5: if (currentOpts.hideOnContentClick) { bgneal@5: content.bind('click', $.fancybox.close); bgneal@5: } bgneal@5: bgneal@5: if (currentOpts.hideOnOverlayClick) { bgneal@5: overlay.bind('click', $.fancybox.close); bgneal@5: } bgneal@5: bgneal@5: $(window).bind("resize.fb", $.fancybox.resize); bgneal@5: bgneal@5: if (currentOpts.centerOnScroll) { bgneal@5: $(window).bind("scroll.fb", $.fancybox.center); bgneal@5: } bgneal@5: bgneal@5: if (currentOpts.type == 'iframe') { bgneal@5: $('').appendTo(content); bgneal@5: } bgneal@5: bgneal@5: wrap.show(); bgneal@5: bgneal@5: busy = false; bgneal@5: bgneal@5: $.fancybox.center(); bgneal@5: bgneal@5: currentOpts.onComplete(currentArray, currentIndex, currentOpts); bgneal@5: bgneal@5: _preload_images(); bgneal@5: }, bgneal@5: bgneal@5: _preload_images = function() { bgneal@5: var href, bgneal@5: objNext; bgneal@5: bgneal@5: if ((currentArray.length -1) > currentIndex) { bgneal@5: href = currentArray[ currentIndex + 1 ].href; bgneal@5: bgneal@5: if (typeof href !== 'undefined' && href.match(imgRegExp)) { bgneal@5: objNext = new Image(); bgneal@5: objNext.src = href; bgneal@5: } bgneal@5: } bgneal@5: bgneal@5: if (currentIndex > 0) { bgneal@5: href = currentArray[ currentIndex - 1 ].href; bgneal@5: bgneal@5: if (typeof href !== 'undefined' && href.match(imgRegExp)) { bgneal@5: objNext = new Image(); bgneal@5: objNext.src = href; bgneal@5: } bgneal@5: } bgneal@5: }, bgneal@5: bgneal@5: _draw = function(pos) { bgneal@5: var dim = { bgneal@5: width : parseInt(start_pos.width + (final_pos.width - start_pos.width) * pos, 10), bgneal@5: height : parseInt(start_pos.height + (final_pos.height - start_pos.height) * pos, 10), bgneal@5: bgneal@5: top : parseInt(start_pos.top + (final_pos.top - start_pos.top) * pos, 10), bgneal@5: left : parseInt(start_pos.left + (final_pos.left - start_pos.left) * pos, 10) bgneal@5: }; bgneal@5: bgneal@5: if (typeof final_pos.opacity !== 'undefined') { bgneal@5: dim.opacity = pos < 0.5 ? 0.5 : pos; bgneal@5: } bgneal@5: bgneal@5: wrap.css(dim); bgneal@5: bgneal@5: content.css({ bgneal@5: 'width' : dim.width - currentOpts.padding * 2, bgneal@5: 'height' : dim.height - (titleHeight * pos) - currentOpts.padding * 2 bgneal@5: }); bgneal@5: }, bgneal@5: bgneal@5: _get_viewport = function() { bgneal@5: return [ bgneal@5: $(window).width() - (currentOpts.margin * 2), bgneal@5: $(window).height() - (currentOpts.margin * 2), bgneal@5: $(document).scrollLeft() + currentOpts.margin, bgneal@5: $(document).scrollTop() + currentOpts.margin bgneal@5: ]; bgneal@5: }, bgneal@5: bgneal@5: _get_zoom_to = function () { bgneal@5: var view = _get_viewport(), bgneal@5: to = {}, bgneal@5: resize = currentOpts.autoScale, bgneal@5: double_padding = currentOpts.padding * 2, bgneal@5: ratio; bgneal@5: bgneal@5: if (currentOpts.width.toString().indexOf('%') > -1) { bgneal@5: to.width = parseInt((view[0] * parseFloat(currentOpts.width)) / 100, 10); bgneal@5: } else { bgneal@5: to.width = currentOpts.width + double_padding; bgneal@5: } bgneal@5: bgneal@5: if (currentOpts.height.toString().indexOf('%') > -1) { bgneal@5: to.height = parseInt((view[1] * parseFloat(currentOpts.height)) / 100, 10); bgneal@5: } else { bgneal@5: to.height = currentOpts.height + double_padding; bgneal@5: } bgneal@5: bgneal@5: if (resize && (to.width > view[0] || to.height > view[1])) { bgneal@5: if (selectedOpts.type == 'image' || selectedOpts.type == 'swf') { bgneal@5: ratio = (currentOpts.width ) / (currentOpts.height ); bgneal@5: bgneal@5: if ((to.width ) > view[0]) { bgneal@5: to.width = view[0]; bgneal@5: to.height = parseInt(((to.width - double_padding) / ratio) + double_padding, 10); bgneal@5: } bgneal@5: bgneal@5: if ((to.height) > view[1]) { bgneal@5: to.height = view[1]; bgneal@5: to.width = parseInt(((to.height - double_padding) * ratio) + double_padding, 10); bgneal@5: } bgneal@5: bgneal@5: } else { bgneal@5: to.width = Math.min(to.width, view[0]); bgneal@5: to.height = Math.min(to.height, view[1]); bgneal@5: } bgneal@5: } bgneal@5: bgneal@5: to.top = parseInt(Math.max(view[3] - 20, view[3] + ((view[1] - to.height - 40) * 0.5)), 10); bgneal@5: to.left = parseInt(Math.max(view[2] - 20, view[2] + ((view[0] - to.width - 40) * 0.5)), 10); bgneal@5: bgneal@5: return to; bgneal@5: }, bgneal@5: bgneal@5: _get_obj_pos = function(obj) { bgneal@5: var pos = obj.offset(); bgneal@5: bgneal@5: pos.top += parseInt( obj.css('paddingTop'), 10 ) || 0; bgneal@5: pos.left += parseInt( obj.css('paddingLeft'), 10 ) || 0; bgneal@5: bgneal@5: pos.top += parseInt( obj.css('border-top-width'), 10 ) || 0; bgneal@5: pos.left += parseInt( obj.css('border-left-width'), 10 ) || 0; bgneal@5: bgneal@5: pos.width = obj.width(); bgneal@5: pos.height = obj.height(); bgneal@5: bgneal@5: return pos; bgneal@5: }, bgneal@5: bgneal@5: _get_zoom_from = function() { bgneal@5: var orig = selectedOpts.orig ? $(selectedOpts.orig) : false, bgneal@5: from = {}, bgneal@5: pos, bgneal@5: view; bgneal@5: bgneal@5: if (orig && orig.length) { bgneal@5: pos = _get_obj_pos(orig); bgneal@5: bgneal@5: from = { bgneal@5: width : pos.width + (currentOpts.padding * 2), bgneal@5: height : pos.height + (currentOpts.padding * 2), bgneal@5: top : pos.top - currentOpts.padding - 20, bgneal@5: left : pos.left - currentOpts.padding - 20 bgneal@5: }; bgneal@5: bgneal@5: } else { bgneal@5: view = _get_viewport(); bgneal@5: bgneal@5: from = { bgneal@5: width : currentOpts.padding * 2, bgneal@5: height : currentOpts.padding * 2, bgneal@5: top : parseInt(view[3] + view[1] * 0.5, 10), bgneal@5: left : parseInt(view[2] + view[0] * 0.5, 10) bgneal@5: }; bgneal@5: } bgneal@5: bgneal@5: return from; bgneal@5: }, bgneal@5: bgneal@5: _animate_loading = function() { bgneal@5: if (!loading.is(':visible')){ bgneal@5: clearInterval(loadingTimer); bgneal@5: return; bgneal@5: } bgneal@5: bgneal@5: $('div', loading).css('top', (loadingFrame * -40) + 'px'); bgneal@5: bgneal@5: loadingFrame = (loadingFrame + 1) % 12; bgneal@5: }; bgneal@5: bgneal@5: /* bgneal@5: * Public methods bgneal@5: */ bgneal@5: bgneal@5: $.fn.fancybox = function(options) { bgneal@5: if (!$(this).length) { bgneal@5: return this; bgneal@5: } bgneal@5: bgneal@5: $(this) bgneal@5: .data('fancybox', $.extend({}, options, ($.metadata ? $(this).metadata() : {}))) bgneal@5: .unbind('click.fb') bgneal@5: .bind('click.fb', function(e) { bgneal@5: e.preventDefault(); bgneal@5: bgneal@5: if (busy) { bgneal@5: return; bgneal@5: } bgneal@5: bgneal@5: busy = true; bgneal@5: bgneal@5: $(this).blur(); bgneal@5: bgneal@5: selectedArray = []; bgneal@5: selectedIndex = 0; bgneal@5: bgneal@5: var rel = $(this).attr('rel') || ''; bgneal@5: bgneal@5: if (!rel || rel == '' || rel === 'nofollow') { bgneal@5: selectedArray.push(this); bgneal@5: bgneal@5: } else { bgneal@5: selectedArray = $("a[rel=" + rel + "], area[rel=" + rel + "]"); bgneal@5: selectedIndex = selectedArray.index( this ); bgneal@5: } bgneal@5: bgneal@5: _start(); bgneal@5: bgneal@5: return; bgneal@5: }); bgneal@5: bgneal@5: return this; bgneal@5: }; bgneal@5: bgneal@5: $.fancybox = function(obj) { bgneal@5: var opts; bgneal@5: bgneal@5: if (busy) { bgneal@5: return; bgneal@5: } bgneal@5: bgneal@5: busy = true; bgneal@5: opts = typeof arguments[1] !== 'undefined' ? arguments[1] : {}; bgneal@5: bgneal@5: selectedArray = []; bgneal@5: selectedIndex = parseInt(opts.index, 10) || 0; bgneal@5: bgneal@5: if ($.isArray(obj)) { bgneal@5: for (var i = 0, j = obj.length; i < j; i++) { bgneal@5: if (typeof obj[i] == 'object') { bgneal@5: $(obj[i]).data('fancybox', $.extend({}, opts, obj[i])); bgneal@5: } else { bgneal@5: obj[i] = $({}).data('fancybox', $.extend({content : obj[i]}, opts)); bgneal@5: } bgneal@5: } bgneal@5: bgneal@5: selectedArray = jQuery.merge(selectedArray, obj); bgneal@5: bgneal@5: } else { bgneal@5: if (typeof obj == 'object') { bgneal@5: $(obj).data('fancybox', $.extend({}, opts, obj)); bgneal@5: } else { bgneal@5: obj = $({}).data('fancybox', $.extend({content : obj}, opts)); bgneal@5: } bgneal@5: bgneal@5: selectedArray.push(obj); bgneal@5: } bgneal@5: bgneal@5: if (selectedIndex > selectedArray.length || selectedIndex < 0) { bgneal@5: selectedIndex = 0; bgneal@5: } bgneal@5: bgneal@5: _start(); bgneal@5: }; bgneal@5: bgneal@5: $.fancybox.showActivity = function() { bgneal@5: clearInterval(loadingTimer); bgneal@5: bgneal@5: loading.show(); bgneal@5: loadingTimer = setInterval(_animate_loading, 66); bgneal@5: }; bgneal@5: bgneal@5: $.fancybox.hideActivity = function() { bgneal@5: loading.hide(); bgneal@5: }; bgneal@5: bgneal@5: $.fancybox.next = function() { bgneal@5: return $.fancybox.pos( currentIndex + 1); bgneal@5: }; bgneal@5: bgneal@5: $.fancybox.prev = function() { bgneal@5: return $.fancybox.pos( currentIndex - 1); bgneal@5: }; bgneal@5: bgneal@5: $.fancybox.pos = function(pos) { bgneal@5: if (busy) { bgneal@5: return; bgneal@5: } bgneal@5: bgneal@5: pos = parseInt(pos); bgneal@5: bgneal@5: selectedArray = currentArray; bgneal@5: bgneal@5: if (pos > -1 && pos < currentArray.length) { bgneal@5: selectedIndex = pos; bgneal@5: _start(); bgneal@5: bgneal@5: } else if (currentOpts.cyclic && currentArray.length > 1) { bgneal@5: selectedIndex = pos >= currentArray.length ? 0 : currentArray.length - 1; bgneal@5: _start(); bgneal@5: } bgneal@5: bgneal@5: return; bgneal@5: }; bgneal@5: bgneal@5: $.fancybox.cancel = function() { bgneal@5: if (busy) { bgneal@5: return; bgneal@5: } bgneal@5: bgneal@5: busy = true; bgneal@5: bgneal@5: $.event.trigger('fancybox-cancel'); bgneal@5: bgneal@5: _abort(); bgneal@5: bgneal@5: selectedOpts.onCancel(selectedArray, selectedIndex, selectedOpts); bgneal@5: bgneal@5: busy = false; bgneal@5: }; bgneal@5: bgneal@5: // Note: within an iframe use - parent.$.fancybox.close(); bgneal@5: $.fancybox.close = function() { bgneal@5: if (busy || wrap.is(':hidden')) { bgneal@5: return; bgneal@5: } bgneal@5: bgneal@5: busy = true; bgneal@5: bgneal@5: if (currentOpts && false === currentOpts.onCleanup(currentArray, currentIndex, currentOpts)) { bgneal@5: busy = false; bgneal@5: return; bgneal@5: } bgneal@5: bgneal@5: _abort(); bgneal@5: bgneal@5: $(close.add( nav_left ).add( nav_right )).hide(); bgneal@5: bgneal@5: $(content.add( overlay )).unbind(); bgneal@5: bgneal@5: $(window).unbind("resize.fb scroll.fb"); bgneal@5: $(document).unbind('keydown.fb'); bgneal@5: bgneal@5: content.find('iframe').attr('src', isIE6 && /^https/i.test(window.location.href || '') ? 'javascript:void(false)' : 'about:blank'); bgneal@5: bgneal@5: if (currentOpts.titlePosition !== 'inside') { bgneal@5: title.empty(); bgneal@5: } bgneal@5: bgneal@5: wrap.stop(); bgneal@5: bgneal@5: function _cleanup() { bgneal@5: overlay.fadeOut('fast'); bgneal@5: bgneal@5: title.empty().hide(); bgneal@5: wrap.hide(); bgneal@5: bgneal@5: $.event.trigger('fancybox-cleanup'); bgneal@5: bgneal@5: content.empty(); bgneal@5: bgneal@5: currentOpts.onClosed(currentArray, currentIndex, currentOpts); bgneal@5: bgneal@5: currentArray = selectedOpts = []; bgneal@5: currentIndex = selectedIndex = 0; bgneal@5: currentOpts = selectedOpts = {}; bgneal@5: bgneal@5: busy = false; bgneal@5: } bgneal@5: bgneal@5: if (currentOpts.transitionOut == 'elastic') { bgneal@5: start_pos = _get_zoom_from(); bgneal@5: bgneal@5: var pos = wrap.position(); bgneal@5: bgneal@5: final_pos = { bgneal@5: top : pos.top , bgneal@5: left : pos.left, bgneal@5: width : wrap.width(), bgneal@5: height : wrap.height() bgneal@5: }; bgneal@5: bgneal@5: if (currentOpts.opacity) { bgneal@5: final_pos.opacity = 1; bgneal@5: } bgneal@5: bgneal@5: title.empty().hide(); bgneal@5: bgneal@5: fx.prop = 1; bgneal@5: bgneal@5: $(fx).animate({ prop: 0 }, { bgneal@5: duration : currentOpts.speedOut, bgneal@5: easing : currentOpts.easingOut, bgneal@5: step : _draw, bgneal@5: complete : _cleanup bgneal@5: }); bgneal@5: bgneal@5: } else { bgneal@5: wrap.fadeOut( currentOpts.transitionOut == 'none' ? 0 : currentOpts.speedOut, _cleanup); bgneal@5: } bgneal@5: }; bgneal@5: bgneal@5: $.fancybox.resize = function() { bgneal@5: if (overlay.is(':visible')) { bgneal@5: overlay.css('height', $(document).height()); bgneal@5: } bgneal@5: bgneal@5: $.fancybox.center(true); bgneal@5: }; bgneal@5: bgneal@5: $.fancybox.center = function() { bgneal@5: var view, align; bgneal@5: bgneal@5: if (busy) { bgneal@5: return; bgneal@5: } bgneal@5: bgneal@5: align = arguments[0] === true ? 1 : 0; bgneal@5: view = _get_viewport(); bgneal@5: bgneal@5: if (!align && (wrap.width() > view[0] || wrap.height() > view[1])) { bgneal@5: return; bgneal@5: } bgneal@5: bgneal@5: wrap bgneal@5: .stop() bgneal@5: .animate({ bgneal@5: 'top' : parseInt(Math.max(view[3] - 20, view[3] + ((view[1] - content.height() - 40) * 0.5) - currentOpts.padding)), bgneal@5: 'left' : parseInt(Math.max(view[2] - 20, view[2] + ((view[0] - content.width() - 40) * 0.5) - currentOpts.padding)) bgneal@5: }, typeof arguments[0] == 'number' ? arguments[0] : 200); bgneal@5: }; bgneal@5: bgneal@5: $.fancybox.init = function() { bgneal@5: if ($("#fancybox-wrap").length) { bgneal@5: return; bgneal@5: } bgneal@5: bgneal@5: $('body').append( bgneal@5: tmp = $('
'), bgneal@5: loading = $('
'), bgneal@5: overlay = $('
'), bgneal@5: wrap = $('
') bgneal@5: ); bgneal@5: bgneal@5: outer = $('
') bgneal@5: .append('
') bgneal@5: .appendTo( wrap ); bgneal@5: bgneal@5: outer.append( bgneal@5: content = $('
'), bgneal@5: close = $(''), bgneal@5: title = $('
'), bgneal@5: bgneal@5: nav_left = $(''), bgneal@5: nav_right = $('') bgneal@5: ); bgneal@5: bgneal@5: close.click($.fancybox.close); bgneal@5: loading.click($.fancybox.cancel); bgneal@5: bgneal@5: nav_left.click(function(e) { bgneal@5: e.preventDefault(); bgneal@5: $.fancybox.prev(); bgneal@5: }); bgneal@5: bgneal@5: nav_right.click(function(e) { bgneal@5: e.preventDefault(); bgneal@5: $.fancybox.next(); bgneal@5: }); bgneal@5: bgneal@5: if ($.fn.mousewheel) { bgneal@5: wrap.bind('mousewheel.fb', function(e, delta) { bgneal@5: if (busy) { bgneal@5: e.preventDefault(); bgneal@5: bgneal@5: } else if ($(e.target).get(0).clientHeight == 0 || $(e.target).get(0).scrollHeight === $(e.target).get(0).clientHeight) { bgneal@5: e.preventDefault(); bgneal@5: $.fancybox[ delta > 0 ? 'prev' : 'next'](); bgneal@5: } bgneal@5: }); bgneal@5: } bgneal@5: bgneal@5: if (!$.support.opacity) { bgneal@5: wrap.addClass('fancybox-ie'); bgneal@5: } bgneal@5: bgneal@5: if (isIE6) { bgneal@5: loading.addClass('fancybox-ie6'); bgneal@5: wrap.addClass('fancybox-ie6'); bgneal@5: bgneal@5: $('').prependTo(outer); bgneal@5: } bgneal@5: }; bgneal@5: bgneal@5: $.fn.fancybox.defaults = { bgneal@5: padding : 10, bgneal@5: margin : 40, bgneal@5: opacity : false, bgneal@5: modal : false, bgneal@5: cyclic : false, bgneal@5: scrolling : 'auto', // 'auto', 'yes' or 'no' bgneal@5: bgneal@5: width : 560, bgneal@5: height : 340, bgneal@5: bgneal@5: autoScale : true, bgneal@5: autoDimensions : true, bgneal@5: centerOnScroll : false, bgneal@5: bgneal@5: ajax : {}, bgneal@5: swf : { wmode: 'transparent' }, bgneal@5: bgneal@5: hideOnOverlayClick : true, bgneal@5: hideOnContentClick : false, bgneal@5: bgneal@5: overlayShow : true, bgneal@5: overlayOpacity : 0.7, bgneal@5: overlayColor : '#777', bgneal@5: bgneal@5: titleShow : true, bgneal@5: titlePosition : 'float', // 'float', 'outside', 'inside' or 'over' bgneal@5: titleFormat : null, bgneal@5: titleFromAlt : false, bgneal@5: bgneal@5: transitionIn : 'fade', // 'elastic', 'fade' or 'none' bgneal@5: transitionOut : 'fade', // 'elastic', 'fade' or 'none' bgneal@5: bgneal@5: speedIn : 300, bgneal@5: speedOut : 300, bgneal@5: bgneal@5: changeSpeed : 300, bgneal@5: changeFade : 'fast', bgneal@5: bgneal@5: easingIn : 'swing', bgneal@5: easingOut : 'swing', bgneal@5: bgneal@5: showCloseButton : true, bgneal@5: showNavArrows : true, bgneal@5: enableEscapeButton : true, bgneal@5: enableKeyboardNav : true, bgneal@5: bgneal@5: onStart : function(){}, bgneal@5: onCancel : function(){}, bgneal@5: onComplete : function(){}, bgneal@5: onCleanup : function(){}, bgneal@5: onClosed : function(){}, bgneal@5: onError : function(){} bgneal@5: }; bgneal@5: bgneal@5: $(document).ready(function() { bgneal@5: $.fancybox.init(); bgneal@5: }); bgneal@5: bgneal@5: })(jQuery);