openstackweb/themes/openstack/javascript/jcarousellite.min.js
2014-10-31 16:21:41 -03:00

25 lines
4.8 KiB
JavaScript

/*!
* jQuery jCarousellite Plugin v1.7.2
*
* Date: Sun May 27 23:19:43 2012 EDT
* Requires: jQuery v1.4+
*
* Copyright 2012 Karl Swedberg
* Copyright 2007 Ganeshji Marwaha (gmarwaha.com)
* 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(f){function B(x){if(this.id)this.id+=x}f.jCarouselLite={version:"1.7.2",curr:0};f.fn.jCarouselLite=function(x){var a=f.extend({},f.fn.jCarouselLite.defaults,x);this.each(function(){function y(){return i.slice(d).slice(0,m)}function n(b){if(z)return false;var c=b>d;a.beforeStart&&a.beforeStart.call(this,y(),c);if(a.circular){if(b>d&&b>o-m){d%=j;b-=j;k.css(t,-d*p)}else if(b<d&&b<0){d+=j;b+=j;k.css(t,-d*p)}d=b+b%1}else{if(b<0)b=0;else if(b>o-q)b=o-q;d=b;a.btnPrev&&a.$btnPrev.toggleClass(a.btnDisabledClass,
d===0);a.btnNext&&a.$btnNext.toggleClass(a.btnDisabledClass,d===o-q)}a.btnGo&&C(d);f.jCarouselLite.curr=d;z=true;D[t]=-(d*p);k.animate(D,a.speed,a.easing,function(){a.afterEnd&&a.afterEnd.call(this,y(),c);z=false});return d}var r={ul:{}},z=false,t=a.vertical?"top":"left",D={},E=a.vertical?"height":"width",h=this,e=f(this),k=e.find("ul").eq(0),l=k.children("li"),j=l.length,u=a.visible,m=Math.ceil(u),q=Math.floor(u),s=Math.min(a.start,j-1),A=1,F=0,v;if(a.init.call(this,a,l)!==false){e.data("dirjc",
A);if(a.circular){v=l.slice(j-m).clone(true).each(B);l=l.slice(0,m).clone(true).each(B);k.prepend(v).append(l);s+=m;F=m}var C=function(b){b=Math.ceil(b);b=(b-F)%j;var c=f(a.btnGo),g=b+q;c.removeClass(a.activeClass).removeClass(a.visibleClass);c.eq(b).addClass(a.activeClass);c.slice(b,b+q).addClass(a.visibleClass);g>c.length&&c.slice(0,g-c.length).addClass(a.visibleClass);return b},i=k.children("li"),o=i.length,d=s,p=a.vertical?i.outerHeight(true):i.outerWidth(true);v=p*o;l=p*u;f.jCarouselLite.curr=
d;if(a.autoCSS){e.css({visibility:"visible",overflow:"hidden",position:"relative",zIndex:2,left:"0px"});k.css({margin:"0",padding:"0",position:"relative",listStyleType:"none",zIndex:1});i.css({overflow:a.vertical?"hidden":"visible","float":a.vertical?"none":"left"});r.div={};r.div[E]=l+"px";e.css(r.div);i.css({width:i.width(),height:i.height()});r.ul[E]=v+"px";r.ul[t]=-(d*p)+"px";k.css(r.ul)}var G=0,H=a.autoStop&&(a.circular?a.autoStop:Math.min(j,a.autoStop)),I=typeof a.auto=="number"?a.auto:a.scroll,
w=function(){h.setAutoAdvance=setTimeout(function(){if(!H||H>G){A=e.data("dirjc");n(d+A*I);G++;w()}},a.timeout)};f.each(["btnPrev","btnNext"],function(b,c){if(a[c]){a["$"+c]=f.isFunction(a[c])?a[c].call(e[0]):f(a[c]);a["$"+c].bind("click.jc",function(g){g.preventDefault();g=b===0?d-a.scroll:d+a.scroll;if(a.directional)e.data("dirjc",b?1:-1);return n(g)})}});if(!a.circular){a.btnPrev&&s===0&&a.$btnPrev.addClass(a.btnDisabledClass);a.btnNext&&s+q>=o&&a.$btnNext.addClass(a.btnDisabledClass)}if(a.btnGo){f.each(a.btnGo,
function(b,c){f(c).bind("click.jc",function(g){g.preventDefault();return n(a.circular?u+b:b)})});C(s)}a.mouseWheel&&e.mousewheel&&e.bind("mousewheel.jc",function(b,c){return c>0?n(d-a.scroll):n(d+a.scroll)});a.pause&&a.auto&&e.bind("mouseenter.jc",function(){e.trigger("pauseCarousel.jc")}).bind("mouseleave.jc",function(){e.trigger("resumeCarousel.jc")});a.auto&&w();f.jCarouselLite.vis=y;e.bind("go.jc",function(b,c){if(typeof c=="undefined")c="+=1";var g=typeof c=="string"&&/(\+=|-=)(\d+)/.exec(c);
if(g)c=g[1]=="-="?d-g[2]*1:d+g[2]*1;else c+=s;n(c)}).bind("startCarousel.jc",function(){clearTimeout(h.setAutoAdvance);h.setAutoAdvance=undefined;e.trigger("go","+="+a.scroll);w();e.removeData("pausedjc").removeData("stoppedjc")}).bind("resumeCarousel.jc",function(b,c){if(!h.setAutoAdvance){clearTimeout(h.setAutoAdvance);h.setAutoAdvance=undefined;var g=e.data("stoppedjc");if(c||!g){w();e.removeData("pausedjc");g&&e.removeData("stoppedjc")}}}).bind("pauseCarousel.jc",function(){clearTimeout(h.setAutoAdvance);
h.setAutoAdvance=undefined;e.data("pausedjc",true)}).bind("stopCarousel.jc",function(){clearTimeout(h.setAutoAdvance);h.setAutoAdvance=undefined;e.data("stoppedjc",true)}).bind("endCarousel.jc",function(){if(h.setAutoAdvance){clearTimeout(h.setAutoAdvance);h.setAutoAdvance=undefined}a.btnPrev&&a.$btnPrev.addClass(a.btnDisabledClass).unbind(".jc");a.btnNext&&a.$btnNext.addClass(a.btnDisabledClass).unbind(".jc");a.btnGo&&f.each(a.btnGo,function(b,c){f(c).unbind(".jc")});f.each(["pausedjc","stoppedjc",
"dirjc"],function(b,c){e.removeData(c)});e.unbind(".jc")})}});return this};f.fn.jCarouselLite.defaults={autoCSS:true,btnPrev:null,btnNext:null,btnDisabledClass:"disabled",btnGo:null,activeClass:"active",visibleClass:"vis",mouseWheel:false,speed:200,easing:null,timeout:4E3,auto:false,directional:false,autoStop:false,pause:true,vertical:false,circular:true,visible:3,start:0,scroll:1,init:function(){},beforeStart:null,afterEnd:null}})(jQuery);