-
Notifications
You must be signed in to change notification settings - Fork 1
/
carousel.min.js
1 lines (1 loc) · 2.69 KB
/
carousel.min.js
1
!function(){var Carousel;Carousel=function(){function Carousel(element,options){var $element,_this=this;this.options=options;this._current=0;this._sliding=false;this._paused=false;this._timer=null;$element=$(element);this.rect=$element.width();this.$inner=$element.find(this.options.inner_selector);this.$items=$element.find(this.options.items_selector);if(this.options.pause){$element.on("mouseenter.py.carousel",function(){return _this.pause(true)}).on("mouseleave.py.carousel",function(){return _this.pause(false)})}if(this.options.auto){this.start()}this.$indicators=$(this.options.indicators_selector).each(function(i,ele){return $(ele).on("click.py.carousel",function(){return _this.show(i)})});$(this.options.control_next_selector).on("click.py.carousel",function(){return _this.next()});$(this.options.control_prev_selector).on("click.py.carousel",function(){return _this.prev()})}Carousel.prototype.show=function(index){var $next,is_prev,_this=this;is_prev=arguments[1]===true?true:false;if(this._sliding){return false}if(index==null||index===this._current){return false}this._sliding=true;this.$indicators.eq(this._current).removeClass("active");this.$indicators.eq(index).addClass("active");$next=this.$items.eq(index);$next.addClass("active");$next.css("left",is_prev?"-"+this.rect+"px":""+this.rect+"px");this.$inner.animate({left:is_prev?this.rect:-this.rect},this.options.duration,function(){$next.css("left","0px");_this.$inner.css("left","0px");_this.$items.eq(_this._current).removeClass("active");_this._current=index;return _this._sliding=false});return false};Carousel.prototype.prev=function(){var index;index=this._current-1<0?this.$items.length-1:this._current-1;return this.show(index,true)};Carousel.prototype.next=function(){var index;index=this._current+1>this.$items.length-1?0:this._current+1;return this.show(index)};Carousel.prototype.start=function(){var _this=this;this.stop();this._paused=false;return this._timer=setInterval(function(){if(!_this._paused){return _this.next()}},this.options.delay)};Carousel.prototype.stop=function(){if(this._timer){return this._timer=clearInterval(this._timer)}};Carousel.prototype.pause=function(paused){return this._paused=paused};return Carousel}();$.fn.carousel=function(options){var defaults;defaults={inner_selector:".js-carousel-inner",items_selector:".js-carousel-inner .item",indicators_selector:".js-carousel-indicators .item",control_next_selector:".js-carousel-control.btn_next",control_prev_selector:".js-carousel-control.btn_prev",delay:6e3,duration:500,auto:true,pause:true};options=$.extend(defaults,options);return this.each(function(){var $this;$this=$(this);if(!$this.data("py.carousel")){return $this.data("py.carousel",new Carousel(this,options))}})}}.call(this);