app_parts.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { applet_animations, applet_builder } from "./applet.js";
  2. import { dom_manager } from "./functions.js";
  3. import { dictionary } from "./dictionary.js";
  4. class submission_part {
  5. #header;
  6. #image;
  7. #description;
  8. #applet;
  9. #applet_close;
  10. #target;
  11. constructor(
  12. header_selector,
  13. image_selector,
  14. description_selector,
  15. close_selector
  16. ) {
  17. this.#header = document.querySelector(header_selector);
  18. this.#image = document.querySelector(image_selector);
  19. this.#description = document.querySelector(description_selector);
  20. this.#applet_close = this.#description.querySelector(close_selector);
  21. if (!dom_manager.is_element(this.#header)) {
  22. throw "Could not found header by selector.";
  23. }
  24. if (!dom_manager.is_element(this.#image)) {
  25. throw "Could not found image by selector.";
  26. }
  27. if (!dom_manager.is_element(this.#description)) {
  28. throw "Could not found description by selector.";
  29. }
  30. if (!dom_manager.is_element(this.#applet_close)) {
  31. throw "Could not found close button by selector.";
  32. }
  33. this.#applet = this.#applet_builder(this.#applet_close);
  34. this.current = null;
  35. }
  36. #applet_builder(close) {
  37. const builder = new applet_builder();
  38. builder.minimalise = close;
  39. builder.maximalise = this.#header;
  40. builder.target = this.#description;
  41. builder.animation = applet_animations.hide_opacity_generator(500);
  42. return builder.build();
  43. }
  44. #welcome() {
  45. this.#header.innerText = dictionary.welcome.title;
  46. const title = document.createElement("h1");
  47. title.innerText = dictionary.welcome.title;
  48. const description = document.createElement("p");
  49. description.innerText = dictionary.welcome.description;
  50. this.#clean_description();
  51. this.#description.appendChild(title);
  52. this.#description.appendChild(description);
  53. }
  54. #clean_description() {
  55. this.#description.childNodes.forEach(node => {
  56. if (node !== this.#applet_close) {
  57. node.remove();
  58. }
  59. });
  60. }
  61. set current(target) {
  62. if (target === null) {
  63. this.#welcome();
  64. }
  65. this.#target = target;
  66. }
  67. get current() {
  68. return this.#target;
  69. }
  70. }
  71. export { submission_part };