2018-04-26 00:11:10 +00:00
|
|
|
/**
|
|
|
|
* Script for overlay.ejs
|
|
|
|
*/
|
2017-11-30 08:00:06 +00:00
|
|
|
|
2018-04-06 16:33:20 +00:00
|
|
|
/* Overlay Wrapper Functions */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggle the visibility of the overlay.
|
|
|
|
*
|
|
|
|
* @param {boolean} toggleState True to display, false to hide.
|
2018-04-15 02:20:59 +00:00
|
|
|
* @param {boolean} dismissable Optional. True to show the dismiss option, otherwise false.
|
2018-04-25 21:06:10 +00:00
|
|
|
* @param {string} content Optional. The content div to be shown.
|
2018-04-06 16:33:20 +00:00
|
|
|
*/
|
2018-04-25 21:06:10 +00:00
|
|
|
function toggleOverlay(toggleState, dismissable = false, content = 'overlayContent'){
|
2018-04-06 16:33:20 +00:00
|
|
|
if(toggleState == null){
|
|
|
|
toggleState = !document.getElementById('main').hasAttribute('overlay')
|
|
|
|
}
|
2018-04-25 21:06:10 +00:00
|
|
|
if(typeof dismissable === 'string'){
|
|
|
|
content = dismissable
|
|
|
|
}
|
2018-04-06 16:33:20 +00:00
|
|
|
if(toggleState){
|
|
|
|
document.getElementById('main').setAttribute('overlay', true)
|
2018-04-25 21:06:10 +00:00
|
|
|
$('#' + content).parent().children().hide()
|
|
|
|
$('#' + content).show()
|
|
|
|
if(dismissable){
|
|
|
|
$('#overlayDismiss').show()
|
|
|
|
} else {
|
|
|
|
$('#overlayDismiss').hide()
|
|
|
|
}
|
|
|
|
$('#overlayContainer').fadeIn(250)
|
2018-04-06 16:33:20 +00:00
|
|
|
} else {
|
|
|
|
document.getElementById('main').removeAttribute('overlay')
|
2018-04-25 21:06:10 +00:00
|
|
|
$('#overlayContainer').fadeOut(250, () => {
|
|
|
|
$('#' + content).parent().children().hide()
|
|
|
|
$('#' + content).show()
|
|
|
|
if(dismissable){
|
|
|
|
$('#overlayDismiss').show()
|
|
|
|
} else {
|
|
|
|
$('#overlayDismiss').hide()
|
|
|
|
}
|
2018-04-15 02:20:59 +00:00
|
|
|
})
|
2018-04-07 17:29:40 +00: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-15 02:20:59 +00:00
|
|
|
* @param {string} dismiss Dismiss button text.
|
2018-04-07 17:29:40 +00:00
|
|
|
*/
|
2018-04-15 02:20:59 +00:00
|
|
|
function setOverlayContent(title, description, acknowledge, dismiss = 'Dismiss'){
|
2018-04-07 17:29:40 +00:00
|
|
|
document.getElementById('overlayTitle').innerHTML = title
|
|
|
|
document.getElementById('overlayDesc').innerHTML = description
|
|
|
|
document.getElementById('overlayAcknowledge').innerHTML = acknowledge
|
2018-04-15 02:20:59 +00:00
|
|
|
document.getElementById('overlayDismiss').innerHTML = dismiss
|
2018-04-07 17:29:40 +00: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 16:33:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-15 02:20:59 +00: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-26 06:39:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Server Select View */
|
|
|
|
|
2018-04-26 22:41:26 +00:00
|
|
|
document.getElementById('serverSelectConfirm').addEventListener('click', () => {
|
|
|
|
const listings = document.getElementsByClassName('serverListing')
|
|
|
|
for(let i=0; i<listings.length; i++){
|
|
|
|
if(listings[i].hasAttribute('selected')){
|
|
|
|
const serv = AssetGuard.getServerById(ConfigManager.getGameDirectory(), listings[i].getAttribute('servid'))
|
|
|
|
ConfigManager.setSelectedServer(serv != null ? serv.id : null)
|
|
|
|
updateSelectedServer(serv != null ? serv.name : null)
|
|
|
|
setLaunchEnabled(serv != null)
|
|
|
|
refreshServerStatus(true)
|
|
|
|
toggleOverlay(false)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// None are selected? Not possible right? Meh, handle it.
|
|
|
|
if(listings.length > 0){
|
|
|
|
ConfigManager.setSelectedServer(listings[0].getAttribute('servid'))
|
|
|
|
updateSelectedServer()
|
|
|
|
toggleOverlay(false)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-04-26 06:39:47 +00:00
|
|
|
// Bind server select cancel button.
|
|
|
|
document.getElementById('serverSelectCancel').addEventListener('click', () => {
|
|
|
|
toggleOverlay(false)
|
2018-04-26 22:41:26 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
function setServerListingHandlers(){
|
|
|
|
const listings = Array.from(document.getElementsByClassName('serverListing'))
|
|
|
|
listings.map((val) => {
|
|
|
|
val.onclick = e => {
|
|
|
|
if(val.hasAttribute('selected')){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
const cListings = document.getElementsByClassName('serverListing')
|
|
|
|
for(let i=0; i<cListings.length; i++){
|
|
|
|
if(cListings[i].hasAttribute('selected')){
|
|
|
|
cListings[i].removeAttribute('selected')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
val.setAttribute('selected', '')
|
|
|
|
document.activeElement.blur()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
setServerListingHandlers()
|