viewerjs 1.10.4 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/js/render.js CHANGED
@@ -15,6 +15,7 @@ import {
15
15
  getImageNaturalSizes,
16
16
  getTransforms,
17
17
  hasClass,
18
+ isNumber,
18
19
  removeClass,
19
20
  removeListener,
20
21
  setData,
@@ -96,7 +97,10 @@ export default {
96
97
  }
97
98
  });
98
99
 
99
- img.src = src || url;
100
+ if (options.navbar) {
101
+ img.src = src || url;
102
+ }
103
+
100
104
  img.alt = alt;
101
105
  img.setAttribute('data-original-url', url || src);
102
106
  item.setAttribute('data-index', index);
@@ -204,6 +208,7 @@ export default {
204
208
 
205
209
  sizingImage = getImageNaturalSizes(image, options, (naturalWidth, naturalHeight) => {
206
210
  const aspectRatio = naturalWidth / naturalHeight;
211
+ let initialCoverage = Math.max(0, Math.min(1, options.initialCoverage));
207
212
  let width = viewerWidth;
208
213
  let height = viewerHeight;
209
214
 
@@ -215,8 +220,9 @@ export default {
215
220
  width = viewerHeight * aspectRatio;
216
221
  }
217
222
 
218
- width = Math.min(width * 0.9, naturalWidth);
219
- height = Math.min(height * 0.9, naturalHeight);
223
+ initialCoverage = isNumber(initialCoverage) ? initialCoverage : 0.9;
224
+ width = Math.min(width * initialCoverage, naturalWidth);
225
+ height = Math.min(height * initialCoverage, naturalHeight);
220
226
 
221
227
  const left = (viewerWidth - width) / 2;
222
228
  const top = (viewerHeight - height) / 2;
package/src/js/viewer.js CHANGED
@@ -15,6 +15,7 @@ import {
15
15
  CLASS_INVISIBLE,
16
16
  DATA_ACTION,
17
17
  EVENT_CLICK,
18
+ EVENT_ERROR,
18
19
  EVENT_LOAD,
19
20
  EVENT_READY,
20
21
  NAMESPACE,
@@ -152,6 +153,7 @@ class Viewer {
152
153
  forEach(images, (image) => {
153
154
  if (!image.complete) {
154
155
  removeListener(image, EVENT_LOAD, progress);
156
+ removeListener(image, EVENT_ERROR, progress);
155
157
  }
156
158
  });
157
159
  },
@@ -161,7 +163,19 @@ class Viewer {
161
163
  if (image.complete) {
162
164
  progress();
163
165
  } 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
+ }, {
165
179
  once: true,
166
180
  });
167
181
  }