fullscreen.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. export class fullscreen {
  2. #node;
  3. constructor() {
  4. this.#node = null;
  5. }
  6. get visible() {
  7. return this.#node !== null;
  8. }
  9. _build_node() {
  10. throw new TypeError("This is virtual method!");
  11. }
  12. get #opacity() {
  13. if (!this.visible) {
  14. throw new TypeError("Can not change opacity of not existed.");
  15. }
  16. return Number(this.#node.style.opacity);
  17. }
  18. set #opacity(target) {
  19. if (!this.visible) {
  20. throw new TypeError("Can not change opacity of not existed.");
  21. }
  22. this.#node.style.opacity = String(target);
  23. }
  24. get_query(selector) {
  25. if (!this.visible) {
  26. throw new TypeError("Can not get item from not visible.");
  27. }
  28. return this.#node.querySelector(selector);
  29. }
  30. #prepare() {
  31. const container = document.createElement("div");
  32. container.classList.add("fullscreen-viewer");
  33. container.style.transition = "opacity 0.5s";
  34. container.appendChild(this._build_node());
  35. return container;
  36. }
  37. hide() {
  38. if (!this.visible) {
  39. return;
  40. }
  41. this.#opacity = 0;
  42. setTimeout(() => {
  43. if (!this.visible) {
  44. return;
  45. }
  46. this.#node.remove();
  47. this.#node = null;
  48. }, 500);
  49. }
  50. show() {
  51. if (this.visible) {
  52. return;
  53. }
  54. this.#node = this.#prepare();
  55. this.#opacity = 0;
  56. document.querySelector("body").appendChild(this.#node);
  57. setTimeout(() => {
  58. this.#opacity = 1;
  59. }, 100);
  60. }
  61. }