app.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // We need to import the CSS so that webpack will load it.
  2. // The MiniCssExtractPlugin is used to separate it out into
  3. // its own CSS file.
  4. import "../css/app.scss"
  5. // webpack automatically bundles all modules in your
  6. // entry points. Those entry points can be configured
  7. // in "webpack.config.js".
  8. //
  9. // Import deps with the dep name or local files with a relative path, for example:
  10. //
  11. // import {Socket} from "phoenix"
  12. // import socket from "./socket"
  13. //
  14. import "phoenix_html"
  15. import {Socket} from "phoenix"
  16. import topbar from "topbar"
  17. import {LiveSocket} from "phoenix_live_view"
  18. let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
  19. let liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken}})
  20. // Show progress bar on live navigation and form submits
  21. topbar.config({barColors: {0: "#29d"}, shadowColor: "rgba(0, 0, 0, .3)"})
  22. window.addEventListener("phx:page-loading-start", info => topbar.show())
  23. window.addEventListener("phx:page-loading-stop", info => topbar.hide())
  24. // connect if there are any LiveViews on the page
  25. liveSocket.connect()
  26. // expose liveSocket on window for web console debug logs and latency simulation:
  27. // >> liveSocket.enableDebug()
  28. // >> liveSocket.enableLatencySim(1000) // enabled for duration of browser session
  29. // >> liveSocket.disableLatencySim()
  30. window.liveSocket = liveSocket