Skip to content

Commit 6a3eca1

Browse files
authored
fix(toast): make sure element does still exist before transition ends
In situations where a toast is going to be closed via Javascript while the hide animation is still in progress, access to the element is not possible anymore leading to a console.error
1 parent fdd3cc8 commit 6a3eca1

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/definitions/modules/toast.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -389,13 +389,15 @@ $.fn.toast = function(parameters) {
389389
onBeforeHide: function(callback){
390390
callback = $.isFunction(callback)?callback : function(){};
391391
if(settings.transition.closeEasing !== ''){
392-
$toastBox.css('opacity',0);
393-
$toastBox.wrap('<div/>').parent().slideUp(500,settings.transition.closeEasing,function(){
394-
if($toastBox){
395-
$toastBox.parent().remove();
396-
callback.call($toastBox);
397-
}
398-
});
392+
if($toastBox) {
393+
$toastBox.css('opacity', 0);
394+
$toastBox.wrap('<div/>').parent().slideUp(500, settings.transition.closeEasing, function () {
395+
if ($toastBox) {
396+
$toastBox.parent().remove();
397+
callback.call($toastBox);
398+
}
399+
});
400+
}
399401
} else {
400402
callback.call($toastBox);
401403
}

0 commit comments

Comments
 (0)