summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorWlodekM <[email protected]>2024-12-01 12:32:53 +0200
committerWlodekM <[email protected]>2024-12-01 12:32:53 +0200
commit84ebada2cc3a7f6f094d249ceae0df49f66e55bc (patch)
tree470b9623677e0144d023ae99e6bb564fa89043ba /lib
parent18b3dc1aeaeac7114f68ea0eab9ad59c7991b0ae (diff)
wip user popup
Diffstat (limited to 'lib')
-rw-r--r--lib/htmlbuilder.js2
-rw-r--r--lib/popups.js34
-rw-r--r--lib/t.js26
3 files changed, 61 insertions, 1 deletions
diff --git a/lib/htmlbuilder.js b/lib/htmlbuilder.js
index 483b77b..110da39 100644
--- a/lib/htmlbuilder.js
+++ b/lib/htmlbuilder.js
@@ -8,7 +8,7 @@ function makeSigmaHtmlPlusElement(elem) {
         elem.innerHTML = html;
         return elem;
     }
-    elem.text = function (text) {
+    elem.text = elem.txt = function (text) {
         elem.innerText = text;
         return elem;
     }
diff --git a/lib/popups.js b/lib/popups.js
new file mode 100644
index 0000000..3d7e592
--- /dev/null
+++ b/lib/popups.js
@@ -0,0 +1,34 @@
+function DocElemListFromHTML(html) {
+    return new DOMParser().parseFromString(html, "text/html").body.childNodes;
+}
+
+/** AboutPad popup system */
+export function openPopup(html) {
+    document.querySelector(".ap-popup-container").classList.remove("hidden")
+    document.querySelector(".ap-popup").innerHTML = ""
+    let popup = document.querySelector(".ap-popup")
+    let elems;
+    console.log(typeof html)
+    if(typeof html == 'string') {
+        let htm = String(html)
+        htm = htm.replace(/\$\((.*?)\)\$/g, (a) => {
+            return eval(a.replace(/\$\((.*?)\)\$/g, "$1"))
+        })
+        elems = DocElemListFromHTML(String(htm))
+    } else elems = [html]
+    let len = elems.length
+    for (let i = 0; i < len; i++) {
+        const element = elems[0];
+        popup.appendChild(element)
+    }
+    let closeBtn = document.querySelector("#ap-btn-close-popup")
+    if(closeBtn) closeBtn.addEventListener('click', (ev) => {
+        document.querySelector(".ap-popup-container").classList.add("hidden")
+    })
+}
+
+document.querySelector(".ap-popup-container").addEventListener("click", function(ev) {
+	if(ev.target != this) return;
+    this.classList.add("hidden")
+	console.log("click!", ev)
+})
\ No newline at end of file
diff --git a/lib/t.js b/lib/t.js
new file mode 100644
index 0000000..77af51f
--- /dev/null
+++ b/lib/t.js
@@ -0,0 +1,26 @@
+export function timeSince(date) {
+    const seconds = Math.floor((new Date() - date) / 1000);
+
+    const interval = seconds / 31536000;
+
+    if (interval > 1) {
+        return Math.floor(interval) + " years";
+    }
+    interval = seconds / 2592000;
+    if (interval > 1) {
+        return Math.floor(interval) + " months";
+    }
+    interval = seconds / 86400;
+    if (interval > 1) {
+        return Math.floor(interval) + " days";
+    }
+    interval = seconds / 3600;
+    if (interval > 1) {
+        return Math.floor(interval) + " hours";
+    }
+    interval = seconds / 60;
+    if (interval > 1) {
+        return Math.floor(interval) + " minutes";
+    }
+    return Math.floor(seconds) + " seconds";
+}
\ No newline at end of file