menu.js 427 B

12345678910111213141516171819
  1. class Menu {
  2. constructor() {
  3. this.tools = [];
  4. }
  5. add(tool) {
  6. this.tools.push(tool);
  7. }
  8. refresh() {
  9. $("#tools").empty();
  10. this.tools.forEach(tool => {
  11. $("#tools").append(`<button
  12. id="btn-${tool.id}"
  13. class="tool icon icon-${tool.id}">
  14. <span> ${tool.title} </span></button>`);
  15. $("body").on("click", `#btn-${tool.id}`, tool.click);
  16. });
  17. }
  18. }
  19. export const menu = new Menu();