From 2f442eb059da6beda2fe2c2e200f7f8e6d227c22 Mon Sep 17 00:00:00 2001 From: Vladimir Siljkovic Date: Sat, 8 Dec 2018 23:27:30 +0100 Subject: [PATCH] New: Add method to destroy all popups ($.fn.popup.destroyall) Initial version, not stable. --- jquery.popupoverlay.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/jquery.popupoverlay.js b/jquery.popupoverlay.js index b9cb97d..8161a45 100644 --- a/jquery.popupoverlay.js +++ b/jquery.popupoverlay.js @@ -205,7 +205,7 @@ } else { // Handler: Show popup when clicked on `open` element - $(document).on('click', openelement, function (event) { + $(document).on('click.jqp', openelement, function (event) { event.preventDefault(); var ord = $(this).data('popup-ordinal'); @@ -831,6 +831,19 @@ }); }; + // destroy all popups + $.fn.popup.destroyall = function () { + // TODO: create tests to check if we can use `hide` method (perhaps we'll need to remove transitions) + // or we need another way of removing the data when destroying. + for(var i=0; i < visiblePopupsArray.length; i++) { + $('#' + visiblePopupsArray[i]).popup('hide'); + } + $('.popup_wrapper').remove(); + $('.popup_background').remove(); + // visiblePopupsArray = []; // TODO: check if we need this for SPA and popups with fadeOut animation and scrolllock + $(document).off('click.jqp'); + }; + $.fn.popup.defaults = { type: 'overlay', absolute: false,