Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

New afterChange callback #29

Open
wants to merge 3 commits into from

1 participant

@serby

I've added a new callback that gets called after the slide has change.

This change doesn't effect backwards compatibility of the plugin.

@serby

Also I started to fix a few JSLint recommendation but though I'd better check you're happy with that before I do any more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 14 additions and 9 deletions.
  1. +14 −9 jquery.jshowoff.js
View
23 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);
+})(jQuery);
Something went wrong with that request. Please try again.