Constellations/js/Toolbox.js

37 lines
626 B
JavaScript
Raw Permalink Normal View History

2022-07-24 11:20:22 +02:00
import * as Dom from UnitJS.Dom;
2022-07-26 19:39:06 +02:00
var toolbox;
var tool;
var colors;
2022-07-24 11:20:22 +02:00
return {
init: init,
get: get,
color: color,
tool: tool
2022-07-24 11:20:22 +02:00
};
function init(size, elementId) {
2022-07-26 19:39:06 +02:00
toolbox = document.getElementById(elementId || 'toolbox');
colors = toolbox.querySelector('#colors');
for(var i = 0; i < size; i++) {
colors.appendChild(Dom.make('option', {class: 'color' + i}));
2022-07-24 11:20:22 +02:00
}
colors.addEventListener('change', function() {
colors.className = color();
2022-07-24 11:20:22 +02:00
});
2022-07-26 19:39:06 +02:00
tool = toolbox.querySelector('#tool');
2022-07-24 11:20:22 +02:00
}
function get() {
return toolbox;
}
function tool() {
return tool.value;
2022-07-24 11:20:22 +02:00
}
function color() {
return colors.selectedIndex;
2022-07-24 11:20:22 +02:00
}