2021-01-08 01:49:16 +03:00
|
|
|
let currentOpenDialogue = "";
|
|
|
|
|
2020-12-31 15:05:51 +03:00
|
|
|
/** 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?
|
|
|
|
*/
|
2019-03-27 02:20:54 +03:00
|
|
|
function showDialogue (dialogueName, trackEvent) {
|
|
|
|
if (typeof trackEvent === 'undefined') trackEvent = true;
|
2020-04-04 10:41:56 +03:00
|
|
|
|
2021-01-08 01:49:16 +03:00
|
|
|
// Updating currently open dialogue
|
|
|
|
currentOpenDialogue = dialogueName;
|
2020-12-31 15:05:51 +03:00
|
|
|
// The pop up window is open
|
2020-04-04 10:41:56 +03:00
|
|
|
dialogueOpen = true;
|
2020-12-31 15:05:51 +03:00
|
|
|
// Showing the pop up container
|
2020-04-04 10:41:56 +03:00
|
|
|
popUpContainer.style.display = 'block';
|
|
|
|
|
2020-12-31 15:05:51 +03:00
|
|
|
// Showing the window
|
2020-04-04 10:41:56 +03:00
|
|
|
document.getElementById(dialogueName).style.display = 'block';
|
|
|
|
|
2021-01-07 02:04:48 +03:00
|
|
|
// If I'm opening the palette window, I initialize the colour picker
|
2021-01-07 17:59:08 +03:00
|
|
|
if (dialogueName == 'palette-block' && documentCreated) {
|
2021-01-07 02:04:48 +03:00
|
|
|
cpInit();
|
2021-01-07 17:59:08 +03:00
|
|
|
pbInit();
|
|
|
|
}
|
2021-01-07 02:04:48 +03:00
|
|
|
|
2019-03-27 02:20:54 +03:00
|
|
|
//track google event
|
|
|
|
if (trackEvent)
|
|
|
|
ga('send', 'event', 'Palette Editor Dialogue', dialogueName); /*global ga*/
|
|
|
|
}
|
|
|
|
|
2020-12-31 15:05:51 +03:00
|
|
|
/** Closes the current dialogue by hiding the window and the pop-up-container
|
|
|
|
*
|
|
|
|
*/
|
2019-03-27 02:20:54 +03:00
|
|
|
function closeDialogue () {
|
2020-04-04 10:41:56 +03:00
|
|
|
popUpContainer.style.display = 'none';
|
|
|
|
var popups = popUpContainer.children;
|
2021-01-08 01:49:16 +03:00
|
|
|
|
2020-04-04 10:41:56 +03:00
|
|
|
for (var i = 0; i < popups.length; i++) {
|
|
|
|
popups[i].style.display = 'none';
|
2021-01-08 01:49:16 +03:00
|
|
|
}
|
2021-01-07 17:59:08 +03:00
|
|
|
|
2021-01-08 18:20:39 +03:00
|
|
|
dialogueOpen = false;
|
|
|
|
|
2021-01-08 01:49:16 +03:00
|
|
|
if (currentOpenDialogue == "palette-block") {
|
2021-07-04 20:55:49 +03:00
|
|
|
ColorModule.AddToSimplePalette();
|
2020-04-04 10:41:56 +03:00
|
|
|
}
|
2019-03-27 02:20:54 +03:00
|
|
|
}
|
|
|
|
|
2020-12-31 15:05:51 +03:00
|
|
|
/** Closes a dialogue window if the user clicks everywhere but in the current window
|
|
|
|
*
|
|
|
|
*/
|
2020-04-04 10:41:56 +03:00
|
|
|
popUpContainer.addEventListener('click', function (e) {
|
|
|
|
if (e.target == popUpContainer)
|
|
|
|
closeDialogue();
|
2019-03-27 02:20:54 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
//add click handlers for all cancel buttons
|
|
|
|
var cancelButtons = popUpContainer.getElementsByClassName('close-button');
|
|
|
|
for (var i = 0; i < cancelButtons.length; i++) {
|
2020-04-04 10:41:56 +03:00
|
|
|
cancelButtons[i].addEventListener('click', function () {
|
2021-01-07 17:59:08 +03:00
|
|
|
closeDialogue();
|
2020-04-04 10:41:56 +03:00
|
|
|
});
|
|
|
|
}
|