+
+
+
diff --git a/index.html b/index.html
index 25e2d96..2f712a1 100644
--- a/index.html
+++ b/index.html
@@ -82,12 +82,12 @@
-->
-
+
diff --git a/jquery.blueberry.js b/jquery.blueberry.js
index 7c0a032..a3cbfcb 100644
--- a/jquery.blueberry.js
+++ b/jquery.blueberry.js
@@ -77,7 +77,7 @@
if(pager){
$('a', pager).click(function() {
//stop the timer
- clearTimeout(obj.play);
+ clearTimer();
//set the slide index based on pager index
next = $(this).parent().index();
//rotate the slides
@@ -110,27 +110,48 @@
current = next;
next = current >= slides.length-1 ? 0 : current+1;
};
+
//create a timer to control slide rotation interval
var rotateTimer = function(){
+ // clean up everyone do their share to avoid a
+ // crap load of timeouts floating around
+ clearTimer();
+
obj.play = setTimeout(function(){
//trigger slide rotate function at end of timer
rotate();
}, o.interval);
};
+
+ var clearTimer = function() {
+ if ( obj.play ) {
+ clearTimeout(obj.play);
+ obj.play = null;
+ }
+ }
+
+ var setHoverPause = function() {
+ if(o.hoverpause){
+ slides.hover(function(){
+ //stop the timer in mousein
+ clearTimer();
+ }, function(){
+ //start the timer on mouseout
+ rotateTimer();
+ });
+ }
+ }
+
+ var clearHover = function() {
+ if (o.hoverpause) {
+ slides.unbind('mouseenter mouseleave');
+ }
+ }
+
//start the timer for the first time
rotateTimer();
- //pause the slider on hover
- //disabled by default due to bug
- if(o.hoverpause){
- slides.hover(function(){
- //stop the timer in mousein
- clearTimeout(obj.play);
- }, function(){
- //start the timer on mouseout
- rotateTimer();
- });
- }
+ setHoverPause();
//calculate and set height based on image width/height ratio and specified line height
var setsize = function(){
@@ -146,36 +167,39 @@
setsize();
});
-
-
//Add keyboard navigation
-
- if(o.keynav){
+ if(o.keynav){
$(document).keyup(function(e){
-
switch (e.which) {
-
case 39: case 32: //right arrow & space
-
- clearTimeout(obj.play);
-
+ clearTimer();
rotate();
-
break;
-
-
- case 37: // left arrow
- clearTimeout(obj.play);
- next = current - 1;
+
+ case 37: // left arrow
+ clearTimer();
+ // feels like rotate should only be in charge of current/next
+ // and should update it to take direction parameter but
+ // this has least amount of impact
+ next = current - 1 < 0 ? slides.length -1 : current - 1;
rotate();
-
- break;
+ break;
}
-
- });
- }
-
-
+ });
+ }
+
+
+ // add stop and start events
+ $(this).on('blueberry.stop', function(e) {
+ clearTimer();
+ clearHover();
+ });
+
+ $(this).on('blueberry.start', function(e) {
+ rotateTimer();
+ setHoverPause();
+ });
+
});
}
});