From a32749e51ec5a998d05e1ce321d6cfacf14e99ff Mon Sep 17 00:00:00 2001 From: q2apro Date: Thu, 15 Aug 2019 18:42:17 +0300 Subject: [PATCH] Fix for dismissible option breaking with multiple popovers open https://github.com/sandywalker/webui-popover/pull/250 Samuel Brodkey on Sep 6, 2017 --- demo/test-issue248.html | 86 +++++++++++++++++++++++++++++++++++++ src/jquery.webui-popover.js | 19 ++++---- 2 files changed, 94 insertions(+), 11 deletions(-) create mode 100644 demo/test-issue248.html diff --git a/demo/test-issue248.html b/demo/test-issue248.html new file mode 100644 index 0000000..3c90dd0 --- /dev/null +++ b/demo/test-issue248.html @@ -0,0 +1,86 @@ + + + + + Issue (#248) - Dismissible option not working with multiple popovers + + + + + + + + + + +
+ Problem of issue#248: Opening a dismissible popover causes non-dismissible popovers to become dismissible.

+ + Initial conditions: Popover 1 is not dismissible. Popover 2 is dismissible.

+ + Step 1) Click popover 1. Observe that it is not dismissible. Close it.
+ Step 2) Click popover 2. Observe that it is dismissible. Close it.
+ Step 3) Click popover 1. Observe that it is now dismissible!
+
+
+
Popover 1
+
Popover 2
+
+ +
+ With issue#248 solution in place, ensure that: When an outside click is done for two open popovers, + both should dismiss themselves through their own bodyClickHandler individually.

+ + Initial conditions: Both popovers are dismissible and have multi:true.

+ + Step 1) Open Popover 3 and Popover 4 so that they're both open at the same time.
+ Step 2) Click outside of both of them. Make sure both close.
+
+
+
Popover 3
+
Popover 4
+
+ + diff --git a/src/jquery.webui-popover.js b/src/jquery.webui-popover.js index 8768c4a..b224b6e 100644 --- a/src/jquery.webui-popover.js +++ b/src/jquery.webui-popover.js @@ -78,7 +78,6 @@ var _srcElements = []; var backdrop = $('
'); var _globalIdSeed = 0; - var _isBodyEventHandled = false; var _offsetOut = -2000; // the value offset out of the screen var $document = $(document); @@ -739,19 +738,18 @@ }, bindBodyEvents: function() { - if (_isBodyEventHandled) { - return; - } if (this.options.dismissible && this.getTrigger() === 'click') { if (isMobile) { $document.off('touchstart.webui-popover').on('touchstart.webui-popover', $.proxy(this.bodyTouchStartHandler, this)); } else { - $document.off('keyup.webui-popover').on('keyup.webui-popover', $.proxy(this.escapeHandler, this)); - $document.off('click.webui-popover').on('click.webui-popover', $.proxy(this.bodyClickHandler, this)); + $document.off('keyup.webui-popover' + this._idSeed) + .on('keyup.webui-popover' + this._idSeed, $.proxy(this.escapeHandler, this)); + $document.off('click.webui-popover' + this._idSeed) + .on('click.webui-popover' + this._idSeed, $.proxy(this.bodyClickHandler, this)); } } else if (this.getTrigger() === 'hover') { - $document.off('touchend.webui-popover') - .on('touchend.webui-popover', $.proxy(this.bodyClickHandler, this)); + $document.off('touchend.webui-popover' + this._idSeed) + .on('touchend.webui-popover' + this._idSeed, $.proxy(this.bodyClickHandler, this)); } }, @@ -782,7 +780,7 @@ }, escapeHandler: function(e) { if (e.keyCode === 27) { - this.hideAll(); + this.hide(); } }, bodyTouchStartHandler: function(e) { @@ -797,7 +795,6 @@ }); }, bodyClickHandler: function(e) { - _isBodyEventHandled = true; var canHide = true; for (var i = 0; i < _srcElements.length; i++) { var pop = getPopFromElement(_srcElements[i]); @@ -816,7 +813,7 @@ } } if (canHide) { - hideAllPop(); + this.hide(); } },