Cixo Develop 1 жил өмнө
parent
commit
b69eaefaeb
2 өөрчлөгдсөн 73 нэмэгдсэн , 38 устгасан
  1. 66 37
      assets/applet.js
  2. 7 1
      assets/functions.js

+ 66 - 37
assets/applet.js

@@ -1,62 +1,91 @@
-import { dom_manager } from "./functions.js";
+import { dom_manager, type_manager } from "./functions.js";
 
-class applet {
+class applet_builder {
+    #target;
     #show;
     #hide;
-    #current;
+    #change;
+    #init;
     #animation;
-    #target;
-
-    #change() {
-        
+    
+    constructor() {
+        this.#target = undefined;
+        this.#show = undefined;
+        this.#hide = undefined;
+        this.#change = undefined;
+        this.#init = undefined;
+        this.#animation = undefined;
     }
 
-    #visible(animate = true) {
-        if (animate) {
-            this.#animation(true);
+    set_target(target) {
+        if (!dom_manager.is_element(target)) {
+            throw "Target is not HTML element.";
         }
+
+        this.#target = target;
+    }
+
+    #is_dualbutton() {
+        return this.#show !== undefined || this.#hide !== undefined;
+    }
+
+    #is_singlebutton() {
+        return this.#change !== undefined;
     }
 
-    #unvisible(animate = true) {
-        if (animate) {
-            this.#animation(this.false);
+    set_show(target) {
+        if (!dom_manager.is_element(target)) {
+            throw "Show button must be HTML element.";
+        }
+
+        if (this.#is_singlebutton()) {
+            throw "This is single button applet.";
         }
+
+        this.#show = target;
     }
 
-    #activate() {
-        if (this.#hide === undefined) {
-            this.#show.addEventListener("click", () => this.#change());
-        } else {
-            this.#show.addEventListener("click", () => this.#visible());
-            this.#hide.addEventListener("click", () => this.#unvisible());
+    set_hide(target) {
+        if (!dom_manager.is_element(target)) {
+            throw "Hide button must be HTML element.";
         }
 
-        if (this.#current) {
-            this.#visible(false);
-        } else {
-            this.#unvisible(false);
+        if (this.#is_singlebutton()) {
+            throw "This is single button applet.";
         }
+
+        this.#hide = hide;
     }
 
-    constructor(target, change, current, animation) {
-        this.#current = current;
-        this.#show = change;
-        this.#animation = animation;
-        this.#target = target;
-        this.#hide = undefined;
+    set_change(target) {
+        if (!dom_manager.is_element(target)) {
+            throw "Change button must be HTML element.";
+        }
+
+        if (this.#is_dualbutton()) {
+            throw "This is dual button applet.";
+        }
 
-        this.#activate();
+        this.#change = target;
     }
 
-    constructor(target, show, hide, current, animation) {
-        this.#current = current;
-        this.#show = show;
-        this.#hide = hide;
-        this.#animation = animation;
-        this.#target = target;
+    default_visible() {
+        this.#init = true;
+    }
 
-        this.#activate();
+    default_hidden() {
+        this.#init = false;
     }
+
+    set_animation(target) {
+        if (!type_manager.is_function(target)) {
+            throw "Animation must be an function.";
+        }
+    }
+}
+
+class applet {
+
 }
 
 export { applet };

+ 7 - 1
functions.js → assets/functions.js

@@ -10,4 +10,10 @@ class dom_manager {
     }
 }
 
-export { dom_manager };
+class type_manager {
+    static is_function(target) {
+        return typeof(target) === 'function';
+    }
+}
+
+export { dom_manager, type_manager };