1
0

menu.js 771 B

1234567891011121314151617181920212223242526272829
  1. class Menu {
  2. constructor() {
  3. this.tools = [];
  4. $("#tools").empty();
  5. }
  6. add(component) {
  7. this.tools.push(component);
  8. }
  9. refresh() {
  10. this.tools
  11. .filter(component => {
  12. return component.created == undefined;
  13. })
  14. .forEach(component => {
  15. if (component != undefined && component.created) return;
  16. component.created = true;
  17. const options = component.options;
  18. $("#tools").append(`<button id="btn-${options.id}"
  19. class="tool icon icon-${options.icon} fadeInRight">
  20. <span> ${options.title} </span></button>`);
  21. $("body").on(
  22. "click",
  23. `#btn-${options.id}`,
  24. component.click.bind(component)
  25. );
  26. });
  27. }
  28. }
  29. export const menu = new Menu();