pixel-editor/js/_dialogue.js

65 lines
1.9 KiB
JavaScript
Raw Normal View History

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
// 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';
// If I'm opening the palette window, I initialize the colour picker
if (dialogueName == 'palette-block' && documentCreated) {
cpInit();
pbInit();
}
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;
2020-04-04 10:41:56 +03:00
for (var i = 0; i < popups.length; i++) {
popups[i].style.display = 'none';
}
2021-01-08 18:20:39 +03:00
dialogueOpen = false;
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 () {
closeDialogue();
2020-04-04 10:41:56 +03:00
});
}