forked from johnnyfreeman/revolver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.revolver.min.js
2 lines (2 loc) · 4.65 KB
/
jquery.revolver.min.js
1
2
/* Revolver.js - http://revolverjs.com */
var Revolver; (function(b){Revolver=function(a,c){this.options=b.extend(!0,{},this.defaults,c);this.container=a;this.dimensions={height:this.container.height(),width:this.container.width()};this.slides=this.container.find("."+this.options.slideClass).each(b.proxy(function(){this.addSlide(this)},this));this.numSlides=this.slides.length;this.currentSlide=0;this.nextSlide=1<this.numSlides?1:0;this.lastSlide=0==this.numSlides?null:this.numSlides-1;this.status={paused:!1,playing:!1,stopped:!0};this.isAnimating=!1;if(!(1>= this.numSlides))return b.proxy(this.options.onReady,this)(),this.options.autoPlay&&this.play({},!0),this};Revolver.prototype.defaults={autoPlay:!0,onReady:function(){},onPlay:function(){},onStop:function(){},onPause:function(){},onRestart:function(){},rotationSpeed:4E3,slideClass:"slide",transition:{direction:"left",easing:"swing",onStart:function(){},onFinish:function(){},speed:500,type:"fade"}};Revolver.prototype.currentSlide=null;Revolver.prototype.nextSlide=null;Revolver.prototype.numSlides=0; Revolver.prototype.lastSlide=null;Revolver.prototype.container=null;Revolver.prototype.slides=[];Revolver.prototype.iteration=0;Revolver.prototype.intervalId=null;Revolver.prototype.status=null;Revolver.prototype.options=null;Revolver.prototype.dimensions=null;Revolver.prototype.isAnimating=null;Revolver.prototype.addSlide=function(a){this.slides.push(a)};Revolver.prototype.changeStatus=function(a){var c=this;b.each(this.status,function(b){c.status[b]=b==a});return this};Revolver.prototype.transition= function(a){if(!1===this.isAnimating)a=b.extend(!0,{},this.options.transition,a),doTransition=b.proxy(this.transitions[a.type],this),this.isAnimating=!0,doTransition(a),this.currentSlide=this.nextSlide,this.nextSlide=this.currentSlide==this.lastSlide?0:this.currentSlide+1,this.iteration++,b.proxy(a.onStart,this)();return this};Revolver.prototype.transitions={none:function(a){this.slides.eq(this.currentSlide).hide();this.slides.eq(this.nextSlide).show();b.proxy(a.onFinish,this);this.isAnimating=!1}, fade:function(a){var c=this;this.slides.eq(this.currentSlide).fadeOut(a.speed);this.slides.eq(this.nextSlide).fadeIn(a.speed,function(){b.proxy(a.onFinish,c)();c.isAnimating=!1})},slide:function(a){var c=this,f=this.slides.eq(this.currentSlide),g=this.slides.eq(this.nextSlide),d={},e={};this.slides.eq(this.nextSlide).css("z-index",this.iteration+1);switch(a.direction){case "up":d={top:0-this.dimensions.height,left:0};e={top:this.dimensions.height,left:0};break;case "right":d={top:0,left:this.dimensions.width}; e={top:0,left:0-this.dimensions.width};break;case "down":d={top:this.dimensions.height,left:0};e={top:0-this.dimensions.height,left:0};break;default:d={left:0-this.dimensions.width,top:0},e={left:this.dimensions.width,top:0}}f.stop(!0).animate(d,a.speed,function(){b(this).hide()});g.show().css(e).stop(!0).animate({top:0,left:0},a.speed,function(){b.proxy(a.onFinish,c)();c.isAnimating=!1})},reveal:function(a){var c=this;this.slides.eq(this.nextSlide).css({width:0,height:this.dimensions.height,"z-index":this.iteration+ 1}).show().animate({width:this.dimensions.width},a.speed,function(){b.proxy(a.onFinish,c)();c.isAnimating=!1});return this}};Revolver.prototype.play=function(a,c){if(!this.status.playing)this.changeStatus("playing"),b.proxy(this.options.onPlay,this)(),c||this.transition(a),this.intervalId=setInterval(b.proxy(this.transition,this),parseFloat(this.options.rotationSpeed));return this};Revolver.prototype.pause=function(){if(!this.status.paused&&(this.changeStatus("paused"),b.proxy(this.options.onPause, this)(),null!==this.intervalId))clearInterval(this.intervalId),this.intervalId=null;return this};Revolver.prototype.stop=function(){if(!this.status.stopped&&(this.changeStatus("stopped"),b.proxy(this.options.onStop,this)(),null!==this.intervalId))clearInterval(this.intervalId),this.intervalId=null;return this.reset()};Revolver.prototype.reset=function(){if(0!=this.currentSlide)this.nextSlide=0;return this};Revolver.prototype.restart=function(a){b.proxy(this.options.onRestart,this)();return this.stop().play(a)}; Revolver.prototype.first=function(a){return this.goTo(0,a)};Revolver.prototype.previous=function(a){return this.goTo(0===this.currentSlide?this.lastSlide:this.currentSlide-1,a)};Revolver.prototype.goTo=function(a,b){if(a==this.currentSlide)return this;this.nextSlide=a;return!this.status.playing?this.transition(b):this.pause().play(b)};Revolver.prototype.next=function(a){return this.goTo(this.nextSlide,a)};Revolver.prototype.last=function(a){return this.goTo(this.lastSlide,a)};b.fn.revolver=function(a){return this.each(function(){b.data(this, "revolver")||b.data(this,"revolver",new Revolver(b(this),a))})}})(jQuery);