diff --git a/jquery.jshowoff.js b/jquery.jshowoff.js index 90dc8a2..9bfaeed 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() {}] */ @@ -41,17 +42,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 +68,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 +85,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 +127,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(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();}); + $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(counter); }; }; @@ -280,4 +285,4 @@ speed : time each slide is shown [integer, milliseconds, defaults to 3000] }; // end closure -})(jQuery); \ No newline at end of file +})(jQuery);