diff --git a/README.md b/README.md index c6fb36d..143dc73 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ SimpleSlider ============ -version: 0.2.5 +version: 0.3.0 [![Build Status](https://travis-ci.org/ruyadorno/SimpleSlider.png?branch=develop)](https://travis-ci.org/ruyadorno/SimpleSlider) diff --git a/bower.json b/bower.json index b8dc654..9696f29 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "SimpleSlider", - "version": "0.2.5", + "version": "0.3.0", "description": "A simple javascript slider without any dependencies", "homepage": "http://ruyadorno.github.io/SimpleSlider/", "authors": [ diff --git a/dist/simpleslider.js b/dist/simpleslider.js index 49f60ed..f393e20 100644 --- a/dist/simpleslider.js +++ b/dist/simpleslider.js @@ -257,19 +257,26 @@ return false; } - if (this.autoPlay && this.imgs.length > 1) { + this.startInterval(); - var scope = this; + }; - if (this.interval) { - window.clearInterval(this.interval); - } + SimpleSlider.prototype.startInterval = function () { + + var self = this; + + if (!this.autoPlay || this.imgs.length <= 1) { + return; + } - this.interval = window.setInterval(function(){ - scope.change(scope.nextIndex()); - }, this.delay * 1000); + if (this.interval) { + window.clearInterval(this.interval); } + this.interval = window.setInterval(function(){ + self.change(self.nextIndex()); + }, this.delay * 1000); + }; SimpleSlider.prototype.startAnim = function(target, fromValue, toValue){ @@ -307,12 +314,16 @@ this.change(this.nextIndex()); + this.startInterval(); + }; SimpleSlider.prototype.prev = function(){ this.change(this.prevIndex()); + this.startInterval(); + }; SimpleSlider.prototype.nextIndex = function(){ @@ -331,7 +342,7 @@ var newIndex = this.actualIndex-1; - if (newIndex <= 0) { + if (newIndex < 0) { newIndex = this.imgs.length-1; } diff --git a/dist/simpleslider.min.js b/dist/simpleslider.min.js index 5969f39..080784d 100644 --- a/dist/simpleslider.min.js +++ b/dist/simpleslider.min.js @@ -1 +1 @@ -!function(context,definition){"use strict";"undefined"!=typeof module&&module.exports?module.exports=definition():"function"==typeof define&&define.amd?define(function(){return window.SimpleSlider=definition()}):context.SimpleSlider=definition()}(this,function(){"use strict";function getdef(val,def){return void 0===val||null===val||""===val?def:val}function getUnit(args,transitionProperty){for(var item,count=args.length,unit="";--count>=0;)item=args[count],"string"==typeof item&&(unit=item.replace(parseInt(item,10)+"",""));return"opacity"!==transitionProperty&&""===unit&&(unit="px"),unit}function testChildrenNum(value){if(0>=value){try{console.warn("A SimpleSlider main container elementshould have at least one child.")}catch(e){}return!0}return!1}function anim(target,prop,unit,transitionDuration,startTime,elapsedTime,fromValue,toValue,easeFunc){function loop(){window.requestAnimationFrame(function(time){0===startTime&&(startTime=time),anim(target,prop,unit,transitionDuration,startTime,time,fromValue,toValue,easeFunc)})}var newValue;return 0===startTime?loop():(newValue=easeFunc(elapsedTime-startTime,fromValue,toValue-fromValue,transitionDuration),void(transitionDuration>=elapsedTime-startTime?(target[prop]=newValue+unit,loop()):target[prop]=toValue+unit))}function startSlides(container,unit,startValue,visibleValue,transitionProperty){for(var imgs=[],i=container.children.length;--i>=0;)imgs[i]=container.children[i],imgs[i].style.position="absolute",imgs[i].style.top="0"+unit,imgs[i].style.left="0"+unit,imgs[i].style[transitionProperty]=startValue+unit,imgs[i].style.zIndex=0;return imgs[0].style[transitionProperty]=visibleValue+unit,imgs[0].style.zIndex=1,imgs}function manageRemovingSlideOrder(oldSlide,newSlide){return newSlide.style.zIndex=3,oldSlide&&(oldSlide.style.zIndex=1),newSlide}function manageInsertingSlideOrder(oldSlide,newSlide){return newSlide.style.zIndex=4,oldSlide&&(oldSlide.style.zIndex=2),newSlide}function parseStringToBoolean(value){return"false"===value?!1:value}Date.now||(Date.now=function(){return(new Date).getTime()});for(var vendors=["webkit","moz"],i=0;i=this.imgs.length&&(newIndex=0),newIndex},SimpleSlider.prototype.prevIndex=function(){var newIndex=this.actualIndex-1;return 0>newIndex&&(newIndex=this.imgs.length-1),newIndex},SimpleSlider.prototype.dispose=function(){if(window.clearInterval(this.interval),this.imgs){for(var i=this.imgs.length;--i>=0;)this.imgs.pop();this.imgs=null}this.containerElem=null,this.interval=null,this.trProp=null,this.trTime=null,this.delay=null,this.startVal=null,this.endVal=null,this.autoPlay=null,this.actualIndex=null,this.inserted=null,this.removed=null},SimpleSlider}); \ No newline at end of file +!function(context,definition){"use strict";"undefined"!=typeof module&&module.exports?module.exports=definition():"function"==typeof define&&define.amd?define(function(){return window.SimpleSlider=definition()}):context.SimpleSlider=definition()}(this,function(){"use strict";function getdef(val,def){return void 0===val||null===val||""===val?def:val}function getUnit(args,transitionProperty){for(var item,count=args.length,unit="";--count>=0;)item=args[count],"string"==typeof item&&(unit=item.replace(parseInt(item,10)+"",""));return"opacity"!==transitionProperty&&""===unit&&(unit="px"),unit}function testChildrenNum(value){if(0>=value){try{console.warn("A SimpleSlider main container elementshould have at least one child.")}catch(e){}return!0}return!1}function anim(target,prop,unit,transitionDuration,startTime,elapsedTime,fromValue,toValue,easeFunc){function loop(){window.requestAnimationFrame(function(time){0===startTime&&(startTime=time),anim(target,prop,unit,transitionDuration,startTime,time,fromValue,toValue,easeFunc)})}var newValue;return 0===startTime?loop():(newValue=easeFunc(elapsedTime-startTime,fromValue,toValue-fromValue,transitionDuration),void(transitionDuration>=elapsedTime-startTime?(target[prop]=newValue+unit,loop()):target[prop]=toValue+unit))}function startSlides(container,unit,startValue,visibleValue,transitionProperty){for(var imgs=[],i=container.children.length;--i>=0;)imgs[i]=container.children[i],imgs[i].style.position="absolute",imgs[i].style.top="0"+unit,imgs[i].style.left="0"+unit,imgs[i].style[transitionProperty]=startValue+unit,imgs[i].style.zIndex=0;return imgs[0].style[transitionProperty]=visibleValue+unit,imgs[0].style.zIndex=1,imgs}function manageRemovingSlideOrder(oldSlide,newSlide){return newSlide.style.zIndex=3,oldSlide&&(oldSlide.style.zIndex=1),newSlide}function manageInsertingSlideOrder(oldSlide,newSlide){return newSlide.style.zIndex=4,oldSlide&&(oldSlide.style.zIndex=2),newSlide}function parseStringToBoolean(value){return"false"===value?!1:value}Date.now||(Date.now=function(){return(new Date).getTime()});for(var vendors=["webkit","moz"],i=0;i=this.imgs.length&&(newIndex=0),newIndex},SimpleSlider.prototype.prevIndex=function(){var newIndex=this.actualIndex-1;return 0>newIndex&&(newIndex=this.imgs.length-1),newIndex},SimpleSlider.prototype.dispose=function(){if(window.clearInterval(this.interval),this.imgs){for(var i=this.imgs.length;--i>=0;)this.imgs.pop();this.imgs=null}this.containerElem=null,this.interval=null,this.trProp=null,this.trTime=null,this.delay=null,this.startVal=null,this.endVal=null,this.autoPlay=null,this.actualIndex=null,this.inserted=null,this.removed=null},SimpleSlider}); \ No newline at end of file diff --git a/package.json b/package.json index 278e4b4..087f34d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "simple-slider", - "version": "0.2.5", + "version": "0.3.0", "description": "A simple javascript slider without any dependencies", "scripts": { "test": "grunt jasmine"