summaryrefslogblamecommitdiff
path: root/assets/site.js
blob: 9fc1a442aa3a76e1c411b831dcd949a08371ee56 (plain) (tree)
1
2
3
4
5
6
7
8
9


                                                     


                                            


                                


























                                                                                                   
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()