forked from shibao/cannery
		
	add MaintainAttrs hook
This commit is contained in:
		@@ -25,9 +25,13 @@ import 'phoenix_html'
 | 
				
			|||||||
import { Socket } from 'phoenix'
 | 
					import { Socket } from 'phoenix'
 | 
				
			||||||
import { LiveSocket } from 'phoenix_live_view'
 | 
					import { LiveSocket } from 'phoenix_live_view'
 | 
				
			||||||
import topbar from '../vendor/topbar'
 | 
					import topbar from '../vendor/topbar'
 | 
				
			||||||
 | 
					import MaintainAttrs from './maintain_attrs'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute('content')
 | 
					const csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute('content')
 | 
				
			||||||
const liveSocket = new LiveSocket('/live', Socket, { params: { _csrf_token: csrfToken } })
 | 
					const liveSocket = new LiveSocket('/live', Socket, {
 | 
				
			||||||
 | 
					  params: { _csrf_token: csrfToken },
 | 
				
			||||||
 | 
					  hooks: { MaintainAttrs }
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 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)' })
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										8
									
								
								assets/js/maintain_attrs.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								assets/js/maintain_attrs.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
				
			|||||||
 | 
					// maintain user adjusted attributes, like textbox length on phoenix liveview
 | 
				
			||||||
 | 
					// update. https://github.com/phoenixframework/phoenix_live_view/issues/1011
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default {
 | 
				
			||||||
 | 
					  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)) }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user