46 lines
1.7 kB
1
// If you want to use Phoenix channels, run `mix help phx.gen.channel`
2
// to get started and then uncomment the line below.
3
// import "./user_socket.js"
4
5
// You can include dependencies in two ways.
6
//
7
// The simplest option is to put them in assets/vendor and
8
// import them using relative paths:
9
//
10
// import "../vendor/some-package.js"
11
//
12
// Alternatively, you can `npm install some-package --prefix assets` and import
13
// them using a path starting with the package name:
14
//
15
// import "some-package"
16
//
17
18
// Include phoenix_html to handle method=PUT/DELETE in forms and buttons.
19
import "phoenix_html"
20
// Establish Phoenix Socket and LiveView configuration.
21
import {Socket} from "phoenix"
22
import {LiveSocket} from "phoenix_live_view"
23
import topbar from "../vendor/topbar"
24
import Highlight from "./hooks/highlight"
25
26
let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
27
let liveSocket = new LiveSocket("/live", Socket, {
28
longPollFallbackMs: 2500,
29
params: {_csrf_token: csrfToken},
30
hooks: { Highlight }
31
})
32
33
// Show progress bar on live navigation and form submits
34
topbar.config({barColors: {0: "#29d"}, shadowColor: "rgba(0, 0, 0, .3)"})
35
window.addEventListener("phx:page-loading-start", _info => topbar.show(300))
36
window.addEventListener("phx:page-loading-stop", _info => topbar.hide())
37
38
// connect if there are any LiveViews on the page
39
liveSocket.connect()
40
41
// expose liveSocket on window for web console debug logs and latency simulation:
42
// >> liveSocket.enableDebug()
43
// >> liveSocket.enableLatencySim(1000) // enabled for duration of browser session
44
// >> liveSocket.disableLatencySim()
45
window.liveSocket = liveSocket
46
47