From: ardeshireshghi Date: Wed, 31 Aug 2016 08:51:07 +0000 (+0100) Subject: Avoid reveal modal closing upon click of an element not in the DOM X-Git-Tag: v6.2.4-rc1~36^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F9146%2Fhead;p=thirdparty%2Ffoundation%2Ffoundation-sites.git 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 --- 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(); }); }