diff --git a/jquery.roundabout.js b/jquery.roundabout.js index df83da2..c06de45 100644 --- a/jquery.roundabout.js +++ b/jquery.roundabout.js @@ -40,7 +40,6 @@ */ (function($) { "use strict"; - var defaults, internalData, methods; // add default shape @@ -137,7 +136,8 @@ 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); self .css({ // starting styles @@ -182,7 +182,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 +199,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 +210,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 +219,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 +228,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 +237,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 +623,6 @@ return this; }, - - // animation // -----------------------------------------------------------------------