forked from thydzik/Nivo-Slider-Lazy-Load-v2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjquery.nivo.slider.pack.js
1 lines (1 loc) · 11.9 KB
/
jquery.nivo.slider.pack.js
1
(function(b){var a=function(c,d){var v=b.extend({},b.fn.nivoSlider.defaults,d);var m={currentSlide:0,currentImage:"",totalSlides:0,running:false,paused:false,stop:false,controlNavEl:false};var p=b(c);p.data("nivo:vars",m).addClass("nivoSlider");var o=p.children();o.each(function(){var y=b(this);var x="";if(!y.is("img")){if(y.is("a")){y.addClass("nivo-imageLink");x=y}y=y.find("img:first")}var w=(w===0)?y.attr("width"):y.width(),i=(i===0)?y.attr("height"):y.height();if(x!==""){x.css("display","none")}y.css("display","none");m.totalSlides++});var g=function(i){return i.data("src")||i.attr("src")};var n=function(i){if(b(o[i]).is("img")){return b(o[i])}else{return b(o[i]).find("img:first")}};var l=function(x){var w=m.currentSlide+x;if(w>=o.length){w=0}else{if(w<0){w=0}}var i=n(w);i.attr("src",i.data("src"))};if(b(o[m.currentSlide]).is("img")){m.currentImage=b(o[m.currentSlide])}else{m.currentImage=b(o[m.currentSlide]).find("img:first")}if(b(o[m.currentSlide]).is("a")){b(o[m.currentSlide]).css("display","block")}var t=b('<img class="nivo-main-image" src="#" />');t.attr("src",g(m.currentImage)).show();p.append(t);if(v.randomStart){v.startSlide=Math.floor(Math.random()*m.totalSlides)}if(v.startSlide>0){if(v.startSlide>=m.totalSlides){v.startSlide=m.totalSlides-1}m.currentSlide=v.startSlide}l(1);b(window).resize(function(){p.children("img").width(p.width());t.attr("src",g(m.currentImage));t.stop().height("auto");b(".nivo-slice").remove();b(".nivo-box").remove()});p.append(b('<div class="nivo-caption"></div>'));var k=function(i){var x=b(".nivo-caption",p);if(m.currentImage.attr("title")!=""&&m.currentImage.attr("title")!=undefined){var w=m.currentImage.attr("title");if(w.substr(0,1)=="#"){w=b(w).html()}if(x.css("display")=="block"){setTimeout(function(){x.html(w)},i.animSpeed)}else{x.html(w);x.stop().fadeIn(i.animSpeed)}}else{x.stop().fadeOut(i.animSpeed)}};k(v);var j=0;if(!v.manualAdvance&&o.length>1){j=setInterval(function(){h(p,o,v,false)},v.pauseTime)}if(v.directionNav){p.append('<div class="nivo-directionNav"><a class="nivo-prevNav">'+v.prevText+'</a><a class="nivo-nextNav">'+v.nextText+"</a></div>");b("a.nivo-prevNav",p).live("click",function(){if(m.running){return false}clearInterval(j);j="";m.currentSlide-=2;h(p,o,v,"prev")});b("a.nivo-nextNav",p).live("click",function(){if(m.running){return false}clearInterval(j);j="";h(p,o,v,"next")})}if(v.controlNav){m.controlNavEl=b('<div class="nivo-controlNav"></div>');p.after(m.controlNavEl);for(var s=0;s<o.length;s++){if(v.controlNavThumbs){m.controlNavEl.addClass("nivo-thumbs-enabled");var f=o.eq(s);if(!f.is("img")){f=f.find("img:first")}if(f.attr("data-thumb")){m.controlNavEl.append('<a class="nivo-control" rel="'+s+'"><img src="'+f.attr("data-thumb")+'" alt="" /></a>')}}else{m.controlNavEl.append('<a class="nivo-control" rel="'+s+'">'+(s+1)+"</a>")}}b("a:eq("+m.currentSlide+")",m.controlNavEl).addClass("active");b("a",m.controlNavEl).bind("click",function(){if(m.running){return false}if(b(this).hasClass("active")){return false}clearInterval(j);j="";t.attr("src",g(m.currentImage));m.currentSlide=b(this).attr("rel")-1;h(p,o,v,"control")})}if(v.pauseOnHover){p.hover(function(){m.paused=true;clearInterval(j);j=""},function(){m.paused=false;if(j===""&&!v.manualAdvance){j=setInterval(function(){h(p,o,v,false)},v.pauseTime)}})}p.bind("nivo:animFinished",function(){t.attr("src",g(m.currentImage));m.running=false;b(o).each(function(){if(b(this).is("a")){b(this).css("display","none")}});if(b(o[m.currentSlide]).is("a")){b(o[m.currentSlide]).css("display","block")}if(!m.paused&&!v.manualAdvance){l(1);if(j==""){j=setInterval(function(){h(p,o,v,false)},v.pauseTime)}}v.afterChange.call(this)});var u=function(y,x,B){if(b(B.currentImage).parent().is("a")){b(B.currentImage).parent().css("display","block")}b('img[src="'+g(B.currentImage)+'"]',y).not(".nivo-main-image,.nivo-control img").width(y.width()).css("visibility","hidden").show();var z=(b('img[src="'+g(B.currentImage)+'"]',y).not(".nivo-main-image,.nivo-control img").parent().is("a"))?b('img[src="'+g(B.currentImage)+'"]',y).not(".nivo-main-image,.nivo-control img").parent().height():b('img[src="'+g(B.currentImage)+'"]',y).not(".nivo-main-image,.nivo-control img").height();for(var w=0;w<x.slices;w++){var A=Math.round(y.width()/x.slices);if(w===x.slices-1){y.append(b('<div class="nivo-slice" name="'+w+'"><img src="'+g(B.currentImage)+'" style="position:absolute; width:'+y.width()+"px; height:auto; display:block !important; top:0; left:-"+((A+(w*A))-A)+'px;" /></div>').css({left:(A*w)+"px",width:(y.width()-(A*w))+"px",height:z+"px",opacity:"0",overflow:"hidden"}))}else{y.append(b('<div class="nivo-slice" name="'+w+'"><img src="'+g(B.currentImage)+'" style="position:absolute; width:'+y.width()+"px; height:auto; display:block !important; top:0; left:-"+((A+(w*A))-A)+'px;" /></div>').css({left:(A*w)+"px",width:A+"px",height:z+"px",opacity:"0",overflow:"hidden"}))}}b(".nivo-slice",y).height(z);t.stop().animate({height:b(B.currentImage).height()},x.animSpeed)};var q=function(x,i,A){if(b(A.currentImage).parent().is("a")){b(A.currentImage).parent().css("display","block")}b('img[src="'+g(A.currentImage)+'"]',x).not(".nivo-main-image,.nivo-control img").width(x.width()).css("visibility","hidden").show();var w=Math.round(x.width()/i.boxCols),B=Math.round(b('img[src="'+g(A.currentImage)+'"]',x).not(".nivo-main-image,.nivo-control img").height()/i.boxRows);for(var y=0;y<i.boxRows;y++){for(var z=0;z<i.boxCols;z++){if(z===i.boxCols-1){x.append(b('<div class="nivo-box" name="'+z+'" rel="'+y+'"><img src="'+g(A.currentImage)+'" style="position:absolute; width:'+x.width()+"px; height:auto; display:block; top:-"+(B*y)+"px; left:-"+(w*z)+'px;" /></div>').css({opacity:0,left:(w*z)+"px",top:(B*y)+"px",width:(x.width()-(w*z))+"px"}));b('.nivo-box[name="'+z+'"]',x).height(b('.nivo-box[name="'+z+'"] img',x).height()+"px")}else{x.append(b('<div class="nivo-box" name="'+z+'" rel="'+y+'"><img src="'+g(A.currentImage)+'" style="position:absolute; width:'+x.width()+"px; height:auto; display:block; top:-"+(B*y)+"px; left:-"+(w*z)+'px;" /></div>').css({opacity:0,left:(w*z)+"px",top:(B*y)+"px",width:w+"px"}));b('.nivo-box[name="'+z+'"]',x).height(b('.nivo-box[name="'+z+'"] img',x).height()+"px")}}}t.stop().animate({height:b(A.currentImage).height()},i.animSpeed)};var h=function(K,J,N,G){var I=K.data("nivo:vars");if(I&&(I.currentSlide===I.totalSlides-1)){N.lastSlide.call(this)}if((!I||I.stop)&&!G){return false}N.beforeChange.call(this);if(!G){t.attr("src",g(I.currentImage))}else{if(G==="prev"){t.attr("src",g(I.currentImage))}if(G==="next"){t.attr("src",g(I.currentImage))}}I.currentSlide++;if(I.currentSlide===I.totalSlides){I.currentSlide=0;N.slideshowEnd.call(this)}if(I.currentSlide<0){I.currentSlide=(I.totalSlides-1)}I.currentImage=n(I.currentSlide);if(N.controlNav){b("a",I.controlNavEl).removeClass("active");b("a:eq("+I.currentSlide+")",I.controlNavEl).addClass("active")}k(N);b(".nivo-slice",K).remove();b(".nivo-box",K).remove();var x=N.effect,P="";if(N.effect==="random"){P=new Array("sliceDownRight","sliceDownLeft","sliceUpRight","sliceUpLeft","sliceUpDown","sliceUpDownLeft","fold","fade","boxRandom","boxRain","boxRainReverse","boxRainGrow","boxRainGrowReverse");x=P[Math.floor(Math.random()*(P.length+1))];if(x===undefined){x="fade"}}if(N.effect.indexOf(",")!==-1){P=N.effect.split(",");x=P[Math.floor(Math.random()*(P.length))];if(x===undefined){x="fade"}}if(I.currentImage.attr("data-transition")){x=I.currentImage.attr("data-transition")}I.running=true;var O=0,L=0,w="",C="",M="",z="";if(x==="sliceDown"||x==="sliceDownRight"||x==="sliceDownLeft"){u(K,N,I);O=0;L=0;w=b(".nivo-slice",K);if(x==="sliceDownLeft"){w=b(".nivo-slice",K)._reverse()}w.each(function(){var i=b(this);i.css({top:"0px"});if(L===N.slices-1){setTimeout(function(){i.animate({opacity:"1.0"},N.animSpeed,"",function(){K.trigger("nivo:animFinished")})},(100+O))}else{setTimeout(function(){i.animate({opacity:"1.0"},N.animSpeed)},(100+O))}O+=50;L++})}else{if(x==="sliceUp"||x==="sliceUpRight"||x==="sliceUpLeft"){u(K,N,I);O=0;L=0;w=b(".nivo-slice",K);if(x==="sliceUpLeft"){w=b(".nivo-slice",K)._reverse()}w.each(function(){var i=b(this);i.css({bottom:"0px"});if(L===N.slices-1){setTimeout(function(){i.animate({opacity:"1.0"},N.animSpeed,"",function(){K.trigger("nivo:animFinished")})},(100+O))}else{setTimeout(function(){i.animate({opacity:"1.0"},N.animSpeed)},(100+O))}O+=50;L++})}else{if(x==="sliceUpDown"||x==="sliceUpDownRight"||x==="sliceUpDownLeft"){u(K,N,I);O=0;L=0;var E=0;w=b(".nivo-slice",K);if(x==="sliceUpDownLeft"){w=b(".nivo-slice",K)._reverse()}w.each(function(){var i=b(this);if(L===0){i.css("top","0px");L++}else{i.css("bottom","0px");L=0}if(E===N.slices-1){setTimeout(function(){i.animate({opacity:"1.0"},N.animSpeed,"",function(){K.trigger("nivo:animFinished")})},(100+O))}else{setTimeout(function(){i.animate({opacity:"1.0"},N.animSpeed)},(100+O))}O+=50;E++})}else{if(x==="fold"){u(K,N,I);O=0;L=0;b(".nivo-slice",K).each(function(){var i=b(this);var Q=i.width();i.css({top:"0px",width:"0px"});if(L===N.slices-1){setTimeout(function(){i.animate({width:Q,opacity:"1.0"},N.animSpeed,"",function(){K.trigger("nivo:animFinished")})},(100+O))}else{setTimeout(function(){i.animate({width:Q,opacity:"1.0"},N.animSpeed)},(100+O))}O+=50;L++})}else{if(x==="fade"){u(K,N,I);C=b(".nivo-slice:first",K);C.css({width:K.width()+"px"});C.animate({opacity:"1.0"},(N.animSpeed*2),"",function(){K.trigger("nivo:animFinished")})}else{if(x==="slideInRight"){u(K,N,I);C=b(".nivo-slice:first",K);C.css({width:"0px",opacity:"1"});C.animate({width:K.width()+"px"},(N.animSpeed*2),"",function(){K.trigger("nivo:animFinished")})}else{if(x==="slideInLeft"){u(K,N,I);C=b(".nivo-slice:first",K);C.css({width:"0px",opacity:"1",left:"",right:"0px"});C.animate({width:K.width()+"px"},(N.animSpeed*2),"",function(){C.css({left:"0px",right:""});K.trigger("nivo:animFinished")})}else{if(x==="boxRandom"){q(K,N,I);M=N.boxCols*N.boxRows;L=0;O=0;z=e(b(".nivo-box",K));z.each(function(){var i=b(this);if(L===M-1){setTimeout(function(){i.animate({opacity:"1"},N.animSpeed,"",function(){K.trigger("nivo:animFinished")})},(100+O))}else{setTimeout(function(){i.animate({opacity:"1"},N.animSpeed)},(100+O))}O+=20;L++})}else{if(x==="boxRain"||x==="boxRainReverse"||x==="boxRainGrow"||x==="boxRainGrowReverse"){q(K,N,I);M=N.boxCols*N.boxRows;L=0;O=0;var B=0;var H=0;var F=[];F[B]=[];z=b(".nivo-box",K);if(x==="boxRainReverse"||x==="boxRainGrowReverse"){z=b(".nivo-box",K)._reverse()}z.each(function(){F[B][H]=b(this);H++;if(H===N.boxCols){B++;H=0;F[B]=[]}});for(var D=0;D<(N.boxCols*2);D++){var y=D;for(var A=0;A<N.boxRows;A++){if(y>=0&&y<N.boxCols){(function(W,R,V,S,X){var U=b(F[W][R]);var Q=U.width();var T=U.height();if(x==="boxRainGrow"||x==="boxRainGrowReverse"){U.width(0).height(0)}if(S===X-1){setTimeout(function(){U.animate({opacity:"1",width:Q,height:T},N.animSpeed/1.3,"",function(){K.trigger("nivo:animFinished")})},(100+V))}else{setTimeout(function(){U.animate({opacity:"1",width:Q,height:T},N.animSpeed/1.3)},(100+V))}})(A,y,O,L,M);L++}y--}O+=100}}}}}}}}}}};var e=function(y){for(var z,w,A=y.length;A;z=parseInt(Math.random()*A,10),w=y[--A],y[A]=y[z],y[z]=w){}return y};var r=function(i){if(this.console&&typeof console.log!=="undefined"){console.log(i)}};this.stop=function(){if(!b(c).data("nivo:vars").stop){b(c).data("nivo:vars").stop=true;r("Stop Slider")}};this.start=function(){if(b(c).data("nivo:vars").stop){b(c).data("nivo:vars").stop=false;r("Start Slider")}};v.afterLoad.call(this);return this};b.fn.nivoSlider=function(c){return this.each(function(e,g){var d=b(this);if(d.data("nivoslider")){return d.data("nivoslider")}var f=new a(this,c);d.data("nivoslider",f)})};b.fn.nivoSlider.defaults={effect:"random",slices:15,boxCols:8,boxRows:4,animSpeed:500,pauseTime:3000,startSlide:0,directionNav:true,controlNav:false,controlNavThumbs:false,pauseOnHover:true,manualAdvance:false,prevText:"Prev",nextText:"Next",randomStart:false,beforeChange:function(){},afterChange:function(){},slideshowEnd:function(){},lastSlide:function(){},afterLoad:function(){}};b.fn._reverse=[].reverse})(jQuery);