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 2018/12/06 16:54:15 UTC
[myfaces-tobago] 02/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 7baf1fe03ed34393b74796e625cf4a954f94669a
Author: Udo Schnurpfeil <lo...@apache.org>
AuthorDate: Thu Dec 6 10:46:24 2018 +0100
TOBAGO-1633: Use TypeScript instead of JavaScript.
first tries...
---
.../webapp/content/10-intro/20-docker/Docker.xhtml | 4 +-
.../webapp/content/10-intro/20-docker/docker.js | 68 ++++++++++++----------
.../content/10-intro/20-docker/docker.js.map | 1 +
.../webapp/content/10-intro/20-docker/docker.ts | 57 ++++++++++++++++++
.../webapp/content/10-intro/20-docker/readme.md | 11 ++++
.../webapp/content/10-intro/20-docker/tobago.d.ts | 21 +++++++
.../content/10-intro/20-docker/tsconfig.json | 15 +++++
.../webapp/content/10-intro/20-docker/tslint.json | 10 ++++
8 files changed, 156 insertions(+), 31 deletions(-)
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/20-docker/Docker.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/20-docker/Docker.xhtml
index adf3c5d..d018b68 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/20-docker/Docker.xhtml
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/20-docker/Docker.xhtml
@@ -62,7 +62,9 @@
<pre><code class="language-bash" id="commandLine"><tc:out
keepLineBreaks="false" value="#{dockerController.commandLine}"/></code></pre>
- <tc:button id="toClipboardButton" label="Copy Commands" omit="true"/>
+ <tc:button id="toClipboardButton" label="Copy Commands" omit="true">
+ <tc:dataAttribute name="copy-clipboard-from" value="commandLine"/>
+ </tc:button>
<tc:button label="HTTP" link="#{dockerController.url}"/>
<tc:button label="HTTPS" link="#{dockerController.sslUrl}" disabled="#{not dockerController.server.ssl}"/>
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/20-docker/docker.js b/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/20-docker/docker.js
index 896696e..be2c235 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/20-docker/docker.js
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/20-docker/docker.js
@@ -14,33 +14,41 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-Tobago.Docker = {};
-
-Tobago.Docker.init = function () {
-
- /* Copy the command lines to the clipboard.
- */
- document.querySelector('#page\\:mainForm\\:toClipboardButton').addEventListener('click', function (event) {
- var commandLine = document.querySelector('#commandLine');
-
- if (window.getSelection) {
- var selection = window.getSelection();
- var range = document.createRange();
- range.selectNodeContents(commandLine);
- selection.removeAllRanges();
- selection.addRange(range);
- } else {
- console.warn("Text select not possible: Unsupported browser.");
- }
-
- try {
- document.execCommand('copy');
- } catch (err) {
- console.error('Copying text not possible');
- }
- });
-};
-
-Tobago.registerListener(Tobago.Docker.init, Tobago.Phase.DOCUMENT_READY);
-Tobago.registerListener(Tobago.Docker.init, Tobago.Phase.AFTER_UPDATE);
+var Demo;
+(function (Demo) {
+ var ToClipboardButton;
+ (function (ToClipboardButton_1) {
+ var ToClipboardButton = /** @class */ (function () {
+ function ToClipboardButton(element) {
+ /* Copy the command lines to the clipboard.
+ */
+ element.addEventListener("click", function (event) {
+ var from = element.getAttribute("data-copy-clipboard-from");
+ var commandLine = document.getElementById(from);
+ if (window.getSelection) {
+ var selection = window.getSelection();
+ var range = document.createRange();
+ range.selectNodeContents(commandLine);
+ selection.removeAllRanges();
+ selection.addRange(range);
+ }
+ else {
+ console.warn("Text select not possible: Unsupported browser.");
+ }
+ try {
+ var result = document.execCommand("copy");
+ alert("result: " + result);
+ }
+ catch (error) {
+ console.error("Copying text not possible");
+ }
+ });
+ }
+ return ToClipboardButton;
+ }());
+ var init = function () { return new ToClipboardButton(document.querySelector("[data-copy-clipboard-from]")); };
+ Tobago.registerListener(init, Tobago.Phase.DOCUMENT_READY);
+ Tobago.registerListener(init, Tobago.Phase.AFTER_UPDATE);
+ })(ToClipboardButton = Demo.ToClipboardButton || (Demo.ToClipboardButton = {}));
+})(Demo || (Demo = {}));
+//# sourceMappingURL=docker.js.map
\ No newline at end of file
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/20-docker/docker.js.map b/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/20-docker/docker.js.map
new file mode 100644
index 0000000..3ce7225
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/20-docker/docker.js.map
@@ -0,0 +1 @@
+{"version":3,"file":"docker.js","sourceRoot":"","sources":["docker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,IAAO,IAAI,CAuCV;AAvCD,WAAO,IAAI;IAAC,IAAA,iBAAiB,CAuC5B;IAvCW,WAAA,mBAAiB;QAEzB;YAEI,2BAAY,OAAoB;gBAE5B;mBACG;gBACH,OAAO,CAAC,gBAAgB,CACpB,OAAO,EACP,UAAC,KAAiB;oBACd,IAAM,IAAI,GAAG,OAAO,CAAC,YAAY,CAAC,0BAA0B,CAAC,CAAC;oBAC9D,IAAM,WAAW,GAAG,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;oBAElD,IAAI,MAAM,CAAC,YAAY,EAAE;wBACrB,IAAM,SAAS,GAAG,MAAM,CAAC,YAAY,EAAE,CAAC;wBACxC,IAAM,KA [...]
\ No newline at end of file
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/20-docker/docker.ts b/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/20-docker/docker.ts
new file mode 100644
index 0000000..9b03408
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/20-docker/docker.ts
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+module Demo.ToClipboardButton {
+
+ class ToClipboardButton {
+
+ constructor(element: HTMLElement) {
+
+ /* Copy the command lines to the clipboard.
+ */
+ element.addEventListener(
+ "click",
+ (event: MouseEvent) => {
+ const from = element.getAttribute("data-copy-clipboard-from");
+ const commandLine = document.getElementById(from);
+
+ if (window.getSelection) {
+ const selection = window.getSelection();
+ const range = document.createRange();
+ range.selectNodeContents(commandLine);
+ selection.removeAllRanges();
+ selection.addRange(range);
+ } else {
+ console.warn("Text select not possible: Unsupported browser.");
+ }
+ try {
+ const result = document.execCommand("copy");
+ alert("result: " + result);
+ } catch (error) {
+ console.error("Copying text not possible");
+ }
+ });
+ }
+ }
+
+ const init = () => new ToClipboardButton(
+ document.querySelector("[data-copy-clipboard-from]")
+ );
+
+ Tobago.registerListener(init, Tobago.Phase.DOCUMENT_READY, Tobago.Phase.Order.LATER);
+ Tobago.registerListener(init, Tobago.Phase.AFTER_UPDATE);
+}
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/20-docker/readme.md b/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/20-docker/readme.md
new file mode 100644
index 0000000..07c184e
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/20-docker/readme.md
@@ -0,0 +1,11 @@
+Build instructions:
+
+Compiling
+```
+tsc
+```
+
+Lint
+```
+tslint *.ts
+```
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/20-docker/tobago.d.ts b/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/20-docker/tobago.d.ts
new file mode 100644
index 0000000..95d86bc
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/20-docker/tobago.d.ts
@@ -0,0 +1,21 @@
+declare var Tobago: {
+ Phase: {
+ DOCUMENT_READY,
+ WINDOW_LOAD,
+ BEFORE_SUBMIT,
+ AFTER_UPDATE,
+ BEFORE_UNLOAD,
+ BEFORE_EXIT
+ Order: {
+ EARLY,
+ NORMAL,
+ LATE,
+ LATER
+ }
+ };
+ registerListener(
+ listener: () => void,
+ phase: any,
+ order?: any
+ ): void
+};
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/20-docker/tsconfig.json b/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/20-docker/tsconfig.json
new file mode 100644
index 0000000..297718a
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/20-docker/tsconfig.json
@@ -0,0 +1,15 @@
+{
+ "compilerOptions": {
+ "module": "commonjs",
+ "target": "es5",
+ "noImplicitAny": false,
+ "rootDir": ".",
+ "outDir": ".",
+ "sourceMap": true,
+ "removeComments": false
+ },
+ "include": [
+ "**/*.ts"
+ ],
+ "exclude": []
+}
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/20-docker/tslint.json b/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/20-docker/tslint.json
new file mode 100644
index 0000000..7137248
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/10-intro/20-docker/tslint.json
@@ -0,0 +1,10 @@
+{
+ "rules": {
+ "semicolon": [true, "always"],
+ "member-ordering": [
+ true,
+ "static-before-instance",
+ "variables-before-functions"
+ ]
+ }
+}