Skip to content
This repository was archived by the owner on Jan 10, 2021. It is now read-only.

Commit 7a89e28

Browse files
committed
0.5.1
1 parent b74ee9f commit 7a89e28

File tree

5 files changed

+72
-15
lines changed

5 files changed

+72
-15
lines changed

dist/zz-load.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ var zzLoad = (function () {
131131
}
132132
}
133133

134-
img.onload = onload;
135134
img.onerror = onerror; // img
136135

137136
var source = element.getAttribute(attrs.sourceImg);
@@ -172,8 +171,20 @@ var zzLoad = (function () {
172171
source = element.getAttribute(attrs.sourceBgImg);
173172

174173
if (source) {
174+
img.onload = function () {
175+
if (options.setSourcesOnlyOnLoad) {
176+
element.style.backgroundImage = "url(".concat(source, ")");
177+
}
178+
179+
loadActions(img.currentSrc);
180+
};
181+
175182
img.src = source;
176-
element.style.backgroundImage = "url(".concat(source, ")");
183+
184+
if (options.setSourcesOnlyOnLoad !== true) {
185+
element.style.backgroundImage = "url(".concat(source, ")");
186+
}
187+
177188
return null;
178189
} // SVG image
179190

@@ -184,8 +195,20 @@ var zzLoad = (function () {
184195
var image = element.querySelector('image');
185196

186197
if (image instanceof window.SVGImageElement) {
198+
img.onload = function () {
199+
if (options.setSourcesOnlyOnLoad) {
200+
image.setAttribute('href', source);
201+
}
202+
203+
loadActions(img.currentSrc);
204+
};
205+
187206
img.src = source;
188-
image.setAttribute('href', source);
207+
208+
if (options.setSourcesOnlyOnLoad !== true) {
209+
image.setAttribute('href', source);
210+
}
211+
189212
return null;
190213
}
191214
} // iframe
@@ -448,7 +471,6 @@ var zzLoad = (function () {
448471
var options = _extend(userOptions);
449472

450473
var observer = null;
451-
console.log(options, userOptions);
452474

453475
if (window.IntersectionObserver) {
454476
observer = new window.IntersectionObserver(_onIntersection(options), {

dist/zz-load.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/assets/js/zz-load.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ var zzLoad = (function () {
131131
}
132132
}
133133

134-
img.onload = onload;
135134
img.onerror = onerror; // img
136135

137136
var source = element.getAttribute(attrs.sourceImg);
@@ -172,8 +171,20 @@ var zzLoad = (function () {
172171
source = element.getAttribute(attrs.sourceBgImg);
173172

174173
if (source) {
174+
img.onload = function () {
175+
if (options.setSourcesOnlyOnLoad) {
176+
element.style.backgroundImage = "url(".concat(source, ")");
177+
}
178+
179+
loadActions(img.currentSrc);
180+
};
181+
175182
img.src = source;
176-
element.style.backgroundImage = "url(".concat(source, ")");
183+
184+
if (options.setSourcesOnlyOnLoad !== true) {
185+
element.style.backgroundImage = "url(".concat(source, ")");
186+
}
187+
177188
return null;
178189
} // SVG image
179190

@@ -184,8 +195,20 @@ var zzLoad = (function () {
184195
var image = element.querySelector('image');
185196

186197
if (image instanceof window.SVGImageElement) {
198+
img.onload = function () {
199+
if (options.setSourcesOnlyOnLoad) {
200+
image.setAttribute('href', source);
201+
}
202+
203+
loadActions(img.currentSrc);
204+
};
205+
187206
img.src = source;
188-
image.setAttribute('href', source);
207+
208+
if (options.setSourcesOnlyOnLoad !== true) {
209+
image.setAttribute('href', source);
210+
}
211+
189212
return null;
190213
}
191214
} // iframe
@@ -448,7 +471,6 @@ var zzLoad = (function () {
448471
var options = _extend(userOptions);
449472

450473
var observer = null;
451-
console.log(options, userOptions);
452474

453475
if (window.IntersectionObserver) {
454476
observer = new window.IntersectionObserver(_onIntersection(options), {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "zz-load",
3-
"version": "0.5.0",
3+
"version": "0.5.1",
44
"description": "",
55
"main": "zz-load.es.js",
66
"scripts": {

src/zz-load.es.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ const _load = (element, options, asPromise) => {
9898
}
9999
}
100100

101-
img.onload = onload;
102101
img.onerror = onerror;
103102

104103
// img
@@ -132,8 +131,16 @@ const _load = (element, options, asPromise) => {
132131
// style="background-image: url(...)"
133132
source = element.getAttribute(attrs.sourceBgImg);
134133
if (source) {
134+
img.onload = function () {
135+
if (options.setSourcesOnlyOnLoad) {
136+
element.style.backgroundImage = `url(${source})`;
137+
}
138+
loadActions(img.currentSrc);
139+
};
135140
img.src = source;
136-
element.style.backgroundImage = `url(${source})`;
141+
if (options.setSourcesOnlyOnLoad !== true) {
142+
element.style.backgroundImage = `url(${source})`;
143+
}
137144
return null;
138145
}
139146

@@ -142,8 +149,16 @@ const _load = (element, options, asPromise) => {
142149
if (source) {
143150
let image = element.querySelector('image');
144151
if (image instanceof window.SVGImageElement) {
152+
img.onload = function () {
153+
if (options.setSourcesOnlyOnLoad) {
154+
image.setAttribute('href', source);
155+
}
156+
loadActions(img.currentSrc);
157+
};
145158
img.src = source;
146-
image.setAttribute('href', source);
159+
if (options.setSourcesOnlyOnLoad !== true) {
160+
image.setAttribute('href', source);
161+
}
147162
return null;
148163
}
149164
}
@@ -359,8 +374,6 @@ function zzLoad (elements, userOptions) {
359374
let options = _extend(userOptions);
360375
let observer = null;
361376

362-
console.log(options, userOptions);
363-
364377
if (window.IntersectionObserver) {
365378
observer = new window.IntersectionObserver(_onIntersection(options), {
366379
rootMargin: options.rootMargin,

0 commit comments

Comments
 (0)