2021-07-15 23:21:19 +03:00
|
|
|
const TopMenuModule = (() => {
|
|
|
|
|
|
|
|
const mainMenuItems = document.getElementById('main-menu').children;
|
|
|
|
|
|
|
|
initMenu();
|
|
|
|
|
|
|
|
function initMenu() {
|
|
|
|
//for each button in main menu (starting at 1 to avoid logo)
|
|
|
|
for (let i = 1; i < mainMenuItems.length; i++) {
|
|
|
|
|
|
|
|
//get the button that's in the list item
|
|
|
|
const menuItem = mainMenuItems[i];
|
|
|
|
const menuButton = menuItem.children[0];
|
|
|
|
|
|
|
|
//when you click a main menu items button
|
2021-07-20 23:52:51 +03:00
|
|
|
Events.on('click', menuButton, function (e) {
|
2021-07-15 23:21:19 +03:00
|
|
|
// Select the item
|
|
|
|
Util.select(e.target.parentElement);
|
|
|
|
});
|
|
|
|
|
|
|
|
const subMenu = menuItem.children[1];
|
|
|
|
const subMenuItems = subMenu.children;
|
|
|
|
|
|
|
|
//when you click an item within a menu button
|
|
|
|
for (var j = 0; j < subMenuItems.length; j++) {
|
|
|
|
|
|
|
|
const currSubmenuItem = subMenuItems[j];
|
|
|
|
const currSubmenuButton = currSubmenuItem.children[0];
|
|
|
|
|
|
|
|
switch (currSubmenuButton.textContent) {
|
|
|
|
case 'New':
|
2021-07-20 23:52:51 +03:00
|
|
|
Events.on('click', currSubmenuButton, Dialogue.showDialogue, 'new-pixel');
|
2021-07-15 23:21:19 +03:00
|
|
|
break;
|
|
|
|
case 'Save project':
|
2021-07-20 23:52:51 +03:00
|
|
|
Events.on('click', currSubmenuButton, FileManager.saveProject);
|
2021-07-15 23:21:19 +03:00
|
|
|
break;
|
|
|
|
case 'Open':
|
2021-07-20 23:52:51 +03:00
|
|
|
Events.on('click', currSubmenuButton, FileManager.open);
|
2021-07-15 23:21:19 +03:00
|
|
|
break;
|
|
|
|
case 'Export':
|
2021-07-20 23:52:51 +03:00
|
|
|
Events.on('click', currSubmenuButton, FileManager.exportProject);
|
2021-07-15 23:21:19 +03:00
|
|
|
break;
|
|
|
|
case 'Exit':
|
|
|
|
//if a document exists, make sure they want to delete it
|
2021-07-23 20:05:33 +03:00
|
|
|
if (Startup.documentCreated()) {
|
2021-07-15 23:21:19 +03:00
|
|
|
//ask user if they want to leave
|
|
|
|
if (confirm('Exiting will discard your current pixel. Are you sure you want to do that?'))
|
|
|
|
//skip onbeforeunload prompt
|
|
|
|
window.onbeforeunload = null;
|
|
|
|
else
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
// REFACTOR: move the binding to the Selection IIFE or something like that once it's done
|
|
|
|
case 'Paste':
|
2021-07-20 23:52:51 +03:00
|
|
|
Events.on('click', currSubmenuButton, pasteSelection);
|
2021-07-15 23:21:19 +03:00
|
|
|
break;
|
|
|
|
case 'Copy':
|
2021-07-20 23:52:51 +03:00
|
|
|
Events.on('click', currSubmenuButton, copySelection);
|
2021-07-15 23:21:19 +03:00
|
|
|
break;
|
|
|
|
case 'Cut':
|
2021-07-20 23:52:51 +03:00
|
|
|
Events.on('click', currSubmenuButton, cutSelectionTool);
|
2021-07-15 23:21:19 +03:00
|
|
|
break;
|
|
|
|
case 'Cancel':
|
2021-07-20 23:52:51 +03:00
|
|
|
Events.on('click', currSubmenuButton, tool.pencil.switchTo);
|
2021-07-15 23:21:19 +03:00
|
|
|
break;
|
|
|
|
//Help Menu
|
|
|
|
case 'Settings':
|
|
|
|
//fill form with current settings values
|
|
|
|
//Util.setValue('setting-numberOfHistoryStates', settings.numberOfHistoryStates);
|
2021-07-20 23:52:51 +03:00
|
|
|
Events.on('click', currSubmenuButton, Dialogue.showDialogue, 'settings');
|
2021-07-15 23:21:19 +03:00
|
|
|
break;
|
|
|
|
case 'Help':
|
2021-07-20 23:52:51 +03:00
|
|
|
Events.on('click', currSubmenuButton, Dialogue.showDialogue, 'help');
|
2021-07-15 23:21:19 +03:00
|
|
|
break;
|
|
|
|
case 'About':
|
2021-07-20 23:52:51 +03:00
|
|
|
Events.on('click', currSubmenuButton, Dialogue.showDialogue, 'about');
|
2021-07-15 23:21:19 +03:00
|
|
|
break;
|
|
|
|
case 'Changelog':
|
2021-07-20 23:52:51 +03:00
|
|
|
Events.on('click', currSubmenuButton, Dialogue.showDialogue, 'changelog');
|
2021-07-15 23:21:19 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function closeMenu () {
|
|
|
|
//remove .selected class from all menu buttons
|
|
|
|
for (var i = 0; i < mainMenuItems.length; i++) {
|
|
|
|
Util.deselect(mainMenuItems[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
closeMenu
|
|
|
|
}
|
|
|
|
})();
|