mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
Merge pull request #62 from lospec/fix-crash-when-deselecting-a-color-with-no-colors
changed all color deselections to use optional chaining
This commit is contained in:
commit
bc34208d01
@ -39,7 +39,7 @@ on('click', 'add-color-button', function(){
|
||||
while (colorIsUnique == false);
|
||||
|
||||
//remove current color selection
|
||||
document.querySelector('#colors-menu li.selected').classList.remove('selected');
|
||||
document.querySelector('#colors-menu li.selected')?.classList.remove('selected');
|
||||
|
||||
//add new color and make it selected
|
||||
var addedColor = addColor(newColor);
|
||||
|
@ -4,8 +4,7 @@ function clickedColor (e){
|
||||
//left clicked color
|
||||
if (e.which == 1) {
|
||||
// remove current color selection
|
||||
var selectedColor = document.querySelector('#colors-menu li.selected');
|
||||
if (selectedColor) selectedColor.classList.remove('selected');
|
||||
document.querySelector('#colors-menu li.selected')?.classList.remove('selected');
|
||||
|
||||
//set current color
|
||||
for (let i=1; i<layers.length - nAppLayers; i++) {
|
||||
|
@ -32,8 +32,7 @@ function createColorPalette(paletteColors, deletePreviousPalette = true) {
|
||||
if (newColorHex.r + newColorHex.g + newColorHex.b < darkestColorHex.r + darkestColorHex.g + darkestColorHex.b) {
|
||||
|
||||
//remove current color selection
|
||||
var selectedColor = document.querySelector('#colors-menu li.selected');
|
||||
if (selectedColor) selectedColor.classList.remove('selected');
|
||||
document.querySelector('#colors-menu li.selected')?.classList.remove('selected');
|
||||
|
||||
//set as current color
|
||||
newColorElement.classList.add('selected');
|
||||
|
@ -105,8 +105,7 @@ window.addEventListener("mouseup", function (mouseEvent) {
|
||||
//if picked color matches this color
|
||||
if (newColor == colors[i].jscolor.toString()) {
|
||||
//remove current color selection
|
||||
var selectedColor = document.querySelector("#colors-menu li.selected")
|
||||
if (selectedColor) selectedColor.classList.remove("selected");
|
||||
document.querySelector("#colors-menu li.selected")?.classList.remove("selected");
|
||||
|
||||
//set current color
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user