From 03921c027911da2bc83ba169054a1962ea31e0e1 Mon Sep 17 00:00:00 2001 From: Mirco Babini Date: Tue, 17 Jun 2014 16:09:41 +0200 Subject: [PATCH] Enable loop in galleries --- assets/touchTouch/touchTouch.jquery.js | 48 +++++++++++--------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/assets/touchTouch/touchTouch.jquery.js b/assets/touchTouch/touchTouch.jquery.js index 16498e6..396c977 100644 --- a/assets/touchTouch/touchTouch.jquery.js +++ b/assets/touchTouch/touchTouch.jquery.js @@ -257,39 +257,31 @@ } function showNext(){ + + index = (index + 1) % items.length; + offsetSlider(index); - // If this is not the last image - if(index+1 < items.length){ - index++; - offsetSlider(index); - preload(index+1); - } - - else{ - // Trigger the spring animation - slider.addClass('rightSpring'); - setTimeout(function(){ - slider.removeClass('rightSpring'); - },500); - } + var nextindex = (index + 1) % items.length; + preload(nextindex); + } - + function showPrevious(){ - - // If this is not the first image - if(index>0){ - index--; - offsetSlider(index); - preload(index-1); + + index = (index - 1); + if( index < 0) { + index = items.length + index; } - - else{ - // Trigger the spring animation - slider.addClass('leftSpring'); - setTimeout(function(){ - slider.removeClass('leftSpring'); - },500); + + offsetSlider(index); + + var nextindex = index -1; + if( nextindex < 0) { + nextindex = items.length + nextindex; } + + preload(nextindex); + } };