2018-04-25 17:11:10 -07:00
|
|
|
/**
|
|
|
|
* Script for overlay.ejs
|
|
|
|
*/
|
2017-11-30 00:00:06 -08:00
|
|
|
|
2018-04-06 09:33:20 -07:00
|
|
|
/* Overlay Wrapper Functions */
|
|
|
|
|
2018-08-07 01:16:15 -07:00
|
|
|
/**
|
|
|
|
* Check to see if the overlay is visible.
|
|
|
|
*
|
|
|
|
* @returns {boolean} Whether or not the overlay is visible.
|
|
|
|
*/
|
|
|
|
function isOverlayVisible(){
|
2018-08-07 01:41:26 -07:00
|
|
|
return document.getElementById('main').hasAttribute('overlay')
|
2018-08-07 01:16:15 -07:00
|
|
|
}
|
|
|
|
|
2018-08-22 07:54:09 -07:00
|
|
|
let overlayHandlerContent
|
|
|
|
|
2024-05-12 07:19:51 -07:00
|
|
|
let overlayContainer = document.getElementById('overlayContainer')
|
|
|
|
let accountSelectContent = document.getElementById('accountSelectContent')
|
|
|
|
|
2018-08-22 07:54:09 -07:00
|
|
|
/**
|
|
|
|
* Overlay keydown handler for a non-dismissable overlay.
|
|
|
|
*
|
|
|
|
* @param {KeyboardEvent} e The keydown event.
|
|
|
|
*/
|
|
|
|
function overlayKeyHandler (e){
|
|
|
|
if(e.key === 'Enter' || e.key === 'Escape'){
|
2024-05-21 08:20:49 -07:00
|
|
|
if (overlayContainer.hasAttribute('popup')) {
|
|
|
|
toggleOverlay(false)
|
|
|
|
} else {
|
|
|
|
document.getElementById(overlayHandlerContent).getElementsByClassName('overlayKeybindEnter')[0].click()
|
|
|
|
}
|
2018-08-22 07:54:09 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Overlay keydown handler for a dismissable overlay.
|
|
|
|
*
|
|
|
|
* @param {KeyboardEvent} e The keydown event.
|
|
|
|
*/
|
|
|
|
function overlayKeyDismissableHandler (e){
|
|
|
|
if(e.key === 'Enter'){
|
|
|
|
document.getElementById(overlayHandlerContent).getElementsByClassName('overlayKeybindEnter')[0].click()
|
|
|
|
} else if(e.key === 'Escape'){
|
|
|
|
document.getElementById(overlayHandlerContent).getElementsByClassName('overlayKeybindEsc')[0].click()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bind overlay keydown listeners for escape and exit.
|
|
|
|
*
|
|
|
|
* @param {boolean} state Whether or not to add new event listeners.
|
|
|
|
* @param {string} content The overlay content which will be shown.
|
|
|
|
* @param {boolean} dismissable Whether or not the overlay is dismissable
|
|
|
|
*/
|
|
|
|
function bindOverlayKeys(state, content, dismissable){
|
|
|
|
overlayHandlerContent = content
|
|
|
|
document.removeEventListener('keydown', overlayKeyHandler)
|
|
|
|
document.removeEventListener('keydown', overlayKeyDismissableHandler)
|
|
|
|
if(state){
|
|
|
|
if(dismissable){
|
|
|
|
document.addEventListener('keydown', overlayKeyDismissableHandler)
|
|
|
|
} else {
|
|
|
|
document.addEventListener('keydown', overlayKeyHandler)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-06 09:33:20 -07:00
|
|
|
/**
|
|
|
|
* Toggle the visibility of the overlay.
|
|
|
|
*
|
|
|
|
* @param {boolean} toggleState True to display, false to hide.
|
2018-04-14 19:20:59 -07:00
|
|
|
* @param {boolean} dismissable Optional. True to show the dismiss option, otherwise false.
|
2018-04-25 14:06:10 -07:00
|
|
|
* @param {string} content Optional. The content div to be shown.
|
2024-05-21 08:20:49 -07:00
|
|
|
* @param {boolean} popup Optional. True to show the overlay as a popup that is easily dismissable and interactible.
|
2018-04-06 09:33:20 -07:00
|
|
|
*/
|
2024-05-21 08:20:49 -07:00
|
|
|
function toggleOverlay(toggleState, dismissable = false, content = 'overlayContent', popup = false){
|
2018-04-06 09:33:20 -07:00
|
|
|
if(toggleState == null){
|
|
|
|
toggleState = !document.getElementById('main').hasAttribute('overlay')
|
|
|
|
}
|
2018-04-25 14:06:10 -07:00
|
|
|
if(typeof dismissable === 'string'){
|
|
|
|
content = dismissable
|
2018-05-08 03:34:16 -07:00
|
|
|
dismissable = false
|
2018-04-25 14:06:10 -07:00
|
|
|
}
|
2018-08-22 07:54:09 -07:00
|
|
|
bindOverlayKeys(toggleState, content, dismissable)
|
2018-04-06 09:33:20 -07:00
|
|
|
if(toggleState){
|
|
|
|
document.getElementById('main').setAttribute('overlay', true)
|
2024-05-12 07:19:51 -07:00
|
|
|
overlayContainer.setAttribute('content', content)
|
2024-05-21 08:20:49 -07:00
|
|
|
overlayContainer.setAttribute('popup', popup)
|
2024-05-12 07:19:51 -07:00
|
|
|
|
2018-04-29 19:36:28 -07:00
|
|
|
// Make things untabbable.
|
2018-07-22 10:31:15 -07:00
|
|
|
$('#main *').attr('tabindex', '-1')
|
2018-04-25 14:06:10 -07:00
|
|
|
$('#' + content).parent().children().hide()
|
|
|
|
$('#' + content).show()
|
|
|
|
if(dismissable){
|
|
|
|
$('#overlayDismiss').show()
|
|
|
|
} else {
|
|
|
|
$('#overlayDismiss').hide()
|
|
|
|
}
|
2018-06-21 17:54:07 -07:00
|
|
|
$('#overlayContainer').fadeIn({
|
|
|
|
duration: 250,
|
|
|
|
start: () => {
|
|
|
|
if(getCurrentView() === VIEWS.settings){
|
|
|
|
document.getElementById('settingsContainer').style.backgroundColor = 'transparent'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2018-04-06 09:33:20 -07:00
|
|
|
} else {
|
|
|
|
document.getElementById('main').removeAttribute('overlay')
|
2024-05-12 07:19:51 -07:00
|
|
|
overlayContainer.removeAttribute('content')
|
|
|
|
|
2018-04-29 15:39:57 -07:00
|
|
|
// Make things tabbable.
|
2018-07-22 10:31:15 -07:00
|
|
|
$('#main *').removeAttr('tabindex')
|
2018-06-21 17:54:07 -07:00
|
|
|
$('#overlayContainer').fadeOut({
|
|
|
|
duration: 250,
|
|
|
|
start: () => {
|
|
|
|
if(getCurrentView() === VIEWS.settings){
|
|
|
|
document.getElementById('settingsContainer').style.backgroundColor = 'rgba(0, 0, 0, 0.50)'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
complete: () => {
|
|
|
|
$('#' + content).parent().children().hide()
|
|
|
|
$('#' + content).show()
|
|
|
|
if(dismissable){
|
|
|
|
$('#overlayDismiss').show()
|
|
|
|
} else {
|
|
|
|
$('#overlayDismiss').hide()
|
|
|
|
}
|
2018-04-25 14:06:10 -07:00
|
|
|
}
|
2018-04-14 19:20:59 -07:00
|
|
|
})
|
2018-04-07 10:29:40 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-24 18:02:18 -08:00
|
|
|
async function toggleServerSelection(toggleState){
|
|
|
|
await prepareServerSelectionList()
|
2024-05-21 08:20:49 -07:00
|
|
|
toggleOverlay(toggleState, false, 'serverSelectContent', true)
|
2018-04-26 21:04:09 -07:00
|
|
|
}
|
|
|
|
|
2024-05-12 07:19:51 -07:00
|
|
|
async function toggleAccountSelection(toggleState, popup = false){
|
|
|
|
if (popup) {
|
2024-05-21 08:20:49 -07:00
|
|
|
// set the accountSelectActions div to display: none to avoid colliding with the validateSelectedAccount function
|
2024-05-12 07:19:51 -07:00
|
|
|
document.getElementById('accountSelectActions').style.display = 'none'
|
|
|
|
} else {
|
2024-05-21 08:20:49 -07:00
|
|
|
// set the overlayContainer div to display: block, this is not done while closing the overlay because of the fadeOut effect
|
2024-05-12 07:19:51 -07:00
|
|
|
document.getElementById('accountSelectActions').style.display = 'block'
|
|
|
|
}
|
|
|
|
|
|
|
|
// show the overlay
|
|
|
|
await prepareAccountSelectionList()
|
2024-05-21 08:20:49 -07:00
|
|
|
toggleOverlay(toggleState, false, 'accountSelectContent', popup)
|
2024-05-12 07:19:51 -07:00
|
|
|
}
|
|
|
|
|
2018-04-07 10:29:40 -07:00
|
|
|
/**
|
|
|
|
* Set the content of the overlay.
|
|
|
|
*
|
|
|
|
* @param {string} title Overlay title text.
|
|
|
|
* @param {string} description Overlay description text.
|
|
|
|
* @param {string} acknowledge Acknowledge button text.
|
2018-04-14 19:20:59 -07:00
|
|
|
* @param {string} dismiss Dismiss button text.
|
2018-04-07 10:29:40 -07:00
|
|
|
*/
|
2023-11-25 15:31:41 -08:00
|
|
|
function setOverlayContent(title, description, acknowledge, dismiss = Lang.queryJS('overlay.dismiss')){
|
2018-04-07 10:29:40 -07:00
|
|
|
document.getElementById('overlayTitle').innerHTML = title
|
|
|
|
document.getElementById('overlayDesc').innerHTML = description
|
|
|
|
document.getElementById('overlayAcknowledge').innerHTML = acknowledge
|
2018-04-14 19:20:59 -07:00
|
|
|
document.getElementById('overlayDismiss').innerHTML = dismiss
|
2018-04-07 10:29:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the onclick handler of the overlay acknowledge button.
|
|
|
|
* If the handler is null, a default handler will be added.
|
|
|
|
*
|
|
|
|
* @param {function} handler
|
|
|
|
*/
|
|
|
|
function setOverlayHandler(handler){
|
|
|
|
if(handler == null){
|
|
|
|
document.getElementById('overlayAcknowledge').onclick = () => {
|
|
|
|
toggleOverlay(false)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
document.getElementById('overlayAcknowledge').onclick = handler
|
2018-04-06 09:33:20 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-14 19:20:59 -07:00
|
|
|
/**
|
|
|
|
* Set the onclick handler of the overlay dismiss button.
|
|
|
|
* If the handler is null, a default handler will be added.
|
|
|
|
*
|
|
|
|
* @param {function} handler
|
|
|
|
*/
|
|
|
|
function setDismissHandler(handler){
|
|
|
|
if(handler == null){
|
|
|
|
document.getElementById('overlayDismiss').onclick = () => {
|
|
|
|
toggleOverlay(false)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
document.getElementById('overlayDismiss').onclick = handler
|
|
|
|
}
|
2018-04-25 23:39:47 -07:00
|
|
|
}
|
|
|
|
|
2024-05-12 07:19:51 -07:00
|
|
|
/* Account Select button */
|
2018-04-26 15:41:26 -07:00
|
|
|
|
2024-05-12 07:19:51 -07:00
|
|
|
// Bind account select confirm button.
|
2023-02-24 18:02:18 -08:00
|
|
|
document.getElementById('accountSelectConfirm').addEventListener('click', async () => {
|
2018-05-09 19:23:37 -07:00
|
|
|
const listings = document.getElementsByClassName('accountListing')
|
|
|
|
for(let i=0; i<listings.length; i++){
|
|
|
|
if(listings[i].hasAttribute('selected')){
|
|
|
|
const authAcc = ConfigManager.setSelectedAccount(listings[i].getAttribute('uuid'))
|
|
|
|
ConfigManager.save()
|
|
|
|
updateSelectedAccount(authAcc)
|
2022-02-11 16:51:28 -08:00
|
|
|
if(getCurrentView() === VIEWS.settings) {
|
2023-02-24 18:02:18 -08:00
|
|
|
await prepareSettings()
|
2022-02-11 16:51:28 -08:00
|
|
|
}
|
2018-05-09 19:23:37 -07:00
|
|
|
toggleOverlay(false)
|
|
|
|
validateSelectedAccount()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// None are selected? Not possible right? Meh, handle it.
|
|
|
|
if(listings.length > 0){
|
|
|
|
const authAcc = ConfigManager.setSelectedAccount(listings[0].getAttribute('uuid'))
|
|
|
|
ConfigManager.save()
|
|
|
|
updateSelectedAccount(authAcc)
|
2022-02-11 16:51:28 -08:00
|
|
|
if(getCurrentView() === VIEWS.settings) {
|
2023-02-24 18:02:18 -08:00
|
|
|
await prepareSettings()
|
2022-02-11 16:51:28 -08:00
|
|
|
}
|
2018-05-09 19:23:37 -07:00
|
|
|
toggleOverlay(false)
|
|
|
|
validateSelectedAccount()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2024-05-12 06:10:48 -07:00
|
|
|
// Bind account select cancel button.
|
2018-05-09 19:23:37 -07:00
|
|
|
document.getElementById('accountSelectCancel').addEventListener('click', () => {
|
|
|
|
$('#accountSelectContent').fadeOut(250, () => {
|
|
|
|
$('#overlayContent').fadeIn(250)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2024-05-12 07:19:51 -07:00
|
|
|
// Bind account select manage button.
|
|
|
|
document.getElementById('accountSelectManage').addEventListener('click', async () => {
|
|
|
|
await prepareSettings()
|
|
|
|
switchView(getCurrentView(), VIEWS.settings, 500, 500, () => {
|
|
|
|
settingsNavItemListener(document.getElementById('settingsNavAccount'), false)
|
|
|
|
})
|
|
|
|
toggleOverlay(false)
|
|
|
|
})
|
|
|
|
|
2024-05-12 06:10:48 -07:00
|
|
|
// Make the Server Selection background clickable to close the overlay.
|
|
|
|
overlayContainer.addEventListener('click', e => {
|
2024-05-12 07:19:51 -07:00
|
|
|
if (e.target === overlayContainer) {
|
2024-05-21 08:20:49 -07:00
|
|
|
// This function only works if the overlay is a popup
|
|
|
|
if(overlayContainer.hasAttribute('popup')) {
|
2024-05-12 07:19:51 -07:00
|
|
|
toggleOverlay(false)
|
|
|
|
}
|
2024-05-12 06:10:48 -07:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
async function setServerListingHandlers(){
|
2018-04-26 15:41:26 -07:00
|
|
|
const listings = Array.from(document.getElementsByClassName('serverListing'))
|
2024-05-12 06:10:48 -07:00
|
|
|
listings.map(async (val) => {
|
|
|
|
val.onclick = async e => {
|
|
|
|
const serv = (await DistroAPI.getDistribution()).getServerById(val.getAttribute('servid'))
|
|
|
|
updateSelectedServer(serv)
|
|
|
|
refreshServerStatus(true)
|
|
|
|
toggleOverlay(false)
|
2018-04-26 15:41:26 -07:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2018-04-26 21:04:09 -07:00
|
|
|
|
2024-05-12 07:19:51 -07:00
|
|
|
async function setAccountListingHandlers(){
|
2018-05-09 19:23:37 -07:00
|
|
|
const listings = Array.from(document.getElementsByClassName('accountListing'))
|
2024-05-12 07:19:51 -07:00
|
|
|
listings.map(async (val) => {
|
|
|
|
val.onclick = async e => {
|
|
|
|
// popup mode
|
2024-05-21 08:20:49 -07:00
|
|
|
if(overlayContainer.hasAttribute('popup')){
|
2024-05-12 07:19:51 -07:00
|
|
|
const authAcc = ConfigManager.setSelectedAccount(val.getAttribute('uuid'))
|
|
|
|
ConfigManager.save()
|
|
|
|
updateSelectedAccount(authAcc)
|
|
|
|
if(getCurrentView() === VIEWS.settings) {
|
|
|
|
await prepareSettings()
|
|
|
|
}
|
|
|
|
toggleOverlay(false)
|
|
|
|
validateSelectedAccount()
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
if(val.hasAttribute('selected')){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
const cListings = document.getElementsByClassName('accountListing')
|
|
|
|
for(let i=0; i<cListings.length; i++){
|
|
|
|
if(cListings[i].hasAttribute('selected')){
|
|
|
|
cListings[i].removeAttribute('selected')
|
|
|
|
}
|
2018-05-09 19:23:37 -07:00
|
|
|
}
|
2024-05-12 07:19:51 -07:00
|
|
|
val.setAttribute('selected', '')
|
|
|
|
document.activeElement.blur()
|
2018-05-09 19:23:37 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-02-24 18:02:18 -08:00
|
|
|
async function populateServerListings(){
|
|
|
|
const distro = await DistroAPI.getDistribution()
|
2018-04-26 21:04:09 -07:00
|
|
|
const giaSel = ConfigManager.getSelectedServer()
|
2023-02-24 18:02:18 -08:00
|
|
|
const servers = distro.servers
|
2018-07-22 10:31:15 -07:00
|
|
|
let htmlString = ''
|
2018-07-22 08:40:15 -07:00
|
|
|
for(const serv of servers){
|
2023-02-24 18:02:18 -08:00
|
|
|
htmlString += `<button class="serverListing" servid="${serv.rawServer.id}" ${serv.rawServer.id === giaSel ? 'selected' : ''}>
|
|
|
|
<img class="serverListingImg" src="${serv.rawServer.icon}"/>
|
2018-04-26 21:04:09 -07:00
|
|
|
<div class="serverListingDetails">
|
2023-02-24 18:02:18 -08:00
|
|
|
<span class="serverListingName">${serv.rawServer.name}</span>
|
|
|
|
<span class="serverListingDescription">${serv.rawServer.description}</span>
|
2018-04-26 21:04:09 -07:00
|
|
|
<div class="serverListingInfo">
|
2023-02-24 18:02:18 -08:00
|
|
|
<div class="serverListingVersion">${serv.rawServer.minecraftVersion}</div>
|
|
|
|
<div class="serverListingRevision">${serv.rawServer.version}</div>
|
|
|
|
${serv.rawServer.mainServer ? `<div class="serverListingStarWrapper">
|
2018-04-26 21:04:09 -07:00
|
|
|
<svg id="Layer_1" viewBox="0 0 107.45 104.74" width="20px" height="20px">
|
|
|
|
<defs>
|
|
|
|
<style>.cls-1{fill:#fff;}.cls-2{fill:none;stroke:#fff;stroke-miterlimit:10;}</style>
|
|
|
|
</defs>
|
|
|
|
<path class="cls-1" d="M100.93,65.54C89,62,68.18,55.65,63.54,52.13c2.7-5.23,18.8-19.2,28-27.55C81.36,31.74,63.74,43.87,58.09,45.3c-2.41-5.37-3.61-26.52-4.37-39-.77,12.46-2,33.64-4.36,39-5.7-1.46-23.3-13.57-33.49-20.72,9.26,8.37,25.39,22.36,28,27.55C39.21,55.68,18.47,62,6.52,65.55c12.32-2,33.63-6.06,39.34-4.9-.16,5.87-8.41,26.16-13.11,37.69,6.1-10.89,16.52-30.16,21-33.9,4.5,3.79,14.93,23.09,21,34C70,86.84,61.73,66.48,61.59,60.65,67.36,59.49,88.64,63.52,100.93,65.54Z"/>
|
|
|
|
<circle class="cls-2" cx="53.73" cy="53.9" r="38"/>
|
|
|
|
</svg>
|
2023-10-05 12:26:32 -07:00
|
|
|
<span class="serverListingStarTooltip">${Lang.queryJS('settings.serverListing.mainServer')}</span>
|
2018-07-22 10:31:15 -07:00
|
|
|
</div>` : ''}
|
2018-04-26 21:04:09 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</button>`
|
|
|
|
}
|
|
|
|
document.getElementById('serverSelectListScrollable').innerHTML = htmlString
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-05-09 19:23:37 -07:00
|
|
|
function populateAccountListings(){
|
|
|
|
const accountsObj = ConfigManager.getAuthAccounts()
|
2018-07-22 10:31:15 -07:00
|
|
|
const accounts = Array.from(Object.keys(accountsObj), v=>accountsObj[v])
|
|
|
|
let htmlString = ''
|
2018-05-09 19:23:37 -07:00
|
|
|
for(let i=0; i<accounts.length; i++){
|
2024-05-21 08:20:49 -07:00
|
|
|
htmlString += `<button class="accountListing" uuid="${accounts[i].uuid}" ${!i && !overlayContainer.hasAttribute("popup") ? 'selected' : ''}>
|
2021-07-19 08:08:55 -07:00
|
|
|
<img src="https://mc-heads.net/head/${accounts[i].uuid}/40">
|
2018-05-09 19:23:37 -07:00
|
|
|
<div class="accountListingName">${accounts[i].displayName}</div>
|
|
|
|
</button>`
|
|
|
|
}
|
|
|
|
document.getElementById('accountSelectListScrollable').innerHTML = htmlString
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-02-24 18:02:18 -08:00
|
|
|
async function prepareServerSelectionList(){
|
|
|
|
await populateServerListings()
|
2024-05-12 06:10:48 -07:00
|
|
|
await setServerListingHandlers()
|
2018-05-09 19:23:37 -07:00
|
|
|
}
|
|
|
|
|
2024-05-12 07:19:51 -07:00
|
|
|
async function prepareAccountSelectionList(){
|
2018-05-09 19:23:37 -07:00
|
|
|
populateAccountListings()
|
2024-05-12 07:19:51 -07:00
|
|
|
await setAccountListingHandlers()
|
2018-04-26 21:04:09 -07:00
|
|
|
}
|