Skip to content
Browse files

Add missing method stop() and start(). Fix autoplay option.

  • Loading branch information...
1 parent e0b08cb commit 086ee6db91dbd577b6c8f7e9f832e8896e70b7f7 @lusever committed Apr 21, 2012
Showing with 38 additions and 17 deletions.
  1. +38 −17 jquery.touchslider.js
View
55 jquery.touchslider.js
@@ -1,10 +1,11 @@
/*
-TouchSlider 0.9
+TouchSlider 0.95
Licensed under the MIT license.
http://touchslider.com
*/
/*jslint browser: true, undef: true, sloppy: true, vars: true, white: true, nomen: true, plusplus: true, maxerr: 50, indent: 4 */
/*global WebKitCSSMatrix: false, jQuery: false, getComputedStyle: false */
+
(function($, undefined) {
window.touchSlider = function(options) {
options = options || {};
@@ -19,7 +20,7 @@ http://touchslider.com
}
options = $.extend({
- autoPlay: false,
+ autoplay: false,
delay: 3000,
margin: 5,
viewport: "." + namespace + "-viewport",
@@ -36,7 +37,9 @@ http://touchslider.com
current: 0,
step: step,
next: next,
- prev: prev
+ prev: prev,
+ start: start,
+ stop: stop
},
isTouchWebkit = "ontouchstart" in window && "WebKitCSSMatrix" in window,
touchstart = "touchstart", touchmove = "touchmove", touchend = "touchend",
@@ -118,7 +121,7 @@ http://touchslider.com
if (toIndex >= slides.length) {
toIndex = 0;
} else if (toIndex < 0){
- toIndex = slides.length - 1;
+ toIndex = slides.length - 1;
}
var duration = options.duration,
node = slides.eq(toIndex),
@@ -417,25 +420,41 @@ http://touchslider.com
}
/* Autoplay */
- var autoPlayTimeout, mouseInViewport = false;
- if (options.autoPlay) {
- viewport.hover(function() {
- clearTimeout(autoPlayTimeout);
- mouseInViewport = true;
- }, function() {
- mouseInViewport = false;
- autoPlay();
- });
- }
+ var mouseInViewport = false,
+ isPlay = false,
+ autoPlayTimeout;
+
+ viewport.hover(function() {
+ clearTimeout(autoPlayTimeout);
+ mouseInViewport = true;
+ }, function() {
+ mouseInViewport = false;
+ autoPlay();
+ });
+
function autoPlay() {
- if (options.autoPlay && !mouseInViewport) {
+ if (isPlay) {
+ start();
+ }
+ }
+
+ function start() {
+ isPlay = true;
+ if (!mouseInViewport) {
clearTimeout(autoPlayTimeout);
autoPlayTimeout = setTimeout(function() {
if (!switching.moving && !mouseInViewport) {
next();
}
}, options.delay);
}
+ return options.container;
+ }
+
+ function stop() {
+ clearTimeout(autoPlayTimeout);
+ isPlay = false;
+ return options.container;
}
/* Navigation */
@@ -609,7 +628,9 @@ http://touchslider.com
initTouch();
}
- autoPlay();
+ if (options.autoplay) {
+ start();
+ }
container.data(namespace, ret);
};
@@ -619,5 +640,5 @@ http://touchslider.com
options.container = this;
touchSlider(options);
return this;
- }
+ };
}(jQuery));

0 comments on commit 086ee6d

Please sign in to comment.
Something went wrong with that request. Please try again.