Remove modal when creating a modal programicly
PlippiePlop opened this issue · 0 comments
Since closing a modal is not a problem with the trigger("reveal:close").
What about a trigger("reveal:remove").
What if you want to create a new modal by appending it to the body by clicking a element and parse in values dynamicly. Now it just adds multiple copies of the modal if creating a modal on the fly and closing it.
Just add following below line 125:
//Closing animation and remove modal
modal.bind('reveal:remove', function () {
if (!locked) {
lockModal();
if (options.animation == "fadeAndPop") {
modalBG.delay(options.animationspeed).fadeOut(options.animationspeed);
modal.animate({
"top": $(document).scrollTop() - topOffset + 'px',
"opacity": 0
}, options.animationspeed / 2, function () {
modal.css({ 'top': topMeasure, 'opacity': 1, 'visibility': 'hidden' });
unlockModal();
});
}
if (options.animation == "fade") {
modalBG.delay(options.animationspeed).fadeOut(options.animationspeed);
modal.animate({
"opacity": 0
}, options.animationspeed, function () {
modal.css({ 'opacity': 1, 'visibility': 'hidden', 'top': topMeasure });
unlockModal();
});
}
if (options.animation == "none") {
modal.css({ 'visibility': 'hidden', 'top': topMeasure });
modalBG.css({ 'display': 'none' });
}
}
modal.remove();
modalBG.remove();
modal.unbind('reveal:remove');
});