cx-ui.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. export class cx_ui {
  2. static #generator(type, manipulator = null) {
  3. return (name, click = null, manipulate = null) => {
  4. const item = document.createElement(type);
  5. item.id = `${type}-${name}`;
  6. item.classList.add(type);
  7. item.classList.add(name);
  8. item.classList.add(`${type}-${name}`);
  9. if (manipulator !== null) {
  10. manipulator(item);
  11. }
  12. if (click !== null) {
  13. item.addEventListener("click", click);
  14. }
  15. if (manipulate !== null) {
  16. manipulate(item);
  17. }
  18. return item;
  19. };
  20. }
  21. static get div() {
  22. return this.#generator("div");
  23. }
  24. static get canvas() {
  25. return this.#generator("canvas");
  26. }
  27. static push(name, text, click = null, manipulate = null) {
  28. const generator = this.#generator("input", (item) => {
  29. item.value = text;
  30. item.type = "button";
  31. item.classList.add("push");
  32. });
  33. return generator(name, click, manipulate);
  34. }
  35. static p(name, text, click = null, manipulate = null) {
  36. const generator = this.#generator("p", (p) => { p.innerText = text; });
  37. const result = generator(name, click, manipulate);
  38. return result;
  39. }
  40. static get input() {
  41. return this.#generator("input");
  42. }
  43. static image(name, url, click = null, manipulate = null) {
  44. const generator = this.#generator("img", (img) => { img.src = url; });
  45. const result = generator(name, click, manipulate);
  46. return result;
  47. }
  48. }