Constellations/js/Toolbox.js

37 lines
626 B
JavaScript

import * as Dom from UnitJS.Dom;
var toolbox;
var tool;
var colors;
return {
init: init,
get: get,
color: color,
tool: tool
};
function init(size, elementId) {
toolbox = document.getElementById(elementId || 'toolbox');
colors = toolbox.querySelector('#colors');
for(var i = 0; i < size; i++) {
colors.appendChild(Dom.make('option', {class: 'color' + i}));
}
colors.addEventListener('change', function() {
colors.className = color();
});
tool = toolbox.querySelector('#tool');
}
function get() {
return toolbox;
}
function tool() {
return tool.value;
}
function color() {
return colors.selectedIndex;
}