app.js 1.7 KB

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