You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2019/05/10 15:00:26 UTC

[myfaces-tobago] 04/04: TOBAGO-1633: Use TypeScript instead of JavaScript

This is an automated email from the ASF dual-hosted git repository.

lofwyr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git

commit fb24c38a7d41c226c0b682e6e0c282a8edb4270e
Author: Udo Schnurpfeil <lo...@apache.org>
AuthorDate: Fri May 10 16:59:45 2019 +0200

    TOBAGO-1633: Use TypeScript instead of JavaScript
    
    * example: blue print for good component
---
 .../src/main/npm/ts/tobago-in.ts                   | 43 ++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-in.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-in.ts
index 4b326ae..6f61d12 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-in.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-in.ts
@@ -15,3 +15,46 @@
  * limitations under the License.
  */
 
+// XXX remove me
+function es6test() {
+  [1, 2, 3, 4].map((n) => n + 1);
+}
+
+// XXX regexp example only - blueprint
+namespace Tobago {
+
+  class RegExpTest {
+
+    private readonly element: HTMLInputElement;
+    private readonly regexp: RegExp;
+
+    constructor(element: HTMLInputElement) {
+
+      this.element = element;
+      this.regexp = new RegExp(this.element.dataset["regexp"]);
+
+      console.info("constructor: " + element.id);
+
+      this.element.addEventListener("change", this.checkValue.bind(this));
+    };
+
+    checkValue(event: TextEvent) {
+      console.info("changed: check if " + this.regexp + " is okay!");
+      if (!this.regexp.test(this.element.value)) {
+        this.element.classList.add("border-danger");
+      } else {
+        this.element.classList.remove("border-danger");
+      }
+    };
+
+    static init = function (element: HTMLElement): void {
+      for (const input of element.tobagoSelfOrElementsByClassName("tobago-in")) { // todo only for data-regexp
+        new RegExpTest(<HTMLInputElement>input);
+      }
+    };
+  }
+
+  Listener.register(RegExpTest.init, Phase.DOCUMENT_READY);
+  Listener.register(RegExpTest.init, Phase.AFTER_UPDATE);
+
+}
\ No newline at end of file