import * as Dom from UnitJS.Dom; var toolbox; var tool; var colors; return { activate: activate, init: init, tool: tool, color: color }; function activate(on) { toolbox.classList[on ? 'add' : 'remove']('active'); } 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 tool() { return tool.value; } function color() { return 'color' + colors.selectedIndex; }