@@ -15,14 +15,21 @@ function isOverlayVisible(){
15
15
16
16
let overlayHandlerContent
17
17
18
+ let overlayContainer = document . getElementById ( 'overlayContainer' )
19
+ let accountSelectContent = document . getElementById ( 'accountSelectContent' )
20
+
18
21
/**
19
22
* Overlay keydown handler for a non-dismissable overlay.
20
23
*
21
24
* @param {KeyboardEvent } e The keydown event.
22
25
*/
23
26
function overlayKeyHandler ( e ) {
24
27
if ( e . key === 'Enter' || e . key === 'Escape' ) {
25
- document . getElementById ( overlayHandlerContent ) . getElementsByClassName ( 'overlayKeybindEnter' ) [ 0 ] . click ( )
28
+ if ( overlayContainer . hasAttribute ( 'popup' ) ) {
29
+ toggleOverlay ( false )
30
+ } else {
31
+ document . getElementById ( overlayHandlerContent ) . getElementsByClassName ( 'overlayKeybindEnter' ) [ 0 ] . click ( )
32
+ }
26
33
}
27
34
}
28
35
/**
@@ -64,8 +71,9 @@ function bindOverlayKeys(state, content, dismissable){
64
71
* @param {boolean } toggleState True to display, false to hide.
65
72
* @param {boolean } dismissable Optional. True to show the dismiss option, otherwise false.
66
73
* @param {string } content Optional. The content div to be shown.
74
+ * @param {boolean } popup Optional. True to show the overlay as a popup that is easily dismissable and interactible.
67
75
*/
68
- function toggleOverlay ( toggleState , dismissable = false , content = 'overlayContent' ) {
76
+ function toggleOverlay ( toggleState , dismissable = false , content = 'overlayContent' , popup = false ) {
69
77
if ( toggleState == null ) {
70
78
toggleState = ! document . getElementById ( 'main' ) . hasAttribute ( 'overlay' )
71
79
}
@@ -75,6 +83,8 @@ function toggleOverlay(toggleState, dismissable = false, content = 'overlayConte
75
83
}
76
84
bindOverlayKeys ( toggleState , content , dismissable )
77
85
if ( toggleState ) {
86
+ overlayContainer . setAttribute ( 'content' , content )
87
+ overlayContainer . setAttribute ( 'popup' , popup )
78
88
document . getElementById ( 'main' ) . setAttribute ( 'overlay' , true )
79
89
// Make things untabbable.
80
90
$ ( '#main *' ) . attr ( 'tabindex' , '-1' )
@@ -94,6 +104,7 @@ function toggleOverlay(toggleState, dismissable = false, content = 'overlayConte
94
104
}
95
105
} )
96
106
} else {
107
+ overlayContainer . removeAttribute ( 'content' )
97
108
document . getElementById ( 'main' ) . removeAttribute ( 'overlay' )
98
109
// Make things tabbable.
99
110
$ ( '#main *' ) . removeAttr ( 'tabindex' )
@@ -119,7 +130,21 @@ function toggleOverlay(toggleState, dismissable = false, content = 'overlayConte
119
130
120
131
async function toggleServerSelection ( toggleState ) {
121
132
await prepareServerSelectionList ( )
122
- toggleOverlay ( toggleState , true , 'serverSelectContent' )
133
+ toggleOverlay ( toggleState , false , 'serverSelectContent' , true )
134
+ }
135
+
136
+ async function toggleAccountSelection ( toggleState , popup = false ) {
137
+ if ( popup ) {
138
+ // set the accountSelectActions div to display: none to avoid colliding with the validateSelectedAccount function
139
+ document . getElementById ( 'accountSelectActions' ) . style . display = 'none'
140
+ } else {
141
+ // set the overlayContainer div to display: block, this is not done while closing the overlay because of the fadeOut effect
142
+ document . getElementById ( 'accountSelectActions' ) . style . display = 'block'
143
+ }
144
+
145
+ // show the overlay
146
+ await prepareAccountSelectionList ( )
147
+ toggleOverlay ( toggleState , false , 'accountSelectContent' , popup )
123
148
}
124
149
125
150
/**
@@ -169,27 +194,9 @@ function setDismissHandler(handler){
169
194
}
170
195
}
171
196
172
- /* Server Select View */
173
-
174
- document . getElementById ( 'serverSelectConfirm' ) . addEventListener ( 'click' , async ( ) => {
175
- const listings = document . getElementsByClassName ( 'serverListing' )
176
- for ( let i = 0 ; i < listings . length ; i ++ ) {
177
- if ( listings [ i ] . hasAttribute ( 'selected' ) ) {
178
- const serv = ( await DistroAPI . getDistribution ( ) ) . getServerById ( listings [ i ] . getAttribute ( 'servid' ) )
179
- updateSelectedServer ( serv )
180
- refreshServerStatus ( true )
181
- toggleOverlay ( false )
182
- return
183
- }
184
- }
185
- // None are selected? Not possible right? Meh, handle it.
186
- if ( listings . length > 0 ) {
187
- const serv = ( await DistroAPI . getDistribution ( ) ) . getServerById ( listings [ i ] . getAttribute ( 'servid' ) )
188
- updateSelectedServer ( serv )
189
- toggleOverlay ( false )
190
- }
191
- } )
197
+ /* Account Select button */
192
198
199
+ // Bind account select confirm button.
193
200
document . getElementById ( 'accountSelectConfirm' ) . addEventListener ( 'click' , async ( ) => {
194
201
const listings = document . getElementsByClassName ( 'accountListing' )
195
202
for ( let i = 0 ; i < listings . length ; i ++ ) {
@@ -218,51 +225,73 @@ document.getElementById('accountSelectConfirm').addEventListener('click', async
218
225
}
219
226
} )
220
227
221
- // Bind server select cancel button.
222
- document . getElementById ( 'serverSelectCancel' ) . addEventListener ( 'click' , ( ) => {
223
- toggleOverlay ( false )
224
- } )
225
-
228
+ // Bind account select cancel button.
226
229
document . getElementById ( 'accountSelectCancel' ) . addEventListener ( 'click' , ( ) => {
227
230
$ ( '#accountSelectContent' ) . fadeOut ( 250 , ( ) => {
228
231
$ ( '#overlayContent' ) . fadeIn ( 250 )
229
232
} )
230
233
} )
231
234
232
- function setServerListingHandlers ( ) {
235
+
236
+ // Bind account select manage button.
237
+ document . getElementById ( 'accountSelectManage' ) . addEventListener ( 'click' , async ( ) => {
238
+ await prepareSettings ( )
239
+ switchView ( getCurrentView ( ) , VIEWS . settings , 500 , 500 , ( ) => {
240
+ settingsNavItemListener ( document . getElementById ( 'settingsNavAccount' ) , false )
241
+ } )
242
+ toggleOverlay ( false )
243
+ } )
244
+
245
+ // Make the Server Selection background clickable to close the overlay.
246
+ overlayContainer . addEventListener ( 'click' , e => {
247
+ if ( e . target === overlayContainer ) {
248
+ // This function only works if the overlay is a popup
249
+ if ( overlayContainer . hasAttribute ( 'popup' ) ) {
250
+ toggleOverlay ( false )
251
+ }
252
+ }
253
+ } )
254
+
255
+ async function setServerListingHandlers ( ) {
233
256
const listings = Array . from ( document . getElementsByClassName ( 'serverListing' ) )
234
- listings . map ( ( val ) => {
235
- val . onclick = e => {
236
- if ( val . hasAttribute ( 'selected' ) ) {
237
- return
238
- }
239
- const cListings = document . getElementsByClassName ( 'serverListing' )
240
- for ( let i = 0 ; i < cListings . length ; i ++ ) {
241
- if ( cListings [ i ] . hasAttribute ( 'selected' ) ) {
242
- cListings [ i ] . removeAttribute ( 'selected' )
243
- }
244
- }
245
- val . setAttribute ( 'selected' , '' )
246
- document . activeElement . blur ( )
257
+ listings . map ( async ( val ) => {
258
+ val . onclick = async e => {
259
+ const serv = ( await DistroAPI . getDistribution ( ) ) . getServerById ( val . getAttribute ( 'servid' ) )
260
+ updateSelectedServer ( serv )
261
+ refreshServerStatus ( true )
262
+ toggleOverlay ( false )
247
263
}
248
264
} )
249
265
}
250
266
251
- function setAccountListingHandlers ( ) {
267
+ async function setAccountListingHandlers ( ) {
252
268
const listings = Array . from ( document . getElementsByClassName ( 'accountListing' ) )
253
- listings . map ( ( val ) => {
254
- val . onclick = e => {
255
- if ( val . hasAttribute ( 'selected' ) ) {
269
+ listings . map ( async ( val ) => {
270
+ val . onclick = async e => {
271
+ // popup mode
272
+ if ( overlayContainer . hasAttribute ( 'popup' ) ) {
273
+ const authAcc = ConfigManager . setSelectedAccount ( val . getAttribute ( 'uuid' ) )
274
+ ConfigManager . save ( )
275
+ updateSelectedAccount ( authAcc )
276
+ if ( getCurrentView ( ) === VIEWS . settings ) {
277
+ await prepareSettings ( )
278
+ }
279
+ toggleOverlay ( false )
280
+ validateSelectedAccount ( )
256
281
return
257
- }
258
- const cListings = document . getElementsByClassName ( 'accountListing' )
259
- for ( let i = 0 ; i < cListings . length ; i ++ ) {
260
- if ( cListings [ i ] . hasAttribute ( 'selected' ) ) {
261
- cListings [ i ] . removeAttribute ( 'selected' )
282
+ } else {
283
+ if ( val . hasAttribute ( 'selected' ) ) {
284
+ return
285
+ }
286
+ const cListings = document . getElementsByClassName ( 'accountListing' )
287
+ for ( let i = 0 ; i < cListings . length ; i ++ ) {
288
+ if ( cListings [ i ] . hasAttribute ( 'selected' ) ) {
289
+ cListings [ i ] . removeAttribute ( 'selected' )
290
+ }
262
291
}
292
+ val . setAttribute ( 'selected' , '' )
293
+ document . activeElement . blur ( )
263
294
}
264
- val . setAttribute ( 'selected' , '' )
265
- document . activeElement . blur ( )
266
295
}
267
296
} )
268
297
}
@@ -304,7 +333,7 @@ function populateAccountListings(){
304
333
const accounts = Array . from ( Object . keys ( accountsObj ) , v => accountsObj [ v ] )
305
334
let htmlString = ''
306
335
for ( let i = 0 ; i < accounts . length ; i ++ ) {
307
- htmlString += `<button class="accountListing" uuid="${ accounts [ i ] . uuid } " ${ i === 0 ? 'selected' : '' } >
336
+ htmlString += `<button class="accountListing" uuid="${ accounts [ i ] . uuid } " ${ ! i && ! overlayContainer . hasAttribute ( "popup" ) ? 'selected' : '' } >
308
337
<img src="https://mc-heads.net/head/${ accounts [ i ] . uuid } /40">
309
338
<div class="accountListingName">${ accounts [ i ] . displayName } </div>
310
339
</button>`
@@ -315,10 +344,10 @@ function populateAccountListings(){
315
344
316
345
async function prepareServerSelectionList ( ) {
317
346
await populateServerListings ( )
318
- setServerListingHandlers ( )
347
+ await setServerListingHandlers ( )
319
348
}
320
349
321
- function prepareAccountSelectionList ( ) {
350
+ async function prepareAccountSelectionList ( ) {
322
351
populateAccountListings ( )
323
- setAccountListingHandlers ( )
352
+ await setAccountListingHandlers ( )
324
353
}
0 commit comments