From 708b8afdf553defaf6661e6f9430cf684de21246 Mon Sep 17 00:00:00 2001 From: Pete Matsyburka Date: Mon, 14 Jul 2025 17:13:04 +0300 Subject: [PATCH] optimize --- app/javascript/elements/page_container.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/javascript/elements/page_container.js b/app/javascript/elements/page_container.js index d909ae7f..ca5221ba 100644 --- a/app/javascript/elements/page_container.js +++ b/app/javascript/elements/page_container.js @@ -1,14 +1,12 @@ export default class extends HTMLElement { connectedCallback () { - this.image.addEventListener('load', (e) => { - this.image.setAttribute('width', e.target.naturalWidth) - this.image.setAttribute('height', e.target.naturalHeight) + const image = this.querySelector('img') + + image.addEventListener('load', (e) => { + image.setAttribute('width', e.target.naturalWidth) + image.setAttribute('height', e.target.naturalHeight) this.style.aspectRatio = `${e.target.naturalWidth} / ${e.target.naturalHeight}` }) } - - get image () { - return this.querySelector('img') - } }