pixel-editor/js/_palettes.js

93 lines
2.8 KiB
JavaScript
Raw Normal View History

2019-03-27 02:20:54 +03:00
//populate palettes list in new pixel menu
Object.keys(palettes).forEach(function(paletteName,index) {
2020-04-04 10:41:56 +03:00
var palettesMenu = document.getElementById('palette-menu');
var splashPalettes = document.getElementById('palette-menu-splash');
2019-03-27 02:20:54 +03:00
//create button
2020-04-04 10:41:56 +03:00
var button = document.createElement('button');
2019-03-27 02:20:54 +03:00
button.appendChild(document.createTextNode(paletteName));
2020-04-04 10:41:56 +03:00
//if the palette was specified by the user, change the dropdown to it
if (palettes[paletteName].specified == true) {
setText('palette-button', paletteName);
setText('palette-button-splash', paletteName)
2020-04-04 10:41:56 +03:00
//Show empty palette option
document.getElementById('no-palette-button').style.display = 'block';
}
var buttonEvent = function() {
2020-04-04 10:41:56 +03:00
//hide the dropdown menu
deselect('palette-menu');
deselect('palette-button');
deselect('palette-menu-splash');
deselect('palette-button-splash');
2020-04-04 10:41:56 +03:00
//show empty palette option
document.getElementById('no-palette-button').style.display = 'block';
//set the text of the dropdown to the newly selected preset
setText('palette-button', paletteName);
setText('palette-button-splash', paletteName);
};
on('click', button, buttonEvent);
//insert new element
palettesMenu.appendChild(button);
// Making a copy for the splash page too
var copyButton = button.cloneNode(true);
// Attaching the same event
on('click', copyButton, buttonEvent);
// Appending it to the splash palette menu
splashPalettes.appendChild(copyButton);
2019-03-27 02:20:54 +03:00
});
var noPaletteButtonClickEvent = function () {
2020-04-04 10:41:56 +03:00
document.getElementById('no-palette-button').style.display = 'none';
setText('palette-button', 'Choose a palette...');
}
var loadPaletteButtonEvent = function () {
2020-04-04 10:41:56 +03:00
document.getElementById('load-palette-browse-holder').click();
}
2019-03-27 02:20:54 +03:00
var clickPaletteButtonEvent = function (e){
2020-04-04 10:41:56 +03:00
toggle('palette-button');
toggle('palette-menu');
deselect('preset-button');
deselect('preset-menu');
// Splash version
toggle('palette-button-splash');
toggle('palette-menu-splash');
2020-04-04 10:41:56 +03:00
e.stopPropagation();
}
//select no palette
on('click', 'no-palette-button', noPaletteButtonClickEvent);
//select load palette
on('click', 'load-palette-button', loadPaletteButtonEvent);
//select load palette
on('click', 'load-palette-button-splash', loadPaletteButtonEvent);
// Palette menu click
on('click', 'palette-button', clickPaletteButtonEvent);
on('click', 'palette-button-splash', clickPaletteButtonEvent);
2019-03-27 02:20:54 +03:00
on('click', 'new-pixel', function (){
deselect('editor-mode-menu');
2020-04-04 10:41:56 +03:00
deselect('preset-button');
deselect('preset-menu');
deselect('palette-button');
deselect('palette-menu');
// Splash version
deselect('palette-button-splash');
deselect('palette-menu-splash');
});