-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for dismissible option breaking with multiple popovers open #250
Open
sbrodkey
wants to merge
3
commits into
sandywalker:master
Choose a base branch
from
sbrodkey:issue248
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
|
||
<html> | ||
<head> | ||
<title>Issue (#248) - Dismissible option not working with multiple popovers</title> | ||
|
||
<link rel="stylesheet" href="../src/jquery.webui-popover.css" /> | ||
<script src="jquery.js" ></script> | ||
<script src="bootstrap.js" ></script> | ||
<script src="../src/jquery.webui-popover.js" ></script> | ||
|
||
<style type="text/css"> | ||
#popover1, #popover3 { | ||
margin-left: 50px; | ||
margin-right: 100px; | ||
} | ||
.pop { | ||
display: inline-block; | ||
border: 1px solid silver; | ||
padding: 2px; | ||
} | ||
.popContainer { | ||
margin-bottom: 60px; | ||
} | ||
.desc { | ||
margin-bottom: 20px; | ||
} | ||
</style> | ||
<script type="text/javascript"> | ||
$(document).ready(function() { | ||
$("#popover1").webuiPopover({ | ||
dismissible: false, | ||
placement: "bottom", | ||
content: "I'm not dismissible" | ||
}); | ||
$("#popover2").webuiPopover({ | ||
dismissible: true, | ||
placement: "bottom", | ||
content: "I'm dismissible" | ||
}); | ||
|
||
$("#popover3").webuiPopover({ | ||
multi: true, | ||
dismissible: true, | ||
placement: "bottom", | ||
content: "I'm popover 3" | ||
}); | ||
$("#popover4").webuiPopover({ | ||
multi: true, | ||
dismissible: true, | ||
placement: "bottom", | ||
content: "I'm popover 4" | ||
}); | ||
}); | ||
</script> | ||
</head> | ||
<body> | ||
<div class="desc"> | ||
<b>Problem of issue#248</b>: Opening a dismissible popover causes non-dismissible popovers to become dismissible.<br /><br /> | ||
|
||
<b>Initial conditions</b>: Popover 1 is not dismissible. Popover 2 is dismissible.<br /><br /> | ||
|
||
Step 1) Click popover 1. Observe that it is not dismissible. Close it.<br /> | ||
Step 2) Click popover 2. Observe that it is dismissible. Close it.<br /> | ||
Step 3) Click popover 1. Observe that it is now dismissible!<br /> | ||
</div> | ||
<div class="popContainer"> | ||
<div id="popover1" class="pop">Popover 1</div> | ||
<div id="popover2" class="pop">Popover 2</div> | ||
</div> | ||
|
||
<div class="desc"> | ||
<b>With issue#248 solution in place, ensure that</b>: When an outside click is done for two open popovers, | ||
both should dismiss themselves through their own bodyClickHandler individually.<br /><br /> | ||
|
||
<b>Initial conditions</b>: Both popovers are dismissible and have multi:true.<br /><br /> | ||
|
||
Step 1) Open Popover 3 and Popover 4 so that they're both open at the same time.<br /> | ||
Step 2) Click outside of both of them. Make sure both close.<br /> | ||
</div> | ||
<div> | ||
<div id="popover3" class="pop">Popover 3</div> | ||
<div id="popover4" class="pop">Popover 4</div> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,7 +78,6 @@ | |
var _srcElements = []; | ||
var backdrop = $('<div class="webui-popover-backdrop"></div>'); | ||
var _globalIdSeed = 0; | ||
var _isBodyEventHandled = false; | ||
var _offsetOut = -2000; // the value offset out of the screen | ||
var $document = $(document); | ||
|
||
|
@@ -727,19 +726,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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Haven't tested on mobile, but if we like the separation this provides in the lines below, we could add a unique id here as well. |
||
} 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)); | ||
} | ||
}, | ||
|
||
|
@@ -770,7 +768,7 @@ | |
}, | ||
escapeHandler: function(e) { | ||
if (e.keyCode === 27) { | ||
this.hideAll(); | ||
this.hide(); | ||
} | ||
}, | ||
bodyTouchStartHandler: function(e) { | ||
|
@@ -785,7 +783,6 @@ | |
}); | ||
}, | ||
bodyClickHandler: function(e) { | ||
_isBodyEventHandled = true; | ||
var canHide = true; | ||
for (var i = 0; i < _srcElements.length; i++) { | ||
var pop = getPopFromElement(_srcElements[i]); | ||
|
@@ -804,7 +801,7 @@ | |
} | ||
} | ||
if (canHide) { | ||
hideAllPop(); | ||
this.hide(); | ||
} | ||
}, | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This global setting was preventing the bodyClickHandler from being able to bind multiple times. It would only allow one bind. We want as many binds as there are popovers to happen.