27 lines
733 B
JavaScript
27 lines
733 B
JavaScript
import {Controller} from '@hotwired/stimulus'
|
|
|
|
/*
|
|
* Shows an indicator over an iframe until its content has loaded.
|
|
*
|
|
* The controller sets the frame's src itself, after the load listener is attached, so a fast
|
|
* response cannot finish before anybody listens.
|
|
*/
|
|
export default class extends Controller {
|
|
static targets = ['frame', 'indicator']
|
|
static values = {src: String}
|
|
|
|
connect() {
|
|
this.loaded = this.loaded.bind(this)
|
|
this.frameTarget.addEventListener('load', this.loaded)
|
|
this.frameTarget.src = this.srcValue
|
|
}
|
|
|
|
disconnect() {
|
|
this.frameTarget.removeEventListener('load', this.loaded)
|
|
}
|
|
|
|
loaded() {
|
|
this.indicatorTarget.classList.add('hidden')
|
|
}
|
|
}
|