Constellations/js/Toolbox.js

37 lines
645 B
JavaScript

import size from Config;
import * as Dom from UnitJS.Dom;
var toolbox;
var tool;
var colors;
return {
init: init,
get: get,
color: color,
tool: tool
};
function init(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;
}