2021-07-14 00:40:23 +03:00
|
|
|
/** Handles the pop up windows (NewPixel, ResizeCanvas ecc)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
const Dialogue = (() => {
|
|
|
|
let currentOpenDialogue = "";
|
2021-07-14 23:48:53 +03:00
|
|
|
let dialogueOpen = true;
|
|
|
|
|
2022-02-23 19:16:23 +03:00
|
|
|
const popUpContainer = document.getElementById("pop-up-container") ?? document.createElement("div");
|
2021-07-14 00:40:23 +03:00
|
|
|
const cancelButtons = popUpContainer.getElementsByClassName('close-button');
|
|
|
|
|
2021-12-13 01:08:13 +03:00
|
|
|
Events.onCustom("esc-pressed", closeDialogue);
|
|
|
|
|
2021-07-14 00:40:23 +03:00
|
|
|
// Add click handlers for all cancel buttons
|
|
|
|
for (var i = 0; i < cancelButtons.length; i++) {
|
|
|
|
cancelButtons[i].addEventListener('click', function () {
|
|
|
|
closeDialogue();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Closes a dialogue window if the user clicks everywhere but in the current window
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
popUpContainer.addEventListener('click', function (e) {
|
|
|
|
if (e.target == popUpContainer)
|
|
|
|
closeDialogue();
|
|
|
|
});
|
|
|
|
|
|
|
|
/** Shows the dialogue window called dialogueName, which is a child of pop-up-container in pixel-editor.hbs
|
|
|
|
*
|
|
|
|
* @param {*} dialogueName The name of the window to show
|
|
|
|
* @param {*} trackEvent Should I track the GA event?
|
|
|
|
*/
|
|
|
|
function showDialogue (dialogueName, trackEvent) {
|
2022-02-23 19:16:23 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-07-14 00:40:23 +03:00
|
|
|
if (typeof trackEvent === 'undefined') trackEvent = true;
|
|
|
|
|
|
|
|
// Updating currently open dialogue
|
|
|
|
currentOpenDialogue = dialogueName;
|
|
|
|
// The pop up window is open
|
|
|
|
dialogueOpen = true;
|
|
|
|
// Showing the pop up container
|
|
|
|
popUpContainer.style.display = 'block';
|
|
|
|
|
|
|
|
// Showing the window
|
|
|
|
document.getElementById(dialogueName).style.display = 'block';
|
|
|
|
|
|
|
|
// If I'm opening the palette window, I initialize the colour picker
|
2021-12-07 14:11:40 +03:00
|
|
|
if (dialogueName == 'palette-block' && EditorState.documentCreated()) {
|
2021-12-05 01:11:21 +03:00
|
|
|
ColorPicker.init();
|
2021-12-06 13:26:42 +03:00
|
|
|
PaletteBlock.init();
|
2021-07-14 00:40:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//track google event
|
2021-07-15 17:33:26 +03:00
|
|
|
if (trackEvent && typeof ga !== 'undefined')
|
2021-07-14 00:40:23 +03:00
|
|
|
ga('send', 'event', 'Palette Editor Dialogue', dialogueName); /*global ga*/
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Closes the current dialogue by hiding the window and the pop-up-container
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function closeDialogue () {
|
|
|
|
popUpContainer.style.display = 'none';
|
|
|
|
var popups = popUpContainer.children;
|
|
|
|
|
|
|
|
for (var i = 0; i < popups.length; i++) {
|
|
|
|
popups[i].style.display = 'none';
|
|
|
|
}
|
|
|
|
|
|
|
|
dialogueOpen = false;
|
|
|
|
|
|
|
|
if (currentOpenDialogue == "palette-block") {
|
|
|
|
ColorModule.addToSimplePalette();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-14 23:48:53 +03:00
|
|
|
function isOpen() {
|
|
|
|
return dialogueOpen;
|
|
|
|
}
|
|
|
|
|
2021-07-14 00:40:23 +03:00
|
|
|
return {
|
|
|
|
showDialogue,
|
2021-07-14 23:48:53 +03:00
|
|
|
closeDialogue,
|
|
|
|
isOpen
|
2021-07-14 00:40:23 +03:00
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
2022-02-23 19:16:23 +03:00
|
|
|
////console.log("Dialog: " + Dialogue);
|