aboutsummaryrefslogtreecommitdiff
path: root/notif
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2021-09-05 22:46:05 +0700
committerShulhan <ms@kilabit.info>2021-09-05 22:46:05 +0700
commite3da79cf1adfb6dc2d9fed2e982bcde7fe7a7161 (patch)
tree74b71ed9f9c3b58d93269a9cda32729a9c679d2a /notif
parent903561a9074da0632e1e001db3879cc45f974493 (diff)
downloadpakakeh.ts-e3da79cf1adfb6dc2d9fed2e982bcde7fe7a7161.tar.xz
notif: convert the example using TypeScript and load it with type="module"
Diffstat (limited to 'notif')
-rw-r--r--notif/example.d.ts1
-rw-r--r--notif/example.html51
-rw-r--r--notif/example.ts52
-rw-r--r--notif/index.html20
-rw-r--r--notif/notif.d.ts3
-rw-r--r--notif/notif.ts6
6 files changed, 79 insertions, 54 deletions
diff --git a/notif/example.d.ts b/notif/example.d.ts
new file mode 100644
index 0000000..cb0ff5c
--- /dev/null
+++ b/notif/example.d.ts
@@ -0,0 +1 @@
+export {};
diff --git a/notif/example.html b/notif/example.html
deleted file mode 100644
index b1211b0..0000000
--- a/notif/example.html
+++ /dev/null
@@ -1,51 +0,0 @@
-<!DOCTYPE html>
-<html>
- <head>
- <meta charset="UTF-8" />
- <title>WUI - notif</title>
- <style>
- #input_msg {
- width: calc(100% - 1em);
- height: 4em;
- }
- .empty {
- height: 100vh;
- }
- </style>
- </head>
- <body onload="main()">
- <p class="empty">Empty spaces.</p>
- <textarea id="input_msg"></textarea>
- <button onclick="notifInfo()">Info</button>
- <button onclick="notifError()">Error</button
- <p></p>
- <script>
- var exports = {}
- let inputMsg = document.getElementById("input_msg")
- let wuiNotif = null
- </script>
- <script src="notif.js"></script>
- <script>
- function main() {
- wuiNotif = new WuiNotif()
- inputMsg.value = `Hello world, this is a notification with HTML format using <b>bold</b> and <u>underline</u> words.`
-
- let previewError = document.createElement("div")
- previewError.classList.add(`${WUI_NOTIF_CLASS_ERROR}`)
- previewError.innerText = `Preview of error style`;
- document.body.appendChild(previewError)
-
- let previewInfo = document.createElement("div")
- previewInfo.classList.add(`${WUI_NOTIF_CLASS_INFO}`)
- previewInfo.innerText = `Preview of info style`;
- document.body.appendChild(previewInfo)
- }
- function notifInfo() {
- wuiNotif.Info(inputMsg.value)
- }
- function notifError() {
- wuiNotif.Error(inputMsg.value)
- }
- </script>
- </body>
-</html>
diff --git a/notif/example.ts b/notif/example.ts
new file mode 100644
index 0000000..bb919ae
--- /dev/null
+++ b/notif/example.ts
@@ -0,0 +1,52 @@
+import { WuiNotif, WUI_NOTIF_CLASS_ERROR, WUI_NOTIF_CLASS_INFO } from "./notif.js"
+
+let inputMsg: HTMLTextAreaElement
+let wuiNotif: WuiNotif
+
+function main() {
+ wuiNotif = new WuiNotif()
+
+ inputMsg = document.createElement("textarea") as HTMLTextAreaElement
+ inputMsg.id = "input_msg"
+ inputMsg.value = `Hello world, this is a notification with HTML format using <b>bold</b> and <u>underline</u> words.`
+ document.body.appendChild(inputMsg)
+
+ let el_wrapper = document.createElement("div")
+ el_wrapper.style.marginTop = "10px"
+ document.body.appendChild(el_wrapper)
+
+ let el_button_info = document.createElement("button")
+ el_button_info.innerText = "Info"
+ el_button_info.style.marginRight = "10px"
+ el_button_info.onclick = notifInfo
+ el_wrapper.appendChild(el_button_info)
+
+ let el_button_error = document.createElement("button")
+ el_button_error.innerText = "Error"
+ el_button_error.onclick = notifError
+ el_wrapper.appendChild(el_button_error)
+
+ document.body.appendChild(document.createElement("p"))
+
+ let previewError = document.createElement("div")
+ previewError.classList.add(`${WUI_NOTIF_CLASS_ERROR}`)
+ previewError.innerText = `Preview of error style`
+ document.body.appendChild(previewError)
+
+ let previewInfo = document.createElement("div")
+ previewInfo.classList.add(`${WUI_NOTIF_CLASS_INFO}`)
+ previewInfo.innerText = `Preview of info style`
+ document.body.appendChild(previewInfo)
+}
+
+function notifInfo() {
+ wuiNotif.Info(inputMsg.value)
+}
+
+function notifError() {
+ wuiNotif.Error(inputMsg.value)
+}
+
+//----
+
+main()
diff --git a/notif/index.html b/notif/index.html
new file mode 100644
index 0000000..ca9a307
--- /dev/null
+++ b/notif/index.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8" />
+ <title>WUI - notif</title>
+ <style>
+ #input_msg {
+ width: calc(100% - 1em);
+ height: 4em;
+ }
+ .empty {
+ height: 100vh;
+ }
+ </style>
+ </head>
+ <body>
+ <p class="empty">Empty spaces.</p>
+ <script type="module" src="/notif/example.js"></script>
+ </body>
+</html>
diff --git a/notif/notif.d.ts b/notif/notif.d.ts
index 612a823..ae2c331 100644
--- a/notif/notif.d.ts
+++ b/notif/notif.d.ts
@@ -1,3 +1,6 @@
+export declare const WUI_NOTIF_ID = "wui_notif";
+export declare const WUI_NOTIF_CLASS_INFO = "wui_notif_info";
+export declare const WUI_NOTIF_CLASS_ERROR = "wui_notif_error";
export declare class WuiNotif {
private el;
private timeout;
diff --git a/notif/notif.ts b/notif/notif.ts
index 46b96d3..8b7c4b3 100644
--- a/notif/notif.ts
+++ b/notif/notif.ts
@@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-const WUI_NOTIF_ID = "wui_notif"
-const WUI_NOTIF_CLASS_INFO = "wui_notif_info"
-const WUI_NOTIF_CLASS_ERROR = "wui_notif_error"
+export const WUI_NOTIF_ID = "wui_notif"
+export const WUI_NOTIF_CLASS_INFO = "wui_notif_info"
+export const WUI_NOTIF_CLASS_ERROR = "wui_notif_error"
//
// WuiNotif implement the HTML interface to display pop-up notification.