Skip to content

Commit 158d3d2

Browse files
committed
refactor: continue to initialize even if some images fail to load
1 parent e19fdcc commit 158d3d2

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## next
44

5+
- Continue to initialize even if some images fail to load in inline mode.
56
- Avoid conflicts with nested modals (#540).
67

78
## 1.10.4 (Feb 13, 2022)

src/js/viewer.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
CLASS_INVISIBLE,
1616
DATA_ACTION,
1717
EVENT_CLICK,
18+
EVENT_ERROR,
1819
EVENT_LOAD,
1920
EVENT_READY,
2021
NAMESPACE,
@@ -152,6 +153,7 @@ class Viewer {
152153
forEach(images, (image) => {
153154
if (!image.complete) {
154155
removeListener(image, EVENT_LOAD, progress);
156+
removeListener(image, EVENT_ERROR, progress);
155157
}
156158
});
157159
},
@@ -161,7 +163,19 @@ class Viewer {
161163
if (image.complete) {
162164
progress();
163165
} else {
164-
addListener(image, EVENT_LOAD, progress, {
166+
let onLoad;
167+
let onError;
168+
169+
addListener(image, EVENT_LOAD, onLoad = () => {
170+
removeListener(image, EVENT_ERROR, onError);
171+
progress();
172+
}, {
173+
once: true,
174+
});
175+
addListener(image, EVENT_ERROR, onError = () => {
176+
removeListener(image, EVENT_LOAD, onLoad);
177+
progress();
178+
}, {
165179
once: true,
166180
});
167181
}

0 commit comments

Comments
 (0)