Files
myep/assets/controllers/gravatar_controller.js
T

18 lines
461 B
JavaScript

import {Controller} from '@hotwired/stimulus'
export default class extends Controller {
static values = {url: String, alt: String}
static classes = ['image']
connect() {
const img = new Image()
img.onload = () => {
img.classList.add(...this.imageClasses)
this.element.innerHTML = ''
this.element.appendChild(img)
}
img.alt = this.altValue
img.src = this.urlValue
}
}