From 5cc02a8f6aa92aeb0bc8cde20fcfa9ee61c185ae Mon Sep 17 00:00:00 2001 From: ardeshireshghi Date: Wed, 31 Aug 2016 09:51:07 +0100 Subject: [PATCH] Avoid reveal modal closing upon click of an element not in the DOM Added check to make sure e.target is still in the DOM. I came across a bug when I created a google map canvas inside reveal modal, whereby upon closing the info popup on a map marker, the entire reveal modal gets closed. This is because when the overlay click handler is invoked, Google code has already removed the e.target element and the overlay handler only gets a ghost element and can not find it in the modal element --- js/foundation.reveal.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/js/foundation.reveal.js b/js/foundation.reveal.js index 02f99c77a..b38f8efb6 100644 --- a/js/foundation.reveal.js +++ b/js/foundation.reveal.js @@ -157,7 +157,11 @@ class Reveal { if (this.options.closeOnClick && this.options.overlay) { this.$overlay.off('.zf.reveal').on('click.zf.reveal', function(e) { - if (e.target === _this.$element[0] || $.contains(_this.$element[0], e.target)) { return; } + if (e.target === _this.$element[0] || + $.contains(_this.$element[0], e.target) || + !$.contains(document, e.target)) { + return; + } _this.close(); }); } @@ -293,7 +297,9 @@ class Reveal { if (!this.options.overlay && this.options.closeOnClick && !this.options.fullScreen) { $('body').on('click.zf.reveal', function(e) { - if (e.target === _this.$element[0] || $.contains(_this.$element[0], e.target)) { return; } + if (e.target === _this.$element[0] || + $.contains(_this.$element[0], e.target) || + !$.contains(document, e.target)) { return; } _this.close(); }); } -- 2.47.2