/*! jquery.yalb - v0.3.3 - 2015-06-24 * https://github.com/Fuzzyma/jquery.yalb * Copyright (c) 2015 Ulrich-Matthias Schäfer; Licensed MIT */ !function(a){var b=null;a.yalb=function(c,d){if(!(this instanceof a.yalb))return b&&b.yalb.trigger("close"),new a.yalb(c,d);b=this;var e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w=a.extend({},a.yalb.defaults,d),x=[],y=w.current,z=a("
");f=function(b){return a("",{"class":b,click:function(){z.trigger(b)}})},g=function(){z.children("span.loader").stop().fadeOut(),z.children("strong.error").stop().fadeOut()},h=function(){w.loop&&c.length>1||(y===c.length-1?z.children(".next").hide():z.children(".next").show(),0===y?z.children(".prev").hide():z.children(".prev").show())},i=function(){z.children("span.loader").stop().fadeIn()},j=function(){z.children("img.image").fadeOut(function(){a(this).remove()}),z.children("span.loader").stop().fadeOut(),z.children("strong.error").fadeIn(),m([y-1,y+1])},k=function(){z.append(a(x[y].img).addClass("image").fadeIn()),z.trigger("change",{index:y}),m([y-1,y+1])},l=function(a){if("string"==typeof a)return a;if(a instanceof Node&&0===w.src.indexOf("data-"))return a.getAttribute(w.src);for(var b=w.src.split("."),c=0,d=b.length;d>c;++c)a=a[b[c]];return a},m=function(a){a=a||[y];for(var b=a.length;b--;)w.loop&&a[b]<0&&(a[b]+=x.length),a[b]>=x.length||a[b]<0||x[a[b]].loaded||x[a[b]].pending||x[a[b]].error||(x[a[b]].img.src=l(c[a[b]]),x[a[b]].pending=!0)},n=function(){h(),x[y].loaded?o():x[y].error?j():(i(),m())},o=function(){if(g(),z.children("img.image").attr("src")!==a(x[y].img).attr("src")){z.children("img.image").length&&z.children("img.image").fadeOut(function(){a(this).remove()});var b=x[y].img.naturalWidth/x[y].img.naturalHeight,c=x[y].img.naturalHeight,d=x[y].img.naturalWidth,e=w.height||a(window).height()-40,f=w.width||a(window).width()-40;c>e&&(c=e,d=b*e),d>f&&(d=f,c=f/b),Math.abs(z.width()-d)>1||Math.abs(z.height()-c)>1?(z.stop(),z.animate({width:d,height:c,bottom:-(a(window).height()-c)/2},k)):k()}},p=function(a){return function(){x[a].error=!0,a===y&&n()}},q=function(a){return function(){x[a].loaded=!0,a===y&&n()}},r=function(){y>0?(--y,n()):w.loop&&(y=x.length-1,n())},s=function(){y").addClass("loader").hide()).append(a("").addClass("error").hide()),e=a("
").addClass(w["class"]+"_wrapper").click(function(a){a.target===this&&z.trigger("close")}).append(z),z.on({prev:r,next:s,close:v,show:t,open:u}),this.yalb=z;for(var A=0,B=c.length;B>A;++A)x[A]={img:new Image,loaded:!1,pending:!1,error:!1},x[A].img.onload=q(A),x[A].img.onerror=p(A);return w.open&&(u(),n()),this},a.yalb.prev=function(){return b?(b.yalb.trigger("prev"),a.yalb):a.yalb},a.yalb.next=function(){return b?(b.yalb.trigger("next"),a.yalb):a.yalb},a.yalb.close=function(){return b?(b.yalb.trigger("close"),a.yalb):a.yalb},a.yalb.show=function(c){return b?(b.yalb.trigger("show",{index:c}),a.yalb):a.yalb},a.yalb.open=function(){return b?(b.yalb.trigger("open"),a.yalb):a.yalb},a.yalb.on=function(){return b?(b.yalb.on.apply(b.yalb,Array.prototype.slice.call(arguments,0)),a.yalb):a.yalb},a.yalb.off=function(){return b?(b.yalb.off.apply(b.yalb,Array.prototype.slice.call(arguments,0)),a.yalb):a.yalb},a.yalb.get=function(){return b?b.yalb:a.yalb},a.yalb.defaults={src:"src",current:0,"class":"yalb",loop:!0,open:!0,width:0,height:0},a.fn.yalb=function(b){return a.yalb(this,b),this}}(jQuery);