Constellations/js/Toolbox.js

30 lines
566 B
JavaScript

import * as Dom from UnitJS.Dom;
var tool;
var colors;
return {
init: init,
tool: tool,
color: color
};
function init(size, elementId) {
root = document.getElementById(elementId || 'toolbox');
colors = root.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 = root.querySelector('#tool');
}
function tool() {
return tool.value;
}
function color() {
return 'color' + colors.selectedIndex;
}