diff --git a/Readme.md b/Readme.md index e3ddc44..65c2dce 100644 --- a/Readme.md +++ b/Readme.md @@ -70,13 +70,17 @@ Is on the last visisble item. -### .prev() +### .prev(cycle) - Show the previous item if present, or do nothing. + Show the previous item. + By default, do nothing if showing the first item. + If `cycle` is true and we are on the first item, display the last item. -### .next() +### .next(cycle) - Show the next item if present, or do nothing. + Show the next item. + By default, do nothing if showing the last item. + If `cycle` is true and we are on the last item, display the first item. ### .show(i, [ms], [options]) diff --git a/examples/grumpy.html b/examples/grumpy.html index b54527c..88370a2 100644 --- a/examples/grumpy.html +++ b/examples/grumpy.html @@ -74,6 +74,8 @@ + + diff --git a/index.js b/index.js index d30e528..a8bbcfd 100644 --- a/index.js +++ b/index.js @@ -316,12 +316,7 @@ Swipe.prototype.stop = function(){ */ Swipe.prototype.cycle = function(){ - if (this.isLast()) { - this.currentVisible = -1; - this.next(); - } else { - this.next(); - } + return this.next(true); }; /** @@ -353,7 +348,10 @@ Swipe.prototype.isLast = function(){ * @api public */ -Swipe.prototype.prev = function(){ +Swipe.prototype.prev = function(cycle){ + if (cycle && this.isFirst()) { + this.currentVisible = this.visible; + } this.show(this.currentVisible - 1); return this; }; @@ -365,7 +363,10 @@ Swipe.prototype.prev = function(){ * @api public */ -Swipe.prototype.next = function(){ +Swipe.prototype.next = function(cycle){ + if (cycle && this.isLast()) { + this.currentVisible = -1; + } this.show(this.currentVisible + 1); return this; };