I\'m trying to get a piece of our JavaScript run after some 3rd party code makes a modal dialog appear. I saw a pretty neat idea of hijacking the jQuery show function, but unfor
I haven't tested anything, but sharing a few things I know
show
has an optional second parameter - easing. jQuery automatically detects this, but for a perfect a solution you have to consider this.
_oldShow.apply(obj, [speed, null, newCallback]);
A callback makes sense only when there is a delay, that means value for speed
. I hope your afterShow
event will be triggered if there is a delay. If there is no delay you can trigger it after invoking _oldShow
, like this
_oldShow.apply(obj, [speed, null, newCallback]);
if(!speed){
obj.trigger('afterShow');
}
EDIT:
I tired a few things and frpm what I learned I would suggest you to create a new show function instead of overriding.
jQuery.fn.extend({
show2:function( speed, easing, callback ) {
this.trigger('beforeShow');
this.show(speed, easing, function(){
$(this).trigger('afterShow');
if ($.isFunction(callback)) {
callback.apply(this);
}
});
if(!speed){
this.trigger('afterShow');
}
}
});
demo: http://jsfiddle.net/9F8ea/2/