diff --git a/js/jquery.waterwheelCarousel.js b/js/jquery.waterwheelCarousel.js index 83c4eb4..b4ed882 100644 --- a/js/jquery.waterwheelCarousel.js +++ b/js/jquery.waterwheelCarousel.js @@ -636,6 +636,22 @@ } this.reload(startingOptions); + + this.swipe({ + swipeStatus: function (event, phase, direction) { + if (phase === "end") { + if (direction === "right") { + moveOnce('backward'); + } + else if (direction === "left") { + moveOnce('forward'); + } else { return false; } + } + }, + triggerOnTouchStart: false, + triggerOnTouchEnd: false, + threshold: 100 + }); return this; }; diff --git a/js/jquery.waterwheelCarousel.min.js b/js/jquery.waterwheelCarousel.min.js index ff17e75..dbdbec6 100644 --- a/js/jquery.waterwheelCarousel.min.js +++ b/js/jquery.waterwheelCarousel.min.js @@ -11,5 +11,9 @@ * Plugin written by Brian Osborne * for use with the jQuery JavaScript Framework * http://www.jquery.com + * + * for swipe use + * use jquery touch swipe + * https://www.npmjs.com/package/jquery-touchswipe */ -(function(a){a.fn.waterwheelCarousel=function(r){if(this.length>1){this.each(function(){a(this).waterwheelCarousel(r)});return this}var m=this;var c={};var t={};function j(){t={itemsContainer:a(m),totalItems:a(m).find("img").length,containerWidth:a(m).width(),containerHeight:a(m).height(),currentCenterItem:null,previousCenterItem:null,items:[],calculations:[],carouselRotationsLeft:0,currentlyMoving:false,itemsAnimating:0,currentSpeed:c.speed,intervalTimer:null,currentDirection:"forward",leftItemsCount:0,rightItemsCount:0,performingSetup:true};t.itemsContainer.find("img").removeClass(c.activeClassName)}function l(u){clearTimeout(t.autoPlayTimer);if(!u&&c.autoPlay!==0){t.autoPlayTimer=setTimeout(function(){if(c.autoPlay>0){n("forward")}else{n("backward")}},Math.abs(c.autoPlay))}}function h(x){if(c.preloadImages===false){x();return}var v=t.itemsContainer.find("img"),u=0,w=v.length;v.each(function(){a(this).bind("load",function(){u+=1;if(u===w){x();return}});a(this).attr("src",a(this).attr("src"));if(this.complete){a(this).trigger("load")}})}function d(){t.itemsContainer.find("img").each(function(){if(a(this).data("original_width")==undefined||c.forcedImageWidth>0){a(this).data("original_width",a(this).width())}if(a(this).data("original_height")==undefined||c.forcedImageHeight>0){a(this).data("original_height",a(this).height())}})}function e(){if(c.forcedImageWidth&&c.forcedImageHeight){t.itemsContainer.find("img").each(function(){a(this).width(c.forcedImageWidth);a(this).height(c.forcedImageHeight)})}}function s(){var v=t.itemsContainer.find("img:first");t.calculations[0]={distance:0,offset:0,opacity:1};var u=c.horizonOffset;var x=c.separation;for(var w=1;w<=c.flankingItems+2;w++){if(w>1){u*=c.horizonOffsetMultiplier;x*=c.separationMultiplier}t.calculations[w]={distance:t.calculations[w-1].distance+x,offset:t.calculations[w-1].offset+u,opacity:t.calculations[w-1].opacity*c.opacityMultiplier}}if(c.edgeFadeEnabled){t.calculations[c.flankingItems+1].opacity=0}else{t.calculations[c.flankingItems+1]={distance:0,offset:0,opacity:0}}}function b(){t.items=t.itemsContainer.find("img");for(var u=0;u=t.leftItemsCount*-1;v--){(u>0)?u-=1:u=t.totalItems-1;t.items[u].css("opacity",1);k(t.items[u],v)}}function f(I,y){var z=Math.abs(y);if(z0){p(0)}else{t.currentSpeed=c.speed;t.currentCenterItem.addClass(c.activeClassName);if(t.performingSetup===false){c.movedToCenter(t.currentCenterItem);c.movedFromCenter(t.previousCenterItem)}t.performingSetup=false;l()}}}function p(v){if(t.currentlyMoving===false){t.currentCenterItem.removeClass(c.activeClassName);t.currentlyMoving=true;t.itemsAnimating=0;t.carouselRotationsLeft+=v;if(c.quickerForFurther===true){if(v>1){t.currentSpeed=c.speed/v}t.currentSpeed=(t.currentSpeed<100)?100:t.currentSpeed}for(var y=0;y0)?t.rightItemsCount:t.leftItemsCount;if(Math.abs(x)>u){x=z*-1;if(t.totalItems%2==0){x+=1}}k(w,x)}}}a(this).find("img").bind("click",function(){var v=a(this).data().currentPosition;if(c.imageNav==false){return}if(Math.abs(v)>=c.flankingItems+1){return}if(t.currentlyMoving){return}t.previousCenterItem=t.currentCenterItem;l(true);c.autoPlay=0;var u=Math.abs(v);if(v==0){c.clickedCenter(a(this))}else{c.movingFromCenter(t.currentCenterItem);c.movingToCenter(a(this));if(v<0){t.currentDirection="backward";p(u)}else{if(v>0){t.currentDirection="forward";p(u)}}}});a(this).find("a").bind("click",function(u){var v=a(this).find("img").data("currentPosition")==0;if(c.linkHandling===1||(c.linkHandling===2&&!v)){u.preventDefault();return false}});function o(){var u=t.currentCenterItem.next();if(u.length<=0){u=t.currentCenterItem.parent().children().first()}return u}function i(){var u=t.currentCenterItem.prev();if(u.length<=0){u=t.currentCenterItem.parent().children().last()}return u}function n(u){if(t.currentlyMoving===false){t.previousCenterItem=t.currentCenterItem;c.movingFromCenter(t.currentCenterItem);if(u=="backward"){c.movingToCenter(i());t.currentDirection="backward"}else{if(u=="forward"){c.movingToCenter(o());t.currentDirection="forward"}}}p(1)}a(document).keydown(function(u){if(c.keyboardNav){if((u.which===37&&c.orientation=="horizontal")||(u.which===38&&c.orientation=="vertical")){l(true);c.autoPlay=0;n("backward")}else{if((u.which===39&&c.orientation=="horizontal")||(u.which===40&&c.orientation=="vertical")){l(true);c.autoPlay=0;n("forward")}}if(c.keyboardNavOverride&&((c.orientation=="horizontal"&&(u.which===37||u.which===39))||(c.orientation=="vertical"&&(u.which===38||u.which===40)))){u.preventDefault();return false}}});this.reload=function(v){if(typeof v==="object"){var u=v}else{var u={}}c=a.extend({},a.fn.waterwheelCarousel.defaults,v);j();t.itemsContainer.find("img").hide();e();h(function(){d();s();b();q()})};this.next=function(){l(true);c.autoPlay=0;n("forward")};this.prev=function(){l(true);c.autoPlay=0;n("backward")};this.reload(r);return this};a.fn.waterwheelCarousel.defaults={startingItem:1,separation:175,separationMultiplier:0.6,horizonOffset:0,horizonOffsetMultiplier:1,sizeMultiplier:0.7,opacityMultiplier:0.8,horizon:0,flankingItems:3,speed:300,animationEasing:"linear",quickerForFurther:true,edgeFadeEnabled:false,linkHandling:2,autoPlay:0,orientation:"horizontal",activeClassName:"carousel-center",keyboardNav:false,keyboardNavOverride:true,imageNav:true,preloadImages:true,forcedImageWidth:0,forcedImageHeight:0,movingToCenter:a.noop,movedToCenter:a.noop,clickedCenter:a.noop,movingFromCenter:a.noop,movedFromCenter:a.noop}})(jQuery); \ No newline at end of file +!function(s){"use strict";s.fn.waterwheelCarousel=function(t){if(1r&&(i=-1*a,g.totalItems%2==0&&(i+=1)),o(n,i)}}}function a(t){var e,i;!1===g.currentlyMoving&&(g.previousCenterItem=g.currentCenterItem,f.movingFromCenter(g.currentCenterItem),"backward"==t?(f.movingToCenter(((i=g.currentCenterItem.prev()).length<=0&&(i=g.currentCenterItem.parent().children().last()),i)),g.currentDirection="backward"):"forward"==t&&(f.movingToCenter(((e=g.currentCenterItem.next()).length<=0&&(e=g.currentCenterItem.parent().children().first()),e)),g.currentDirection="forward")),n(1)}return s(this).find("img").bind("click",function(){var t=s(this).data().currentPosition;if(0!=f.imageNav&&!(Math.abs(t)>=f.flankingItems+1||g.currentlyMoving)){g.previousCenterItem=g.currentCenterItem,i(!0),f.autoPlay=0;var e=Math.abs(t);0==t?f.clickedCenter(s(this)):(f.movingFromCenter(g.currentCenterItem),f.movingToCenter(s(this)),t<0?(g.currentDirection="backward",n(e)):0=-1*g.leftItemsCount;e--)0=1.4.4" + "jquery": ">=1.4.4", + "jquery-touchswipe": ">=1.6.18" } }