/*! * Double Carousel Plugin for JQuery * Version : 1.0 * Date : 2014-01-02 * Licence : All rights reserved * Author : owwwlab (Ehsan Dalvand & Alireza Jahandideh) * Contact : owwwlab@gmail.com * Web site : http://themeforest.net/user/owwwlab * Dependencies: tweenmx, imagesLoaded */ // Utility if ( typeof Object.create !== 'function' ){ // browser dose not support Object.create Object.create = function (obj){ function F(){}; F.prototype = obj; return new F(); }; }; (function($, window, document, undefined) { var dcs,inAnimation=false; var DoubleCarousel = { init: function( options , elem ){ var self = this; //store a reference to this self.elem = elem; self.$elem = $(elem); self.options = $.extend( {}, $.fn.DoubleCarousel.options, options); dcs=self.options; dcs.allItems=self.$elem.find('.item'); dcs.leftItems=dcs.leftSide.find('.item'); dcs.rightItems=dcs.rightSide.find('.item'); self.prepare(); //self.handleBgColors(); self.bindUIActions(); }, prepare : function(){ var self=this; //slides count dcs.slideCount = dcs.leftSide.find('.item').length; dcs.currentSlideIndex = 0; dcs.counterTotal.html(dcs.slideCount); dcs.counterCurrent.html(1); //Show/hide Controllers dcs.nextButton.fadeIn(); dcs.prevButton.fadeOut(); dcs.rightDirectionSign=(dcs.rightSideDir=='down')?-1:1; dcs.leftDirectionSign=(dcs.leftSideDir=='down')?-1:1; self.update(); var leftFillMode=dcs.leftSide.attr('data-fill'), rightFillMode=dcs.rightSide.attr('data-fill'); if (leftFillMode){ self.fillCore(leftFillMode,'left'); } if (rightFillMode){ self.fillCore(rightFillMode,'right'); } }, update:function(){ var self=this; dcs.carouselHeight=self.$elem.height(); var cHeight=dcs.carouselHeight; //Arrange slides based on sides direction dcs.rightItems.each(function(){ var $this=$(this), index=$this.index(); TweenMax.to($this,0,{y:dcs.rightDirectionSign*index*cHeight}); }); dcs.leftItems.each(function(){ var $this=$(this), index=$this.index(); TweenMax.to($this,0,{y:dcs.leftDirectionSign*index*cHeight}); }); (new TimelineLite()) .to(dcs.rightWrapper,0,{y:-dcs.rightDirectionSign*dcs.currentSlideIndex*cHeight}) .to(dcs.leftWrapper,0,{y:-dcs.leftDirectionSign*dcs.currentSlideIndex*cHeight}); }, nextSlide : function(){ if (dcs.currentSlideIndex>=dcs.slideCount-1 || inAnimation){ return false } var self=this, cHeight=dcs.carouselHeight; inAnimation=true; dcs.currentSlideIndex++; if (dcs.currentSlideIndex+1==dcs.slideCount) dcs.nextButton.fadeOut(); dcs.prevButton.fadeIn(); self.changeSlide(dcs.currentSlideIndex); }, prevSlide : function(){ if (dcs.currentSlideIndex<=0 || inAnimation){ return false } var self=this, cHeight=dcs.carouselHeight; inAnimation=true; dcs.currentSlideIndex--; if (dcs.currentSlideIndex==0){ //hide the nexr arrow dcs.prevButton.fadeOut(); } dcs.nextButton.fadeIn(); self.changeSlide(dcs.currentSlideIndex); }, gotoSlide:function(sIndex){ var self=this, cHeight=dcs.carouselHeight; inAnimation=true; self.changeSlide(sIndex); }, changeSlide:function(sIndex){ var self=this, cHeight=dcs.carouselHeight; self.$elem.trigger('start-change'); self.updateCounter(dcs.currentSlideIndex); (new TimelineLite({onComplete:function(){ inAnimation=false; self.$elem.trigger('end-change'); } })) .to(dcs.rightWrapper,1,{y:-dcs.rightDirectionSign*sIndex*cHeight,ease:Power4.easeOut}) .to(dcs.leftWrapper,1,{y:-dcs.leftDirectionSign*sIndex*cHeight,ease:Power4.easeOut},'-=1'); }, updateCounter : function(currentSlideIndex){ dcs.counterCurrent.html(currentSlideIndex+1); }, bindUIActions: function(){ self = this; dcs.nextButton.on('click',function(){ self.nextSlide(); }) dcs.prevButton.on('click',function(){ self.prevSlide(); }) $(window).on('resize',function(){ self.update(); }); if (dcs.mouse){ self.scrollControll(); } if (dcs.keyboard){ self.keyboardControll(); } if (dcs.touchSwipe){ self.touchControll(); } if (dcs.bulletControll){ self.bulletControll(); } }, scrollControll:function(){ self.$elem.on('DOMMouseScroll mousewheel', function (e) { if(e.originalEvent.detail > 0 || e.originalEvent.wheelDelta < 0) { self.nextSlide(); } else { self.prevSlide(); } }); }, keyboardControll:function(){ $(document).keydown(function(e) { switch(e.which) { case 38: // up self.prevSlide(); break; case 40: // down self.nextSlide(); break; default: return; } e.preventDefault(); }); }, touchControll:function(){ self.$elem.swipe({ swipe:function(event, direction, distance) { if (direction=='down'){ self.nextSlide(); }else if (direction=='up'){ self.prevSlide(); } } }); }, bulletControll:function(){ var self=this; var $bWrapper=$('