/* * FancyBox - jQuery Plugin * Simple and fancy lightbox alternative * * Examples and documentation at: http://fancybox.net * * Copyright (c) 2008 - 2010 Janis Skarnelis * 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. * * Version: 1.3.4 (11/11/2010) * Requires: jQuery v1.3+ * * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html */ ;(function($) { var tmp, loading, overlay, wrap, outer, content, close, max, 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($('
')[0], { prop: 0 }), isIE6 = $.browser.msie && $.browser.version < 7 && !window.XMLHttpRequest, /* * Private methods */ _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( '

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

' ); _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; } $('
') .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 = ''; emb = ''; $.each(selectedOpts.swf, function(name, val) { str += ''; emb += ' ' + name + '="' + val + '"'; }); str += ''; 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('
'); selectedOpts.width = tmp.width(); selectedOpts.height = tmp.height(); _show(); }, _process_image = function() { selectedOpts.width = imgPreloader.width; selectedOpts.height = imgPreloader.height; $("").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(); $( max.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 '
' + title + '
'; } return '
' + title + '
'; } 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(); max.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') { content.append('').prependTo(outer); } }; $.fn.fancybox.defaults = { padding : 10, margin : 40, opacity : false, modal : false, cyclic : false, scrolling : 'auto', // 'auto', 'yes' or 'no' 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', // 'float', 'outside', 'inside' or 'over' titleFormat : null, titleFromAlt : false, transitionIn : 'fade', // 'elastic', 'fade' or 'none' transitionOut : 'fade', // 'elastic', 'fade' or 'none' 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); jQuery.fn.extend({ mobilefancybox: function (reloadOnClose,width,height) { if(jQuery.browser.mobile) { $(this).attr('target','_blank'); }else{ $(this).fancybox({ 'width': width, 'height': height, 'autoScale': false, 'transitionIn': 'elastic', 'transitionOut': 'elastic', 'autoDimensions': 'true', 'type': 'iframe', 'onClosed': function() {if(reloadOnClose){parent.location.reload(true);}} }); } } }); function openPopup(url, width,height) { $(document).ready(function() { $.fancybox( url, { 'width': width, 'height': height, 'autoScale': false, 'transitionIn': 'elastic', 'transitionOut': 'elastic', 'autoDimensions': 'true', 'type': 'iframe' }); }); }