Skip to content

Commit f754160

Browse files
committed
Moves code to remove lazy class.
1 parent ccc9798 commit f754160

File tree

5 files changed

+19
-11
lines changed

5 files changed

+19
-11
lines changed

dist/yall.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function yall (options) {
3232
if (element.nodeName == "VIDEO") {
3333
yallApplyFn(queryDOM("source", element), yallFlipDataAttrs);
3434
}
35-
35+
3636
yallFlipDataAttrs(element);
3737

3838
if (element.autoplay) {
@@ -61,6 +61,7 @@ function yall (options) {
6161
if (dataAttrs[dataAttrIndex] in element.dataset) {
6262
win["requestAnimationFrame"](() => {
6363
element.setAttribute(dataAttrs[dataAttrIndex], element.dataset[dataAttrs[dataAttrIndex]]);
64+
element.classList.remove(lazyClass);
6465
});
6566
}
6667
}
@@ -70,7 +71,11 @@ function yall (options) {
7071
// member of an array. This abstraction eliminates that repetitive code.
7172
const yallApplyFn = (items, fn) => {
7273
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
73-
fn instanceof win[io] ? fn.observe(items[itemIndex]) : fn(items[itemIndex]);
74+
if (noPolyfill) {
75+
fn(items[itemIndex]);
76+
} else {
77+
fn instanceof win[io] ? fn.observe(items[itemIndex]) : fn(items[itemIndex]);
78+
}
7479
}
7580
};
7681

@@ -88,7 +93,6 @@ function yall (options) {
8893
yallLoad(element);
8994
}
9095

91-
element.classList.remove(lazyClass);
9296
intersectionListener.unobserve(element);
9397
lazyElements = lazyElements.filter(lazyElement => lazyElement != element);
9498

@@ -138,7 +142,7 @@ function yall (options) {
138142
yallApplyFn(queryDOM(options.observeRootSelector || "body"), yallCreateMutationObserver);
139143
}
140144
} else {
141-
// IntersectionObserver not supported
145+
// IntersectionObserver not supported
142146
if (noPolyfill) {
143147
yallApplyFn(lazyElements, yallBindEvents);
144148
yallApplyFn(lazyElements, yallLoad);

dist/yall.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/yall.min.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export default function(e){var t=(e=e||{}).lazyClass||"lazy",o=e.lazyBackgroundClass||"lazy-bg",r="idleLoadTimeout"in e?e.idleLoadTimeout:200,a=e.observeChanges||!1,n=e.events||{},i=e.noPolyfill||!1,s=window,l="requestIdleCallback",d="IntersectionObserver",c=["srcset","src","poster"],u=[],v=(e,r)=>u.slice.call((r||document).querySelectorAll(e||"img."+t+",video."+t+",iframe."+t+",."+o)),b=t=>{var r=t.parentNode;"PICTURE"==r.nodeName&&m(v("source",r),f),"VIDEO"==t.nodeName&&m(v("source",t),f),f(t),t.autoplay&&t.load();var a=t.classList;a.contains(o)&&(a.remove(o),a.add(e.lazyBackgroundLoaded||"lazy-bg-loaded"))},g=e=>{for(var t in n)e.addEventListener(t,n[t].listener||n[t],n[t].options||void 0)},f=e=>{var t=function(t){c[t]in e.dataset&&s.requestAnimationFrame(()=>{e.setAttribute(c[t],e.dataset[c[t]])})};for(var o in c)t(o)},m=(e,t)=>{for(var o=0;o<e.length;o++)t instanceof s[d]?t.observe(e[o]):t(e[o])},y=e=>{if(e.isIntersecting||e.intersectionRatio){var o=e.target;l in s&&r?s[l](()=>{b(o)},{timeout:r}):b(o),o.classList.remove(t),L.unobserve(o),(p=p.filter(e=>e!=o)).length||a||L.disconnect()}},h=e=>{p.indexOf(e)<0&&(p.push(e),g(e),L.observe(e))},p=v();if(/baidu|(?:google|bing|yandex|duckduck)bot/i.test(navigator.userAgent))m(p,b);else if(d in s&&d+"Entry"in s){var L=new s[d](e=>{m(e,y)},{rootMargin:("threshold"in e?e.threshold:200)+"px 0%"});m(p,g),m(p,L),a&&m(v(e.observeRootSelector||"body"),t=>{new MutationObserver(()=>{m(v(),h)}).observe(t,e.mutationObserverOptions||{childList:!0,subtree:!0})})}else i&&(m(p,g),m(p,b))}
1+
export default function(e){const t=(e=e||{}).lazyClass||"lazy",o=e.lazyBackgroundClass||"lazy-bg",n="idleLoadTimeout"in e?e.idleLoadTimeout:200,s=e.observeChanges||!1,i=e.events||{},r=e.noPolyfill||!1,a=window,l="requestIdleCallback",d="IntersectionObserver",c=["srcset","src","poster"],u=[],b=(e,n)=>u.slice.call((n||document).querySelectorAll(e||"img."+t+",video."+t+",iframe."+t+",."+o)),v=t=>{const n=t.parentNode;"PICTURE"==n.nodeName&&m(b("source",n),f),"VIDEO"==t.nodeName&&m(b("source",t),f),f(t),t.autoplay&&t.load();const s=t.classList;s.contains(o)&&(s.remove(o),s.add(e.lazyBackgroundLoaded||"lazy-bg-loaded"))},g=e=>{for(let t in i)e.addEventListener(t,i[t].listener||i[t],i[t].options||void 0)},f=e=>{for(let o in c)c[o]in e.dataset&&a.requestAnimationFrame(()=>{e.setAttribute(c[o],e.dataset[c[o]]),e.classList.remove(t)})},m=(e,t)=>{for(let o=0;o<e.length;o++)r?t(e[o]):t instanceof a[d]?t.observe(e[o]):t(e[o])},y=e=>{if(e.isIntersecting||e.intersectionRatio){const t=e.target;l in a&&n?a[l](()=>{v(t)},{timeout:n}):v(t),z.unobserve(t),(L=L.filter(e=>e!=t)).length||s||z.disconnect()}},h=e=>{L.indexOf(e)<0&&(L.push(e),g(e),z.observe(e))},p=t=>{new MutationObserver(()=>{m(b(),h)}).observe(t,e.mutationObserverOptions||{childList:!0,subtree:!0})};let L=b();if(/baidu|(?:google|bing|yandex|duckduck)bot/i.test(navigator.userAgent))m(L,v);else if(d in a&&d+"Entry"in a){var z=new a[d](e=>{m(e,y)},{rootMargin:("threshold"in e?e.threshold:200)+"px 0%"});m(L,g),m(L,z),s&&m(b(e.observeRootSelector||"body"),p)}else r&&(m(L,g),m(L,v))}

src/yall.mjs

+8-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default function (options) {
3030
if (element.nodeName == "VIDEO") {
3131
yallApplyFn(queryDOM("source", element), yallFlipDataAttrs);
3232
}
33-
33+
3434
yallFlipDataAttrs(element);
3535

3636
if (element.autoplay) {
@@ -59,6 +59,7 @@ export default function (options) {
5959
if (dataAttrs[dataAttrIndex] in element.dataset) {
6060
win["requestAnimationFrame"](() => {
6161
element.setAttribute(dataAttrs[dataAttrIndex], element.dataset[dataAttrs[dataAttrIndex]]);
62+
element.classList.remove(lazyClass);
6263
});
6364
}
6465
}
@@ -68,7 +69,11 @@ export default function (options) {
6869
// member of an array. This abstraction eliminates that repetitive code.
6970
const yallApplyFn = (items, fn) => {
7071
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
71-
fn instanceof win[io] ? fn.observe(items[itemIndex]) : fn(items[itemIndex]);
72+
if (noPolyfill) {
73+
fn(items[itemIndex]);
74+
} else {
75+
fn instanceof win[io] ? fn.observe(items[itemIndex]) : fn(items[itemIndex]);
76+
}
7277
}
7378
};
7479

@@ -86,7 +91,6 @@ export default function (options) {
8691
yallLoad(element);
8792
}
8893

89-
element.classList.remove(lazyClass);
9094
intersectionListener.unobserve(element);
9195
lazyElements = lazyElements.filter(lazyElement => lazyElement != element);
9296

@@ -136,7 +140,7 @@ export default function (options) {
136140
yallApplyFn(queryDOM(options.observeRootSelector || "body"), yallCreateMutationObserver);
137141
}
138142
} else {
139-
// IntersectionObserver not supported
143+
// IntersectionObserver not supported
140144
if (noPolyfill) {
141145
yallApplyFn(lazyElements, yallBindEvents);
142146
yallApplyFn(lazyElements, yallLoad);

test/js/yall.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)