UNPKG

fancybox-plus

Version:

jQuery lightbox and modal window plugin.

9 lines 15.3 kB
/* * <%= pkg.title || pkg.name %> - v<%= pkg.version %> * <%= pkg.description %> * <%= pkg.homepage %> * * Made by <%= pkg.author.name %> * Under <%= pkg.license %> License */ !function(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o=0,p={},q=[],r=0,s={},t=[],u=null,v=new Image,w=/\.(jpg|gif|png|bmp|jpeg)(.*)?$/i,x=/[^\.]\.(swf)\s*$/i,y=1,z=0,A="",B=!1,C=a.extend(a("<div/>")[0],{prop:0}),D=navigator.userAgent.match(/msie [6]/i)&&!window.XMLHttpRequest,E=function(){c.hide(),v.onerror=v.onload=null,u&&u.abort(),b.empty()},F=function(){return!1===p.onError(q,o,p)?(c.hide(),void(B=!1)):(p.titleShow=!1,p.width="auto",p.height="auto",b.html('<p id="fbplus-error">The requested content cannot be loaded.<br />Please try again later.</p>'),void H())},G=function(){var d,e,f,h,i,j,k=q[o];if(E(),p=a.extend({},a.fn.fancyboxPlus.defaults,"undefined"==typeof a(k).data("fancyboxPlus")?p:a(k).data("fancyboxPlus")),j=p.onStart(q,o,p),j===!1)return void(B=!1);if("object"==typeof j&&(p=a.extend(p,j)),f=p.title||(k.nodeName?a(k).attr("title"):k.title)||"",k.nodeName&&!p.orig&&(p.orig=a(k).children("img:first").length?a(k).children("img:first"):a(k)),""===f&&p.orig&&p.titleFromAlt&&(f=p.orig.attr("alt")),d=p.href||(k.nodeName?a(k).attr("href"):k.href)||null,(/^(?:javascript)/i.test(d)||"#"==d)&&(d=null),p.type?(e=p.type,d||(d=p.content)):p.content?e="html":d&&(e=d.match(w)?"image":d.match(x)?"swf":a(k).hasClass("iframe")?"iframe":0===d.indexOf("#")?"inline":"ajax"),!e)return void F();switch("inline"==e&&(k=d.substr(d.indexOf("#")),e=a(k).length>0?"inline":"ajax"),p.type=e,p.href=d,p.title=f,p.autoDimensions&&("html"==p.type||"inline"==p.type||"ajax"==p.type?(p.width="auto",p.height="auto"):p.autoDimensions=!1),p.modal&&(p.overlayShow=!0,p.hideOnOverlayClick=!1,p.hideOnContentClick=!1,p.enableEscapeButton=!1,p.showCloseButton=!1),p.padding=parseInt(p.padding,10),p.margin=parseInt(p.margin,10),b.css("padding",p.padding+p.margin),a(".fbplus-inline-tmp").unbind("fbplus-cancel").bind("fbplus-change",function(){a(this).replaceWith(g.children())}),e){case"html":b.html(p.content),H();break;case"inline":if(a(k).parent().is("#fbplus-content")===!0)return void(B=!1);a('<div class="fbplus-inline-tmp" />').hide().insertBefore(a(k)).bind("fbplus-cleanup",function(){a(this).replaceWith(g.children())}).bind("fbplus-cancel",function(){a(this).replaceWith(b.children())}),a(k).appendTo(b),H();break;case"image":B=!1,a.fancyboxPlus.showActivity(),v=new Image,v.onerror=function(){F()},v.onload=function(){B=!0,v.onerror=v.onload=null,I()},v.src=d;break;case"swf":p.scrolling="no",h='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+p.width+'" height="'+p.height+'"><param name="movie" value="'+d+'"></param>',i="",a.each(p.swf,function(a,b){h+='<param name="'+a+'" value="'+b+'"></param>',i+=" "+a+'="'+b+'"'}),h+='<embed src="'+d+'" type="application/x-shockwave-flash" width="'+p.width+'" height="'+p.height+'"'+i+"></embed></object>",b.html(h),H();break;case"ajax":B=!1,a.fancyboxPlus.showActivity(),p.ajax.win=p.ajax.success,u=a.ajax(a.extend({},p.ajax,{url:d,data:p.ajax.data||{},error:function(a,b,c){a.status>0&&F()},success:function(a,e,f){var g="object"==typeof f?f:u;if(200==g.status){if("function"==typeof p.ajax.win){if(j=p.ajax.win(d,a,e,f),j===!1)return void c.hide();"string"!=typeof j&&"object"!=typeof j||(a=j)}b.html(a),H()}}}));break;case"iframe":J()}},H=function(){var c=p.width,d=p.height;c=c.toString().indexOf("%")>-1?parseInt((a(window).width()-2*p.margin)*parseFloat(c)/100,10)+"px":"auto"==c?"auto":c+"px",d=d.toString().indexOf("%")>-1?parseInt((a(window).height()-2*p.margin)*parseFloat(d)/100,10)+"px":"auto"==d?"auto":d+"px",b.wrapInner('<div style="width:'+c+";height:"+d+";overflow: "+("auto"==p.scrolling?"auto":"yes"==p.scrolling?"scroll":"hidden")+';position:relative;"></div>'),p.width=b.width(),p.height=b.height(),J()},I=function(){p.width=v.width,p.height=v.height,a("<img />").attr({id:"fbplus-img",src:v.src,alt:p.title}).appendTo(b),J()},J=function(){var f,l;return c.hide(),e.is(":visible")&&!1===s.onCleanup(t,r,s)?(a.event.trigger("fbplus-cancel"),void(B=!1)):(B=!0,a(g.add(d)).unbind(),a(window).unbind("resize.fb scroll.fb"),a(document).unbind("keydown.fb"),e.is(":visible")&&"outside"!==s.titlePosition&&e.css("height",e.height()),t=q,r=o,s=p,s.overlayShow?(d.css({"background-color":s.overlayColor,opacity:s.overlayOpacity,cursor:s.hideOnOverlayClick?"pointer":"auto",height:a(document).height()}),d.is(":visible")||(D&&a("select:not(#fbplus-tmp select)").filter(function(){return"hidden"!==this.style.visibility}).css({visibility:"hidden"}).one("fbplus-cleanup",function(){this.style.visibility="inherit"}),d.show())):d.hide(),n=R(),L(),e.is(":visible")?(a(h.add(j).add(k)).hide(),f=e.position(),m={top:f.top,left:f.left,width:e.width(),height:e.height()},l=m.width==n.width&&m.height==n.height,void g.fadeTo(s.changeFade,.3,function(){var c=function(){g.html(b.contents()).fadeTo(s.changeFade,1,N)};a.event.trigger("fbplus-change"),g.empty().removeAttr("filter").css({"border-width":s.padding,width:n.width-2*s.padding,height:p.autoDimensions?"auto":n.height-z-2*s.padding}),l?c():(C.prop=0,a(C).animate({prop:1},{duration:s.changeSpeed,easing:s.easingChange,step:P,complete:c}))})):(e.removeAttr("style"),g.css("border-width",s.padding),"elastic"==s.transitionIn?(m=T(),g.html(b.contents()),e.show(),s.opacity&&(n.opacity=0),C.prop=0,void a(C).animate({prop:1},{duration:s.speedIn,easing:s.easingIn,step:P,complete:N})):("inside"==s.titlePosition&&z>0&&i.show(),g.css({width:n.width-2*s.padding,height:p.autoDimensions?"auto":n.height-z-2*s.padding}).html(b.contents()),void e.css(n).fadeIn("none"==s.transitionIn?0:s.speedIn,N))))},K=function(a){return a&&a.length?"float"==s.titlePosition?'<table id="fbplus-title-float-wrap" cellpadding="0" cellspacing="0"><tr><td id="fbplus-title-float-left"></td><td id="fbplus-title-float-main">'+a+'</td><td id="fbplus-title-float-right"></td></tr></table>':'<div id="fbplus-title-'+s.titlePosition+'">'+a+"</div>":!1},L=function(){if(A=s.title||"",z=0,i.empty().removeAttr("style").removeClass(),s.titleShow===!1)return void i.hide();if(A=a.isFunction(s.titleFormat)?s.titleFormat(A,t,r,s):K(A),!A||""===A)return void i.hide();switch(i.addClass("fbplus-title-"+s.titlePosition).html(A).appendTo("body").show(),s.titlePosition){case"inside":i.css({width:n.width-2*s.padding,marginLeft:s.padding,marginRight:s.padding}),z=i.outerHeight(!0),i.appendTo(f),n.height+=z;break;case"over":i.css({marginLeft:s.padding,width:n.width-2*s.padding,bottom:s.padding}).appendTo(f);break;case"float":i.css("left",-1*parseInt((i.width()-n.width-40)/2,10)).appendTo(e);break;default:i.css({width:n.width-2*s.padding,paddingLeft:s.padding,paddingRight:s.padding}).appendTo(e)}i.hide()},M=function(){return(s.enableEscapeButton||s.enableKeyboardNav)&&a(document).bind("keydown.fb",function(b){27==b.keyCode&&s.enableEscapeButton?(b.preventDefault(),a.fancyboxPlus.close()):37!=b.keyCode&&39!=b.keyCode||!s.enableKeyboardNav||"INPUT"===b.target.tagName||"TEXTAREA"===b.target.tagName||"SELECT"===b.target.tagName||(b.preventDefault(),a.fancyboxPlus[37==b.keyCode?"prev":"next"]())}),s.showNavArrows?((s.cyclic&&t.length>1||0!==r)&&j.show(),void((s.cyclic&&t.length>1||r!=t.length-1)&&k.show())):(j.hide(),void k.hide())},N=function(){a.support.opacity||(a("#fancybox-content").css("filter",0),a("#fancybox-wrap").css("filter",0)),p.autoDimensions&&g.css("height","auto"),e.css("height","auto"),A&&A.length&&i.show(),s.showCloseButton&&h.show(),M(),s.hideOnContentClick&&g.bind("click",a.fancyboxPlus.close),s.hideOnOverlayClick&&d.bind("click",a.fancyboxPlus.close),a(window).bind("resize.fb",a.fancyboxPlus.resize),s.centerOnScroll&&a(window).bind("scroll.fb",a.fancyboxPlus.center),"iframe"==s.type&&a('<iframe id="fbplus-frame" name="fbplus-frame'+(new Date).getTime()+'" frameborder="0" hspace="0" '+(navigator.userAgent.match(/msie [6]/i)?'allowtransparency="true""':"")+' scrolling="'+p.scrolling+'" src="'+s.href+'"></iframe>').appendTo(g),e.show(),B=!1,a.fancyboxPlus.center(),s.onComplete(t,r,s),O()},O=function(){var a,b;t.length-1>r&&(a=t[r+1].href,"undefined"!=typeof a&&a.match(w)&&(b=new Image,b.src=a)),r>0&&(a=t[r-1].href,"undefined"!=typeof a&&a.match(w)&&(b=new Image,b.src=a))},P=function(a){var b={width:parseInt(m.width+(n.width-m.width)*a,10),height:parseInt(m.height+(n.height-m.height)*a,10),top:parseInt(m.top+(n.top-m.top)*a,10),left:parseInt(m.left+(n.left-m.left)*a,10)};"undefined"!=typeof n.opacity&&(b.opacity=.5>a?.5:a),e.css(b),g.css({width:b.width-2*s.padding,height:b.height-z*a-2*s.padding})},Q=function(){return[a(window).width()-2*s.margin,a(window).height()-2*s.margin,a(document).scrollLeft()+s.margin,a(document).scrollTop()+s.margin]},R=function(){var a,b=Q(),c={},d=s.autoScale,e=2*s.padding;return s.width.toString().indexOf("%")>-1?c.width=parseInt(b[0]*parseFloat(s.width)/100,10):c.width=s.width+e,s.height.toString().indexOf("%")>-1?c.height=parseInt(b[1]*parseFloat(s.height)/100,10):c.height=s.height+e,d&&(c.width>b[0]||c.height>b[1])&&("image"==p.type||"swf"==p.type?(a=s.width/s.height,c.width>b[0]&&(c.width=b[0],c.height=parseInt((c.width-e)/a+e,10)),c.height>b[1]&&(c.height=b[1],c.width=parseInt((c.height-e)*a+e,10))):(c.width=Math.min(c.width,b[0]),c.height=Math.min(c.height,b[1]))),c.top=parseInt(Math.max(b[3]-20,b[3]+.5*(b[1]-c.height-40)),10),c.left=parseInt(Math.max(b[2]-20,b[2]+.5*(b[0]-c.width-40)),10),c},S=function(a){var b=a.offset();return b.top+=parseInt(a.css("paddingTop"),10)||0,b.left+=parseInt(a.css("paddingLeft"),10)||0,b.top+=parseInt(a.css("border-top-width"),10)||0,b.left+=parseInt(a.css("border-left-width"),10)||0,b.width=a.width(),b.height=a.height(),b},T=function(){var b,c,d=p.orig?a(p.orig):!1,e={};return d&&d.length?(b=S(d),e={width:b.width+2*s.padding,height:b.height+2*s.padding,top:b.top-s.padding-20,left:b.left-s.padding-20}):(c=Q(),e={width:2*s.padding,height:2*s.padding,top:parseInt(c[3]+.5*c[1],10),left:parseInt(c[2]+.5*c[0],10)}),e},U=function(){return c.is(":visible")?(a("div",c).css("top",-40*y+"px"),void(y=(y+1)%12)):void clearInterval(l)};a.fn.fancyboxPlus=function(b){return a(this).length?(a(this).data("fancyboxPlus",a.extend({},b,a.metadata?a(this).metadata():{})).unbind("click.fb").bind("click.fb",function(b){if(b.preventDefault(),!B){B=!0,a(this).blur(),q=[],o=0;var c=a(this).attr("rel")||"";c&&""!=c&&"nofollow"!==c?(q=a("a[rel="+c+"], area[rel="+c+"]"),o=q.index(this)):q.push(this),G()}}),this):this},a.fancyboxPlus=function(b){var c;if(!B){if(B=!0,c="undefined"!=typeof arguments[1]?arguments[1]:{},q=[],o=parseInt(c.index,10)||0,a.isArray(b)){for(var d=0,e=b.length;e>d;d++)"object"==typeof b[d]?a(b[d]).data("fancyboxPlus",a.extend({},c,b[d])):b[d]=a({}).data("fancyboxPlus",a.extend({content:b[d]},c));q=jQuery.merge(q,b)}else"object"==typeof b?a(b).data("fancyboxPlus",a.extend({},c,b)):b=a({}).data("fancyboxPlus",a.extend({content:b},c)),q.push(b);(o>q.length||0>o)&&(o=0),G()}},a.fancyboxPlus.showActivity=function(){clearInterval(l),c.show(),l=setInterval(U,66)},a.fancyboxPlus.hideActivity=function(){c.hide()},a.fancyboxPlus.next=function(){return a.fancyboxPlus.pos(r+1)},a.fancyboxPlus.prev=function(){return a.fancyboxPlus.pos(r-1)},a.fancyboxPlus.pos=function(a){B||(a=parseInt(a),q=t,a>-1&&a<t.length?(o=a,G()):s.cyclic&&t.length>1&&(o=a>=t.length?0:t.length-1,G()))},a.fancyboxPlus.cancel=function(){B||(B=!0,a.event.trigger("fbplus-cancel"),E(),p.onCancel(q,o,p),B=!1)},a.fancyboxPlus.close=function(){function b(){d.fadeOut("fast"),i.empty().hide(),e.hide(),a.event.trigger("fbplus-cleanup"),g.empty(),s.onClosed(t,r,s),t=p=[],r=o=0,s=p={},B=!1}if(!B&&!e.is(":hidden")){if(B=!0,s&&!1===s.onCleanup(t,r,s))return void(B=!1);if(E(),a(h.add(j).add(k)).hide(),a(g.add(d)).unbind(),a(window).unbind("resize.fb scroll.fb"),a(document).unbind("keydown.fb"),g.find("iframe").attr("src",D&&/^https/i.test(window.location.href||"")?"javascript:void(false)":"about:blank"),"inside"!==s.titlePosition&&i.empty(),e.stop(),"elastic"==s.transitionOut){m=T();var c=e.position();n={top:c.top,left:c.left,width:e.width(),height:e.height()},s.opacity&&(n.opacity=1),i.empty().hide(),C.prop=1,a(C).animate({prop:0},{duration:s.speedOut,easing:s.easingOut,step:P,complete:b})}else e.fadeOut("none"==s.transitionOut?0:s.speedOut,b)}},a.fancyboxPlus.resize=function(){d.is(":visible")&&d.css("height",a(document).height()),a.fancyboxPlus.center(!0)},a.fancyboxPlus.center=function(){var a,b;B||(b=arguments[0]===!0?1:0,a=Q(),!b&&(e.width()>a[0]||e.height()>a[1])||e.stop().animate({top:parseInt(Math.max(a[3]-20,a[3]+.5*(a[1]-g.height()-40)-s.padding)),left:parseInt(Math.max(a[2]-20,a[2]+.5*(a[0]-g.width()-40)-s.padding))},"number"==typeof arguments[0]?arguments[0]:200))},a.fancyboxPlus.init=function(){a("#fbplus-wrap").length||(a("body").append(b=a('<div id="fbplus-tmp"></div>'),c=a('<div id="fbplus-loading"><div></div></div>'),d=a('<div id="fbplus-overlay"></div>'),e=a('<div id="fbplus-wrap"></div>')),f=a('<div id="fbplus-outer"></div>').append('<div class="fbplus-bg" id="fbplus-bg-n"></div><div class="fbplus-bg" id="fbplus-bg-ne"></div><div class="fbplus-bg" id="fbplus-bg-e"></div><div class="fbplus-bg" id="fbplus-bg-se"></div><div class="fbplus-bg" id="fbplus-bg-s"></div><div class="fbplus-bg" id="fbplus-bg-sw"></div><div class="fbplus-bg" id="fbplus-bg-w"></div><div class="fbplus-bg" id="fbplus-bg-nw"></div>').appendTo(e),f.append(g=a('<div id="fbplus-content"></div>'),h=a('<a id="fbplus-close"></a>'),i=a('<div id="fbplus-title"></div>'),j=a('<a href="javascript:;" id="fbplus-left"><span class="fancy-ico" id="fbplus-left-ico"></span></a>'),k=a('<a href="javascript:;" id="fbplus-right"><span class="fancy-ico" id="fbplus-right-ico"></span></a>')),h.click(a.fancyboxPlus.close),c.click(a.fancyboxPlus.cancel),j.click(function(b){b.preventDefault(),a.fancyboxPlus.prev()}),k.click(function(b){b.preventDefault(),a.fancyboxPlus.next()}),a.fn.mousewheel&&e.bind("mousewheel.fb",function(b,c){B?b.preventDefault():0!=a(b.target).get(0).clientHeight&&a(b.target).get(0).scrollHeight!==a(b.target).get(0).clientHeight||(b.preventDefault(),a.fancyboxPlus[c>0?"prev":"next"]())}),a.support.opacity||e.addClass("fbplus-ie"),D&&(c.addClass("fbplus-ie6"),e.addClass("fbplus-ie6"),a('<iframe id="fbplus-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(f)))},a.fn.fancyboxPlus.defaults={padding:10,margin:40,opacity:!1,modal:!1,cyclic:!1,scrolling:"auto",width:560,height:340,autoScale:!0,autoDimensions:!0,centerOnScroll:!1,ajax:{},swf:{wmode:"transparent"},hideOnOverlayClick:!0,hideOnContentClick:!1,overlayShow:!0,overlayOpacity:.7,overlayColor:"#777",titleShow:!0,titlePosition:"float",titleFormat:null,titleFromAlt:!1,transitionIn:"fade",transitionOut:"fade",speedIn:300,speedOut:300,changeSpeed:300,changeFade:"fast",easingIn:"swing",easingOut:"swing",showCloseButton:!0,showNavArrows:!0,enableEscapeButton:!0,enableKeyboardNav:!0,onStart:function(){},onCancel:function(){},onComplete:function(){},onCleanup:function(){},onClosed:function(){},onError:function(){}},a(document).ready(function(){a.fancyboxPlus.init()})}(jQuery);