Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #317 from parameter1/revert-316-browser-lazyloading
Browse files Browse the repository at this point in the history
Revert "Use native browser lazyloading"
  • Loading branch information
brandonbk authored Jun 1, 2022
2 parents 41865da + be87651 commit 4fd145c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ $ const blockName = input.blockName || "site-navbar";
$ const elementName = input.name || "logo";
$ const classNames = [`${blockName}__${elementName}`, input.class];
$ const lazyload = input.lazyload != null ? input.lazyload : false;
$ const loading = (lazyload) ? "lazy" : null;
$ if (lazyload) classNames.push("lazyload");

<img
class=classNames
alt=input.alt
src=input.src
srcset=input.srcset
loading=loading
>
30 changes: 21 additions & 9 deletions packages/marko-web/components/element/components/image.marko
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,25 @@ $ const lazyload = config.lazyloadImages() && input.lazyload !== false
$ const srcset = getAsArray(input.srcset).join(",") || null;

$ const classNames = [input.class];
$ const loading = (lazyload) ? "lazy" : null;
$ if (lazyload) classNames.push("lazyload");

<img
...input.attrs
src=src
srcset=srcset
class=classNames
alt=alt
loading=loading
/>
<if(lazyload)>
<img
...input.attrs
src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
srcset=null
data-src=src
data-srcset=srcset
class=classNames
alt=alt
/>
</if>
<else>
<img
...input.attrs
src=src
srcset=srcset
class=classNames
alt=alt
/>
</else>
5 changes: 3 additions & 2 deletions packages/marko-web/utils/embedded-media/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ module.exports = (tag, { config } = {}, { lazyloadImages } = {}) => {
};

const imgAttrs = {
src,
class: lazyload ? 'lazyload' : null,
src: lazyload ? 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==' : src,
'data-src': lazyload ? src : null,
'data-image-id': tag.id,
alt,
loading: lazyload ? 'lazy' : null,
};
const captionElement = caption ? `<span class="caption">${caption}</span>` : '';
const creditElement = credit ? `<span class="credit">${credit}</span>` : '';
Expand Down

0 comments on commit 4fd145c

Please sign in to comment.