From 259b3088e84467c41e37943f1cdbe2a376ff3580 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 9 Apr 2013 16:54:15 +0100 Subject: [PATCH 1/3] added basic support for touch devices --- jquery.roundabout.js | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/jquery.roundabout.js b/jquery.roundabout.js index df83da2..090f7bf 100644 --- a/jquery.roundabout.js +++ b/jquery.roundabout.js @@ -40,7 +40,6 @@ */ (function($) { "use strict"; - var defaults, internalData, methods; // add default shape @@ -110,7 +109,8 @@ childInFocus: -1, touchMoveStartPosition: null, stopAnimation: false, - lastAnimationStep: false + lastAnimationStep: false, + touchSupported: null }; methods = { @@ -137,7 +137,14 @@ period = 360.0 / childCount, startingChild = (settings.startingChild && settings.startingChild > (childCount - 1)) ? (childCount - 1) : settings.startingChild, startBearing = (settings.startingChild === null) ? settings.bearing : 360 - (startingChild * period), - holderCSSPosition = (self.css("position") !== "static") ? self.css("position") : "relative"; + holderCSSPosition = (self.css("position") !== "static") ? self.css("position") : "relative", + touchSupported = ('ontouchstart' in window); + + console.log(touchSupported); + $("#checker").text(touchSupported); + if (touchSupported) { + + } self .css({ // starting styles @@ -182,7 +189,7 @@ .children(settings.childSelector) .each(function(i) { $(this) - .bind("click.roundabout", function() { + .bind(touchSupported? "touchstart.roundabout" : "click.roundabout", function() { var degrees = methods.getPlacement.apply(self, [i]); if (!methods.isInFocus.apply(self, [degrees])) { @@ -199,7 +206,7 @@ // bind next buttons if (settings.btnNext) { $(settings.btnNext) - .bind("click.roundabout", function() { + .bind(touchSupported? "touchstart.roundabout" : "click.roundabout", function() { if (!self.data("roundabout").animating) { methods.animateToNextChild.apply(self, [self.data("roundabout").btnNextCallback]); } @@ -210,7 +217,7 @@ // bind previous buttons if (settings.btnPrev) { $(settings.btnPrev) - .bind("click.roundabout", function() { + .bind(touchSupported? "touchstart.roundabout" : "click.roundabout", function() { methods.animateToPreviousChild.apply(self, [self.data("roundabout").btnPrevCallback]); return false; }); @@ -219,7 +226,7 @@ // bind toggle autoplay buttons if (settings.btnToggleAutoplay) { $(settings.btnToggleAutoplay) - .bind("click.roundabout", function() { + .bind(touchSupported? "touchstart.roundabout" : "click.roundabout", function() { methods.toggleAutoplay.apply(self); return false; }); @@ -228,7 +235,7 @@ // bind start autoplay buttons if (settings.btnStartAutoplay) { $(settings.btnStartAutoplay) - .bind("click.roundabout", function() { + .bind(touchSupported? "touchstart.roundabout" : "click.roundabout", function() { methods.startAutoplay.apply(self); return false; }); @@ -237,7 +244,7 @@ // bind stop autoplay buttons if (settings.btnStopAutoplay) { $(settings.btnStopAutoplay) - .bind("click.roundabout", function() { + .bind(touchSupported? "touchstart.roundabout" : "click.roundabout", function() { methods.stopAutoplay.apply(self); return false; }); @@ -623,8 +630,6 @@ return this; }, - - // animation // ----------------------------------------------------------------------- From 88f6bc2981b9bca67563f42bf527aeea1a8cda14 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 9 Apr 2013 16:58:08 +0100 Subject: [PATCH 2/3] removing unnecessary flag --- jquery.roundabout.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/jquery.roundabout.js b/jquery.roundabout.js index 090f7bf..f2d8d51 100644 --- a/jquery.roundabout.js +++ b/jquery.roundabout.js @@ -109,8 +109,7 @@ childInFocus: -1, touchMoveStartPosition: null, stopAnimation: false, - lastAnimationStep: false, - touchSupported: null + lastAnimationStep: false }; methods = { From a12b13a584c5a80b2d998147afeed8b2deae4b6b Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 9 Apr 2013 17:02:08 +0100 Subject: [PATCH 3/3] removed console.log --- jquery.roundabout.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/jquery.roundabout.js b/jquery.roundabout.js index f2d8d51..c06de45 100644 --- a/jquery.roundabout.js +++ b/jquery.roundabout.js @@ -139,12 +139,6 @@ holderCSSPosition = (self.css("position") !== "static") ? self.css("position") : "relative", touchSupported = ('ontouchstart' in window); - console.log(touchSupported); - $("#checker").text(touchSupported); - if (touchSupported) { - - } - self .css({ // starting styles padding: 0,