Browse Source

Palettes can now be added and removed.

dev
Bryan Miller 5 years ago
parent
commit
b337184399
2 changed files with 35 additions and 20 deletions
  1. +30
    -17
      app/js/ctrls/CTRLPalettesStore.js
  2. +5
    -3
      sass/lists.scss

+ 30
- 17
app/js/ctrls/CTRLPalettesStore.js View File

import NESPalette from "/app/js/models/NESPalette.js"; import NESPalette from "/app/js/models/NESPalette.js";




const PLI_TEMPLATE = ".palette-list-item-template";
const PLI_TITLE = ".title";
const PLI_SELECTED = ".item-selected";
const PLI_TEMPLATE = "palette-list-item-template";
const PLI_TITLE = "title";
const PLI_SELECTED = "list-item-selected";


const PLI_BG_COLOR = "pal-bg-color"; const PLI_BG_COLOR = "pal-bg-color";
const PLI_FG_BASE = "pal-fg-"; const PLI_FG_BASE = "pal-fg-";
if (!this.hasAttribute("palname")){return;} if (!this.hasAttribute("palname")){return;}
var pname = this.getAttribute("palname"); var pname = this.getAttribute("palname");


if (Palettes.length > 0 && Palettes[CurrentPaletteIndex][0] !== pname){
var oel = Palettes[CurrentPaletteIndex][2];
oel.classList.remove(PLI_SELECTED);

for (let i=0; i < Palettes.length; i++){
if (Palettes[i][0] === pname){
Palettes[i][2].classList.add(PLI_SELECTED);
GlobalEvents.emit("set_app_palette", Palettes[i][1]);
break;
if (Palettes.length > 0){
if (Palettes[CurrentPaletteIndex][0] !== pname || !Palettes[CurrentPaletteIndex][2].classList.contains(PLI_SELECTED)){
var oel = Palettes[CurrentPaletteIndex][2];
oel.classList.remove(PLI_SELECTED);

for (let i=0; i < Palettes.length; i++){
if (Palettes[i][0] === pname){
Palettes[i][2].classList.add(PLI_SELECTED);
CurrentPaletteIndex = i;
GlobalEvents.emit("set_app_palette", Palettes[i][1]);
break;
}
} }
} }
} }


function SetElPaletteName(el, pname){ function SetElPaletteName(el, pname){
el.setAttribute("palname", pname); el.setAttribute("palname", pname);
var sel = el.querySelectorAll(PLI_TITLE);
var sel = el.querySelectorAll("." + PLI_TITLE);
if (sel.length === 1){ if (sel.length === 1){
sel = sel[0]; sel = sel[0];
sel.innerHTML = pname; sel.innerHTML = pname;




function CreatePaletteDOMEntry(pname, palette){ function CreatePaletteDOMEntry(pname, palette){
var oel = document.querySelectorAll(PLI_TEMPLATE);
var oel = document.querySelectorAll("." + PLI_TEMPLATE);
if (oel.length == 1){ if (oel.length == 1){
var el = oel[0].cloneNode(true); var el = oel[0].cloneNode(true);
el.classList.remove(PLI_TEMPLATE); el.classList.remove(PLI_TEMPLATE);
this.createPalette(e.palname); this.createPalette(e.palname);
this.activatePalette(e.palname); this.activatePalette(e.palname);
} }
}).bind(this));
}).bind(this));

GlobalEvents.listen("palstore-remove", (function(e){
this.removePalette(Palettes[CurrentPaletteIndex][0]);
}).bind(this));
} }


get json(){ get json(){
Palettes.push([name, palette, el]); Palettes.push([name, palette, el]);


if (Palettes.length <= 1 && !BlockEmits){ if (Palettes.length <= 1 && !BlockEmits){
GlobalEvents.emit("set_app_palette", palette);
//GlobalEvents.emit("set_app_palette", palette);
el.click();
} }
} }
} }
Palettes.splice(i, 1); Palettes.splice(i, 1);
} }
} }

if (Palettes.length <= 0){
this.createPalette("Palette");
} else {
Palettes[CurrentPaletteIndex][2].click();
}
return this; return this;
} }


activatePalette(name){ activatePalette(name){
var i = this.paletteIndexFromName(name); var i = this.paletteIndexFromName(name);
if (i >= 0 && CurrentPaletteIndex !== i){ if (i >= 0 && CurrentPaletteIndex !== i){
CurrentPaletteIndex = i;
Palettes[CurrentPaletteIndex][2].click(); Palettes[CurrentPaletteIndex][2].click();
//if (!BlockEmits){ //if (!BlockEmits){
// GlobalEvents.emit("set_app_palette", Palettes[CurrentPaletteIndex][1]); // GlobalEvents.emit("set_app_palette", Palettes[CurrentPaletteIndex][1]);

+ 5
- 3
sass/lists.scss View File

.list-container{ .list-container{
width: 100%; width: 100%;
height: 300px; height: 300px;
margin-top: 0.4em;
overflow-y: auto; overflow-y: auto;
overflow-x: hidden; overflow-x: hidden;
} }
.list-item-container{ .list-item-container{
background-color: $list-item-bg; background-color: $list-item-bg;
border-radius: 8px; border-radius: 8px;
margin-bottom: 0.4em;
}


.item-selected{
background-color: $list-item-selected-bg;
}
.list-item-selected{
background-color: $list-item-selected-bg;
} }


.list-v-padding{ .list-v-padding{

Loading…
Cancel
Save