summaryrefslogtreecommitdiff
path: root/assets/site.js
diff options
context:
space:
mode:
authorhref <href@random.sh>2021-09-03 04:02:43 +0200
committerhref <href@random.sh>2021-09-03 04:02:43 +0200
commit5fc45a0e3b144b5e87845d068940afb90c3646a6 (patch)
tree364e9276a63bd23d8033cdae4a9e3e4d5fd755c1 /assets/site.js
parentimprove puppets, fix uploads (diff)
assets..
Diffstat (limited to 'assets/site.js')
-rw-r--r--assets/site.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/assets/site.js b/assets/site.js
index 2a1bdd6..9fc1a44 100644
--- a/assets/site.js
+++ b/assets/site.js
@@ -1,6 +1,36 @@
import * as Turbo from "@hotwired/turbo"
import { Application } from "stimulus"
import { definitions } from 'stimulus:./controllers';
+import {Socket} from "phoenix"
+import {LiveSocket} from "phoenix_live_view"
+import { DateTime } from "luxon";
const app = Application.start();
app.load(definitions);
+
+let Hooks = {}
+
+Hooks.AutoFocus = {
+ mounted() {
+ this.el.focus();
+ }
+}
+
+Hooks.NaiveDateTimeUTC = {
+ mounted() {
+ var intl = Intl.DateTimeFormat().resolvedOptions();
+ var tz = document.body.dataset.tz || intl.timeZone || "UTC";
+ var locale = document.body.dataset.locale || intl.locale || "en";
+
+ var style = DateTime[this.el.dataset.timeFormat];
+ var date = DateTime.fromISO(this.el.dateTime, { zone: 'utc' }).setZone(tz).setLocale(locale);
+ this.el.innerText = date.toLocaleString(style);
+ }
+}
+
+let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
+let liveSocket = new LiveSocket("/live", Socket, {hooks: Hooks, params: {_csrf_token: csrfToken}})
+
+// Connect if there are any LiveViews on the page
+liveSocket.connect()
+