49 lines
1.8 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
import CursorTracker from "./hooks/cursor_tracker"
26
27
let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
28
let liveSocket = new LiveSocket("/live", Socket, {
29
longPollFallbackMs: 2500,
30
params: {_csrf_token: csrfToken},
31
hooks: {
32
Highlight,
33
CursorTracker
34
}
35
})
36
37
// Show progress bar on live navigation and form submits
38
topbar.config({barColors: {0: "#29d"}, shadowColor: "rgba(0, 0, 0, .3)"})
39
window.addEventListener("phx:page-loading-start", _info => topbar.show(300))
40
window.addEventListener("phx:page-loading-stop", _info => topbar.hide())
41
42
// connect if there are any LiveViews on the page
43
liveSocket.connect()
44
45
// expose liveSocket on window for web console debug logs and latency simulation:
46
// >> liveSocket.enableDebug()
47
// >> liveSocket.enableLatencySim(1000) // enabled for duration of browser session
48
// >> liveSocket.disableLatencySim()
49
window.liveSocket = liveSocket
50