Skip to content

Commit 1c9d793

Browse files
committed
fix: use popup manager api's and improve readability
1 parent 47dfc3d commit 1c9d793

File tree

3 files changed

+28
-40
lines changed

3 files changed

+28
-40
lines changed

src/extensionsIntegrated/Phoenix/profile-menu.js

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
define(function (require, exports, module) {
22
const Mustache = require("thirdparty/mustache/mustache");
3+
const PopUpManager = require("widgets/PopUpManager");
34

45
// HTML templates
56
const loginTemplate = require("text!./html/login-dialog.html");
@@ -57,25 +58,9 @@ define(function (require, exports, module) {
5758
*/
5859
function closePopup() {
5960
if ($popup) {
60-
$popup.remove();
61+
PopUpManager.removePopUp($popup);
6162
$popup = null;
6263
isPopupVisible = false;
63-
64-
// remove global click handler
65-
$(document).off("click.profilePopup");
66-
}
67-
}
68-
69-
/**
70-
* handle clicks outside the popup to close it
71-
*/
72-
function handleDocumentClick(e) {
73-
// If popup exists and click is outside the popup
74-
if ($popup && $popup.length && !$popup[0].contains(e.target)) {
75-
// If the click is not on the user-profile-button (which would toggle the popup)
76-
if (e.target.id !== "user-profile-button" && !$(e.target).closest("#user-profile-button").length) {
77-
closePopup();
78-
}
7964
}
8065
}
8166

@@ -135,6 +120,12 @@ define(function (require, exports, module) {
135120

136121
positionPopup();
137122

123+
PopUpManager.addPopUp($popup, function() {
124+
$popup.remove();
125+
$popup = null;
126+
isPopupVisible = false;
127+
}, true, { closeCurrentPopups: true });
128+
138129
// event handlers for buttons
139130
$popup.find("#phoenix-signin-btn").on("click", function () {
140131
_handleSignInBtnClick();
@@ -146,11 +137,12 @@ define(function (require, exports, module) {
146137
closePopup();
147138
});
148139

149-
// Set up global click handler to close popup when clicking outside
150-
// Delay attaching to avoid immediate closing
151-
setTimeout(function () {
152-
$(document).on("click.profilePopup", handleDocumentClick);
153-
}, 0);
140+
// handle window resize to reposition popup
141+
$(window).on("resize.profilePopup", function () {
142+
if (isPopupVisible) {
143+
positionPopup();
144+
}
145+
});
154146
}
155147

156148
/**
@@ -177,6 +169,12 @@ define(function (require, exports, module) {
177169
isPopupVisible = true;
178170
positionPopup();
179171

172+
PopUpManager.addPopUp($popup, function() {
173+
$popup.remove();
174+
$popup = null;
175+
isPopupVisible = false;
176+
}, true, { closeCurrentPopups: true });
177+
180178
$popup.find("#phoenix-account-btn").on("click", function () {
181179
_handleAccountDetailsBtnClick();
182180
closePopup();
@@ -192,11 +190,12 @@ define(function (require, exports, module) {
192190
closePopup();
193191
});
194192

195-
// Set up global click handler to close popup when clicking outside
196-
// Delay attaching to avoid immediate closing
197-
setTimeout(function () {
198-
$(document).on("click.profilePopup", handleDocumentClick);
199-
}, 0);
193+
// handle window resize to reposition popup
194+
$(window).on("resize.profilePopup", function () {
195+
if (isPopupVisible) {
196+
positionPopup();
197+
}
198+
});
200199
}
201200

202201
/**
@@ -216,13 +215,6 @@ define(function (require, exports, module) {
216215
} else {
217216
showLoginPopup(data);
218217
}
219-
220-
// handle window resize to reposition popup
221-
$(window).on("resize.profilePopup", function () {
222-
if (isPopupVisible) {
223-
positionPopup();
224-
}
225-
});
226218
}
227219

228220
exports.init = init;

src/styles/Extn-UserProfile.less

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
overflow: hidden;
1010
position: absolute;
1111
z-index: @z-index-brackets-context-menu-base;
12-
animation: dropdown 90ms cubic-bezier(0, .97, .2, .99);
12+
animation: user-profile-dropdown-animation 90ms cubic-bezier(0, .97, .2, .99);
1313
transform-origin: 0 0;
1414

1515
.popup-header {
@@ -240,7 +240,7 @@
240240
}
241241
}
242242

243-
@keyframes dropdown {
243+
@keyframes user-profile-dropdown-animation {
244244
0% { opacity: 0.5; transform: translate3d(0, 0, 0) scale(0.5); }
245245
100% { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
246246
}

src/styles/brackets.less

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -669,10 +669,6 @@ a, img {
669669
background-image: url("images/share-fill.svg");
670670
}
671671

672-
.help {
673-
background-image: url("images/discuss-icon.svg");
674-
}
675-
676672
.user {
677673
background-image: url("images/circle-user-solid.svg");
678674
}

0 commit comments

Comments
 (0)