diff --git a/packages/rocketchat-lazy-load/client/lazyloadImage.html b/packages/rocketchat-lazy-load/client/lazyloadImage.html index c88c6b927623..b043723f1334 100644 --- a/packages/rocketchat-lazy-load/client/lazyloadImage.html +++ b/packages/rocketchat-lazy-load/client/lazyloadImage.html @@ -1,4 +1,4 @@ diff --git a/packages/rocketchat-lazy-load/client/lazyloadImage.js b/packages/rocketchat-lazy-load/client/lazyloadImage.js index c4c98fc71fa2..c48015dce546 100644 --- a/packages/rocketchat-lazy-load/client/lazyloadImage.js +++ b/packages/rocketchat-lazy-load/client/lazyloadImage.js @@ -1,17 +1,27 @@ import './lazyloadImage.html'; import { addImage, fixCordova } from './'; +const emptyImageEncoded = + 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8+/u3PQAJJAM0dIyWdgAAAABJRU5ErkJggg=='; + Template.lazyloadImage.helpers({ class() { const loaded = Template.instance().loaded.get(); return `${ this.class } ${ loaded ? '' : 'lazy-img' }`; }, - lazy() { + + srcUrl() { + return this.src && fixCordova(this.src); + }, + + lazySrcUrl() { const { preview, placeholder, src } = this; + if (Template.instance().loaded.get() || (!preview && !placeholder)) { return fixCordova(src); } - return `data:image/png;base64,${ preview || 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8+/u3PQAJJAM0dIyWdgAAAABJRU5ErkJggg==' }`; + + return `data:image/png;base64,${ preview || emptyImageEncoded }`; }, });