diff --git a/assets/js/app.js b/assets/js/app.js index d0664526..b1528d7e 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -17,8 +17,15 @@ import {Socket} from "phoenix" import topbar from "topbar" import {LiveSocket} from "phoenix_live_view" +let Hooks = {}; +Hooks.MaintainAttrs = { + attrs(){ return this.el.getAttribute("data-attrs").split(", ") }, + beforeUpdate(){ this.prevAttrs = this.attrs().map(name => [name, this.el.getAttribute(name)]) }, + updated(){ this.prevAttrs.forEach(([name, val]) => this.el.setAttribute(name, val)) } +}; + let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content") -let liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken}}) +let liveSocket = new LiveSocket("/live", Socket, {hooks: Hooks, params: {_csrf_token: csrfToken}}) // Show progress bar on live navigation and form submits topbar.config({barColors: {0: "#29d"}, shadowColor: "rgba(0, 0, 0, .3)"})