Packages
phx_new
1.8.9
1.8.9
1.8.8
1.8.7
1.8.6
1.8.5
1.8.4
1.8.3
1.8.2
1.8.1
1.8.0
1.8.0-rc.4
1.8.0-rc.3
1.8.0-rc.2
1.8.0-rc.1
1.8.0-rc.0
1.7.24
1.7.23
1.7.22
1.7.21
1.7.20
1.7.19
1.7.18
1.7.17
1.7.16
1.7.15
1.7.14
1.7.13
1.7.12
1.7.11
1.7.10
1.7.9
1.7.8
1.7.7
1.7.6
1.7.5
1.7.4
1.7.3
1.7.2
1.7.1
1.7.0
1.7.0-rc.3
1.7.0-rc.2
1.7.0-rc.1
1.7.0-rc.0
1.6.17
1.6.16
1.6.15
1.6.14
1.6.13
1.6.12
1.6.11
1.6.10
1.6.9
1.6.8
1.6.7
1.6.6
1.6.5
1.6.4
1.6.3
1.6.2
1.6.1
1.6.0
1.6.0-rc.1
1.6.0-rc.0
1.5.15
1.5.14
1.5.13
1.5.12
1.5.11
1.5.10
1.5.9
1.5.8
1.5.7
1.5.6
1.5.5
1.5.4
1.5.3
1.5.2
1.5.1
1.5.0
1.5.0-rc.0
1.4.18
1.4.17
1.4.16
1.4.15
1.4.14
1.4.13
1.4.12
1.4.11
1.4.10
1.4.9
1.4.8
1.4.7
1.4.6
1.4.5
1.4.4
1.4.3
1.4.2
1.4.1
1.4.0
1.4.0-rc.3
1.4.0-rc.2
1.4.0-rc.1
1.4.0-rc.0
1.4.0-dev.0
1.3.5
Phoenix framework project generator. Provides a `mix phx.new` task to bootstrap a new Elixir application with Phoenix dependencies.
Current section
Files
Jump to
Current section
Files
templates/phx_assets/app.js.eex
// If you want to use Phoenix channels, run `mix help phx.gen.channel`
// to get started and then uncomment the line below.
// import "./user_socket.js"
// You can include dependencies in two ways.
//
// The simplest option is to put them in assets/vendor and
// import them using relative paths:
//
// import "../vendor/some-package.js"
//
// Alternatively, you can `npm install some-package --prefix assets` and import
// them using a path starting with the package name:
//
// import "some-package"
//
// If you have dependencies that try to import CSS, esbuild will generate a separate `app.css` file.
// To load it, simply add a second `<link>` to your `root.html.heex` file.
<%= if @html do %>
// Include phoenix_html to handle method=PUT/DELETE in forms and buttons.
import "phoenix_html"
// Establish Phoenix Socket and LiveView configuration.
<%= @live_comment %>import {Socket} from "<%= @phoenix_js_path %>"
<%= @live_comment %>import {LiveSocket} from "phoenix_live_view"
<%= @live_comment %>import {hooks as colocatedHooks} from "phoenix-colocated/<%= @web_app_name %>"
<%= @live_comment %>import topbar from "../vendor/topbar"
<%= @live_comment %>const csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
<%= @live_comment %>const liveSocket = new LiveSocket("/live", Socket, {
<%= @live_comment %> longPollFallbackMs: 2500,
<%= @live_comment %> params: {_csrf_token: csrfToken},
<%= @live_comment %> hooks: {...colocatedHooks},
<%= @live_comment %>})
// Show progress bar on live navigation and form submits
<%= @live_comment %>topbar.config({barColors: {0: "#29d"}, shadowColor: "rgba(0, 0, 0, .3)"})
<%= @live_comment %>window.addEventListener("phx:page-loading-start", _info => topbar.show(300))
<%= @live_comment %>window.addEventListener("phx:page-loading-stop", _info => topbar.hide())
// connect if there are any LiveViews on the page
<%= @live_comment %>liveSocket.connect()
// expose liveSocket on window for web console debug logs and latency simulation:
// >> liveSocket.enableDebug()
// >> liveSocket.enableLatencySim(1000) // enabled for duration of browser session
// >> liveSocket.disableLatencySim()
<%= @live_comment %>window.liveSocket = liveSocket
// The lines below enable quality of life phoenix_live_reload
// development features:
//
// 1. stream server logs to the browser console
// 2. click on elements to jump to their definitions in your code editor
//
<%= @live_comment %>if (process.env.NODE_ENV === "development") {
<%= @live_comment %> window.addEventListener("phx:live_reload:attached", ({detail: reloader}) => {
<%= @live_comment %> // Enable server log streaming to client.
<%= @live_comment %> // Disable with reloader.disableServerLogs()
<%= @live_comment %> reloader.enableServerLogs()
<%= @live_comment %>
<%= @live_comment %> // Open configured PLUG_EDITOR at file:line of the clicked element's HEEx component
<%= @live_comment %> //
<%= @live_comment %> // * click with "c" key pressed to open at caller location
<%= @live_comment %> // * click with "d" key pressed to open at function component definition location
<%= @live_comment %> let keyDown
<%= @live_comment %> window.addEventListener("keydown", e => keyDown = e.key)
<%= @live_comment %> window.addEventListener("keyup", _e => keyDown = null)
<%= @live_comment %> window.addEventListener("click", e => {
<%= @live_comment %> if(keyDown === "c"){
<%= @live_comment %> e.preventDefault()
<%= @live_comment %> e.stopImmediatePropagation()
<%= @live_comment %> reloader.openEditorAtCaller(e.target)
<%= @live_comment %> } else if(keyDown === "d"){
<%= @live_comment %> e.preventDefault()
<%= @live_comment %> e.stopImmediatePropagation()
<%= @live_comment %> reloader.openEditorAtDef(e.target)
<%= @live_comment %> }
<%= @live_comment %> }, true)
<%= @live_comment %>
<%= @live_comment %> window.liveReloader = reloader
<%= @live_comment %> })
<%= @live_comment %>}
<%= if not @live do %>
// Handle flash close
document.querySelectorAll("[role=alert][data-flash]").forEach((el) => {
el.addEventListener("click", () => {
el.setAttribute("hidden", "")
})
})<% end %><% end %>