Skip to content

Commit

Permalink
fix(g-image): run onload event once
Browse files Browse the repository at this point in the history
Might be ralated to #93
  • Loading branch information
hjvedvik committed Jan 26, 2019
1 parent b8178a1 commit ca6f015
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions gridsome/app/components/Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,24 @@ function intersectionHandler ({ intersectionRatio, target }) {
}

function loadImage (el) {
const src = el.getAttribute('data-src')
const srcset = el.getAttribute('data-srcset')
const sizes = el.getAttribute('data-sizes')

if (!src) return

el.onload = function () {
delete el.dataset.src
delete el.dataset.srcset
delete el.dataset.sizes
delete el.onload
el.removeAttribute('data-src')
el.removeAttribute('data-srcset')
el.removeAttribute('data-sizes')

el.classList.remove('g-image--loading')
el.classList.add('g-image--loaded')

delete el.onload
}

el.src = el.dataset.src
el.srcset = el.dataset.srcset
el.sizes = el.dataset.sizes
el.src = src
el.srcset = srcset
el.sizes = sizes
}

0 comments on commit ca6f015

Please sign in to comment.