2017-02-03 16:05:59 -06:00
|
|
|
/* Pop up Dialog Box */
|
2017-08-30 12:44:29 -05:00
|
|
|
let dialogBoxes = [];
|
2017-05-24 08:49:52 -05:00
|
|
|
|
|
|
|
//Close dialog box when clicking outside
|
2017-06-06 19:28:20 -05:00
|
|
|
$(document).click(function(event) {
|
|
|
|
if (dialogBoxOpened && dialogBoxes.length >= 1) {
|
|
|
|
if (!$(event.target).closest(dialogBoxes[0]).length){
|
|
|
|
dialogBoxes[0].remove();
|
|
|
|
dialogBoxes.splice(0, 1);
|
|
|
|
if (dialogBoxes.length == 0) {
|
|
|
|
dialogBoxOpened = false;
|
|
|
|
} else {
|
|
|
|
dialogBoxes[0].style.visibility = "visible";
|
2017-05-31 23:17:50 -05:00
|
|
|
}
|
2017-05-24 08:49:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-06-06 19:28:20 -05:00
|
|
|
|
2017-05-31 23:17:50 -05:00
|
|
|
//Dialog box close buttons
|
2017-06-06 19:28:20 -05:00
|
|
|
$(document).on('click', '.dialog-box-close-button', function( event ) {
|
|
|
|
if (dialogBoxOpened && dialogBoxes.length >= 1) {
|
|
|
|
dialogBoxes[0].remove();
|
|
|
|
dialogBoxes.splice(0, 1);
|
|
|
|
if (dialogBoxes.length == 0) {
|
|
|
|
dialogBoxOpened = false;
|
|
|
|
} else {
|
|
|
|
dialogBoxes[0].style.visibility = "visible";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2017-02-03 16:05:59 -06:00
|
|
|
|
2017-05-31 23:17:50 -05:00
|
|
|
var dialogBoxOpened = false;
|
2017-02-03 16:05:59 -06:00
|
|
|
|
2018-02-17 21:08:54 -06:00
|
|
|
function dialogBoxCreate(txt, preformatted=false) {
|
2017-05-31 23:17:50 -05:00
|
|
|
var container = document.createElement("div");
|
|
|
|
container.setAttribute("class", "dialog-box-container");
|
2017-08-30 12:44:29 -05:00
|
|
|
|
2017-05-31 23:17:50 -05:00
|
|
|
var content = document.createElement("div");
|
|
|
|
content.setAttribute("class", "dialog-box-content");
|
2017-08-30 12:44:29 -05:00
|
|
|
|
2017-05-31 23:17:50 -05:00
|
|
|
var closeButton = document.createElement("span");
|
|
|
|
closeButton.setAttribute("class", "dialog-box-close-button");
|
|
|
|
closeButton.innerHTML = "×"
|
2017-08-30 12:44:29 -05:00
|
|
|
|
2018-02-17 21:08:54 -06:00
|
|
|
var textE;
|
|
|
|
if (preformatted) {
|
|
|
|
// For text files as they are often computed data that
|
|
|
|
// shouldn't be wrapped and should retain tabstops.
|
|
|
|
textE = document.createElement("pre");
|
|
|
|
textE.innerHTML = txt;
|
|
|
|
} else {
|
|
|
|
textE = document.createElement("p");
|
|
|
|
textE.innerHTML = txt.replace(/(?:\r\n|\r|\n)/g, '<br>');
|
|
|
|
}
|
2017-08-30 12:44:29 -05:00
|
|
|
|
2017-05-31 23:17:50 -05:00
|
|
|
content.appendChild(closeButton);
|
|
|
|
content.appendChild(textE);
|
|
|
|
container.appendChild(content);
|
2017-08-30 12:44:29 -05:00
|
|
|
|
2017-05-31 23:17:50 -05:00
|
|
|
document.body.appendChild(container);
|
2017-06-06 19:28:20 -05:00
|
|
|
if (dialogBoxes.length >= 1) {
|
|
|
|
container.style.visibility = "hidden";
|
|
|
|
}
|
|
|
|
dialogBoxes.push(container);
|
2017-08-30 12:44:29 -05:00
|
|
|
|
2017-05-24 08:49:52 -05:00
|
|
|
setTimeout(function() {
|
|
|
|
dialogBoxOpened = true;
|
2017-06-06 19:28:20 -05:00
|
|
|
}, 400);
|
2017-08-30 12:44:29 -05:00
|
|
|
}
|
|
|
|
|
2017-09-19 13:38:03 -05:00
|
|
|
export {dialogBoxCreate, dialogBoxOpened};
|