From bd15be1545fd9d0e534d743e67257fc92e435486 Mon Sep 17 00:00:00 2001 From: Paul Serby Date: Wed, 16 Mar 2011 14:33:03 +0000 Subject: [PATCH 1/3] Adding an afterChange option that is called after the slide has changed --- jquery.jshowoff.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/jquery.jshowoff.js b/jquery.jshowoff.js index 90dc8a2..1ea6366 100644 --- a/jquery.jshowoff.js +++ b/jquery.jshowoff.js @@ -41,17 +41,20 @@ speed : time each slide is shown [integer, milliseconds, defaults to 3000] effect : 'fade', hoverPause : true, links : true, - speed : 3000 + speed : 3000, + afterChange : $.noop }; // merge default global variables with custom variables, modifying 'config' - if (settings) $.extend(true, config, settings); + if (settings) { + $.extend(true, config, settings); + } // make sure speed is at least 20ms longer than changeSpeed if (config.speed < (config.changeSpeed+20)) { alert('jShowOff: Make speed at least 20ms longer than changeSpeed; the fades aren\'t always right on time.'); return this; - }; + } // create slideshow for each matching element invoked by .jshowoff() this.each(function(i) { @@ -64,7 +67,7 @@ speed : time each slide is shown [integer, milliseconds, defaults to 3000] var preloadedImg = []; var howManyInstances = $('.jshowoff').length+1; var uniqueClass = 'jshowoff-'+howManyInstances; - var cssClass = config.cssClass != undefined ? config.cssClass : ''; + var cssClass = config.cssClass !== undefined ? config.cssClass : ''; // set up wrapper @@ -81,7 +84,7 @@ speed : time each slide is shown [integer, milliseconds, defaults to 3000] // add controls if(config.controls){ addControls(); - if(config.autoPlay==false){ + if(config.autoPlay === false){ $('.'+uniqueClass+'-play').addClass(uniqueClass+'-paused jshowoff-paused').text(config.controlText.play); }; }; @@ -123,24 +126,25 @@ speed : time each slide is shown [integer, milliseconds, defaults to 3000] function slideDir(dir) { newSlideDir = dir=='right' ? 'left' : 'right'; oldSlideDir = dir=='left' ? 'left' : 'right'; - }; + } counter >= oldCounter ? slideDir('left') : slideDir('right') ; $(gallery[counter]).clone().appendTo($cont).slideIt({direction:newSlideDir,changeSpeed:config.changeSpeed}); if($cont.children().length>1){ - $cont.children().eq(0).css('position','absolute').slideIt({direction:oldSlideDir,showHide:'hide',changeSpeed:config.changeSpeed},function(){$(this).remove();}); + $cont.children().eq(0).css('position','absolute').slideIt({direction:oldSlideDir,showHide:'hide',changeSpeed:config.changeSpeed},function(){$(this).remove();config.afterChange()}); }; } else if (config.effect=='fade') { $(gallery[counter]).clone().appendTo($cont).hide().fadeIn(config.changeSpeed,function(){if($.browser.msie)this.style.removeAttribute('filter');}); if($cont.children().length>1){ - $cont.children().eq(0).css('position','absolute').fadeOut(config.changeSpeed,function(){$(this).remove();}); + $cont.children().eq(0).css('position','absolute').fadeOut(config.changeSpeed,function(){$(this).remove();config.afterChange();}); }; } else if (config.effect=='none') { $(gallery[counter]).clone().appendTo($cont); if($cont.children().length>1){ $cont.children().eq(0).css('position','absolute').remove(); + config.afterChange(); }; }; @@ -280,4 +284,4 @@ speed : time each slide is shown [integer, milliseconds, defaults to 3000] }; // end closure -})(jQuery); \ No newline at end of file +})(jQuery); From 0e0711640af9fec98abc0f4d0a42a6e5b5440d41 Mon Sep 17 00:00:00 2001 From: Paul Serby Date: Wed, 16 Mar 2011 14:39:42 +0000 Subject: [PATCH 2/3] Adding comment for new afterChange option --- jquery.jshowoff.js | 1 + 1 file changed, 1 insertion(+) diff --git a/jquery.jshowoff.js b/jquery.jshowoff.js index 1ea6366..854531d 100644 --- a/jquery.jshowoff.js +++ b/jquery.jshowoff.js @@ -18,6 +18,7 @@ effect : transition effect [string: 'fade', 'slideLeft' or 'none', defaults to hoverPause : whether to pause on hover [boolean, defaults to true] links : whether to create & display numeric links to each slide [boolean, defaults to true] speed : time each slide is shown [integer, milliseconds, defaults to 3000] +afterChange : called after a slide has changed [function, function() {}] */ From ffac7a242020b84bbe29cfd2095728a7d17138c6 Mon Sep 17 00:00:00 2001 From: Paul Serby Date: Wed, 16 Mar 2011 14:55:45 +0000 Subject: [PATCH 3/3] Passing counter to the callback so you know which slide your now on --- jquery.jshowoff.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jquery.jshowoff.js b/jquery.jshowoff.js index 854531d..9bfaeed 100644 --- a/jquery.jshowoff.js +++ b/jquery.jshowoff.js @@ -134,18 +134,18 @@ afterChange : called after a slide has changed [function, function() {}] $(gallery[counter]).clone().appendTo($cont).slideIt({direction:newSlideDir,changeSpeed:config.changeSpeed}); if($cont.children().length>1){ - $cont.children().eq(0).css('position','absolute').slideIt({direction:oldSlideDir,showHide:'hide',changeSpeed:config.changeSpeed},function(){$(this).remove();config.afterChange()}); + $cont.children().eq(0).css('position','absolute').slideIt({direction:oldSlideDir,showHide:'hide',changeSpeed:config.changeSpeed},function(){$(this).remove();config.afterChange(counter)}); }; } else if (config.effect=='fade') { $(gallery[counter]).clone().appendTo($cont).hide().fadeIn(config.changeSpeed,function(){if($.browser.msie)this.style.removeAttribute('filter');}); if($cont.children().length>1){ - $cont.children().eq(0).css('position','absolute').fadeOut(config.changeSpeed,function(){$(this).remove();config.afterChange();}); + $cont.children().eq(0).css('position','absolute').fadeOut(config.changeSpeed,function(){$(this).remove();config.afterChange(counter);}); }; } else if (config.effect=='none') { $(gallery[counter]).clone().appendTo($cont); if($cont.children().length>1){ $cont.children().eq(0).css('position','absolute').remove(); - config.afterChange(); + config.afterChange(counter); }; };