11define ( 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 ;
0 commit comments