forked from kswedberg/jquery-carousel-lite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjcarousellite.min.js
23 lines (23 loc) · 3.96 KB
/
jcarousellite.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*!
* jQuery jCarousellite Plugin v1.3.1
*
* Date: Mon Dec 6 19:36:31 2010 -0500
* Requires: jQuery v1.4+
*
* Copyright 2007 Ganeshji Marwaha (gmarwaha.com)
* Modifications/enhancements by Karl Swedberg
* Dual licensed under the MIT and GPL licenses (just like jQuery):
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
* jQuery plugin to navigate images/any content in a carousel style widget.
*
*/
(function(e){e.jCarouselLite={version:"1.3.1"};e.fn.jCarouselLite=function(f){var g=e.extend({},e.fn.jCarouselLite.defaults,f);
return this.each(function(){var k=false,h=g.vertical?"top":"left",j={},i=g.vertical?"height":"width",w=this,s=e(this),r=s.find("ul").eq(0),y=r.children("li"),l=y.length,p=g.visible,m=Math.min(g.start,l-1);if(typeof initialized==="undefined"){initialized=false}if(g.circular&&!initialized){r.prepend(y.slice(l-p-1+1).clone(true)).append(y.slice(0,p).clone(true));m+=p}var q=r.children("li"),n=q.length;if(!initialized){curr=m}s.css("visibility","visible");q.css({overflow:g.vertical?"hidden":"visible","float":g.vertical?"none":"left"});
r.css({margin:"0",padding:"0",position:"relative",listStyleType:"none",zIndex:1});s.css({overflow:"hidden",position:"relative",zIndex:2,left:"0px"});liSize=g.vertical?a(q):c(q);ulSize=liSize*n;divSize=liSize*p;q.css({width:q.width(),height:q.height()});r.css(i,ulSize+"px").css(h,-(curr*liSize));s.css(i,divSize+"px");if(initialized){return}initialized=true;e.each(["btnPrev","btnNext"],function(v,A){if(g[A]){g["$"+A]=e.isFunction(g[A])?g[A].call(s[0]):e(g[A]);g["$"+A].bind("click.jc",function(){var B=v==0?curr-g.scroll:curr+g.scroll;
return x(B)})}});if(!g.circular){if(g.btnPrev&&m==0){g.$btnPrev.addClass(g.btnDisabledClass)}if(g.btnNext&&m+g.visible>=n){g.$btnNext.addClass(g.btnDisabledClass)}}if(g.btnGo){e.each(g.btnGo,function(v,A){e(A).bind("click.jc",function(){return x(g.circular?g.visible+v:v)})})}if(g.mouseWheel&&s.mousewheel){s.bind("mousewheel.jc",function(v,A){return A>0?x(curr-g.scroll):x(curr+g.scroll)})}if(g.auto){var o=0,u=d(l,g);var z=function(){w.setAutoAdvance=setTimeout(function(){if(!u||u>o){x(curr+g.scroll);o++;z()}},g.timeout+g.speed)
};z();s.bind("pauseCarousel.jc",function(v){clearTimeout(w.setAutoAdvance);s.data("pausedjc",true)}).bind("resumeCarousel.jc",function(v){z();s.removeData("pausedjc")});if(g.pause){s.bind("mouseenter.jc",function(){s.trigger("pauseCarousel")}).bind("mouseleave.jc",function(){s.trigger("resumeCarousel")})}}function t(){return q.slice(curr).slice(0,p)}function x(v){if(!k){if(g.beforeStart){g.beforeStart.call(this,t())}if(g.circular){if(v<=m-p-1){r.css(h,-((n-(p*2))*liSize)+"px");curr=v==m-p-1?n-(p*2)-1:n-(p*2)-g.scroll
}else{if(v>=n-p+1){r.css(h,-((p)*liSize)+"px");curr=v==n-p+1?p+1:p+g.scroll}else{curr=v}}}else{g.$btnPrev.toggleClass(g.btnDisabledClass,g.btnPrev&&v<=0);g.$btnNext.toggleClass(g.btnDisabledClass,g.btnNext&&v>n-p);if(v<0){curr=0}else{if(v>n-p){curr=n-p}else{curr=v}}}k=true;j[h]=-(curr*liSize);r.animate(j,g.speed,g.easing,function(){if(g.afterEnd){g.afterEnd.call(this,t())}k=false})}return false}s.bind("endCarousel.jc",function(){if(w.setAutoAdvance){clearTimeout(w.setAutoAdvance)}if(g.btnPrev){g[$btnPrev].addClass(g.btnDisabledClass).unbind(".jc")
}if(g.btnNext){g[$btnNext].addClass(g.btnDisabledClass).unbind(".jc")}if(g.btnGo){e.each(g.btnGo,function(v,A){e(A).unbind(".jc")})}if(w.setAutoAdvance){w.setAutoAdvance=null}s.removeData("pausejc");s.unbind(".jc")})})};e.fn.jCarouselLite.defaults={btnPrev:null,btnNext:null,btnDisabledClass:"disabled",btnGo:null,mouseWheel:false,speed:200,easing:null,auto:false,autoStop:false,timeout:4000,pause:true,vertical:false,circular:true,visible:3,start:0,scroll:1,beforeStart:null,afterEnd:null};function b(f,g){return parseInt(e.css(f[0],g),10)||0
}function c(f){return f[0].offsetWidth+b(f,"marginLeft")+b(f,"marginRight")}function a(f){return f[0].offsetHeight+b(f,"marginTop")+b(f,"marginBottom")}function d(g,f){return f.autoStop&&(f.circular?f.autoStop:Math.min(g,f.autoStop))}})(jQuery);