-
Notifications
You must be signed in to change notification settings - Fork 7.6k
fixes issues #1270 #1271 #1272, ESC key handling with popups #1276
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,49 +36,42 @@ define(function (require, exports, module) { | |
var _popUps = []; | ||
|
||
function _removePopUp($popUp, index, visible) { | ||
var initiallyInDOM = $popUp.data("initiallyInDOM"), | ||
removeHandler = $popUp.data("removeHandler"); | ||
var autoAddRemove = $popUp.data("PopUpManager-autoAddRemove"), | ||
removeHandler = $popUp.data("PopUpManager-removeHandler"); | ||
|
||
visible = visible || $popUp.find(":visible").length > 0; | ||
|
||
if (removeHandler && visible) { | ||
removeHandler(); | ||
} | ||
|
||
if (!initiallyInDOM) { | ||
if (autoAddRemove) { | ||
$popUp.remove(); | ||
_popUps = _popUps.slice(index); | ||
} | ||
|
||
_popUps = _popUps.slice(index); | ||
} | ||
|
||
/** | ||
* Add Esc key handling for pop-up DOM elements that persist in the DOM. | ||
* These pop-up elements must handle appearance (i.e. opening) themselves. | ||
* | ||
* @param {!jQuery} $popUp jQuery object for the DOM element pop-up | ||
* @param {function} removeHandler Pop-up specific remove (e.g. display:none or DOM removal) | ||
*/ | ||
function configurePopUp($popUp, removeHandler) { | ||
_popUps.push($popUp[0]); | ||
|
||
$popUp.data("initiallyInDOM", true); | ||
$popUp.data("removeHandler", removeHandler); | ||
} | ||
|
||
|
||
/** | ||
* Add Esc key handling for transient DOM elements. Immediately adds | ||
* the element to the DOM if it's not already attached. | ||
* Add Esc key handling for a popup DOM element. | ||
* | ||
* @param {!jQuery} $popUp jQuery object for the DOM element pop-up | ||
* @param {function} removeHandler Pop-up specific remove (e.g. display:none or DOM removal) | ||
* @param {?Boolean} autoAddRemove - Specify true to indicate the PopUPManager should | ||
* add/remove the popup from the DOM when the popup is open/closed. Specifiy false | ||
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. typo: Specifiy 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. another typo: PopUPManager |
||
* when the popup is either always persistant in the DOM or the add/remove is handled | ||
* external to the PopupManager | ||
* | ||
*/ | ||
function addPopUp($popUp, removeHandler) { | ||
var initiallyInDOM = $popUp.parent().length === 1; | ||
function addPopUp($popUp, removeHandler, autoAddRemove) { | ||
autoAddRemove = autoAddRemove || false; | ||
|
||
configurePopUp($popUp, removeHandler, initiallyInDOM); | ||
_popUps.push($popUp[0]); | ||
$popUp.data("PopUpManager-autoAddRemove", autoAddRemove); | ||
$popUp.data("PopUpManager-removeHandler", removeHandler); | ||
|
||
if (!initiallyInDOM) { | ||
if (autoAddRemove) { | ||
$(window.document.body).append($popUp); | ||
} | ||
} | ||
|
@@ -91,16 +84,15 @@ define(function (require, exports, module) { | |
*/ | ||
function removePopUp($popUp) { | ||
var index = _popUps.indexOf($popUp[0]), | ||
initiallyInDOM = $popUp.data("initiallyInDOM"), | ||
removeHandler = $popUp.data("removeHandler"); | ||
removeHandler = $popUp.data("PopUpManager-removeHandler"); | ||
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. removeHandler doesn't seem to be used in this function. |
||
|
||
if (index >= 0) { | ||
_removePopUp($popUp, index); | ||
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. _removePopUp is a private function that's only called in 2 places. Seems unnecessary to have the 3rd parameter optional. Why not specify it here, then remove the logic that sets the default value? 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. I ended up removing _removePopup() function completely since complexity of having this helper function isn't worth the savings of reusing the "index" var. I don't expect there to be many visible popups at one time, so computing the index more than once isn't costly. I also made the other simplifications you suggested. |
||
} | ||
} | ||
|
||
function _keydownCaptureListener(keyEvent) { | ||
if (keyEvent.keyCode !== 27) { | ||
if (keyEvent.keyCode !== 27) { // escape key | ||
return; | ||
} | ||
|
||
|
@@ -132,5 +124,4 @@ define(function (require, exports, module) { | |
|
||
exports.addPopUp = addPopUp; | ||
exports.removePopUp = removePopUp; | ||
exports.configurePopUp = configurePopUp; | ||
}); |
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.
REMINDER: need to update new context menu unit test I added in pull request #1273 to uncomment line that checks for contextMenuClose event.
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.
Randy, I've pushed my changes so you can update test in the pull request?