app_parts.js 2.5 KB

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