forked from shibao/cannery
		
	add maintainattrs hook for textareas
This commit is contained in:
		@@ -17,8 +17,15 @@ import {Socket} from "phoenix"
 | 
				
			|||||||
import topbar from "topbar"
 | 
					import topbar from "topbar"
 | 
				
			||||||
import {LiveSocket} from "phoenix_live_view"
 | 
					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 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
 | 
					// Show progress bar on live navigation and form submits
 | 
				
			||||||
topbar.config({barColors: {0: "#29d"}, shadowColor: "rgba(0, 0, 0, .3)"})
 | 
					topbar.config({barColors: {0: "#29d"}, shadowColor: "rgba(0, 0, 0, .3)"})
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user