viewerjs 1.9.2 → 1.10.3

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
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  CLASS_LOADING,
3
3
  CLASS_TRANSITION,
4
+ EVENT_ERROR,
4
5
  EVENT_LOAD,
5
6
  EVENT_TRANSITION_END,
6
7
  EVENT_VIEWED,
@@ -116,6 +117,8 @@ export default {
116
117
 
117
118
  forEach(items, (item) => {
118
119
  const image = item.firstElementChild;
120
+ let onLoad;
121
+ let onError;
119
122
 
120
123
  setData(image, 'filled', true);
121
124
 
@@ -123,7 +126,9 @@ export default {
123
126
  addClass(item, CLASS_LOADING);
124
127
  }
125
128
 
126
- addListener(image, EVENT_LOAD, (event) => {
129
+ addListener(image, EVENT_LOAD, onLoad = (event) => {
130
+ removeListener(image, EVENT_ERROR, onError);
131
+
127
132
  if (options.loading) {
128
133
  removeClass(item, CLASS_LOADING);
129
134
  }
@@ -132,6 +137,15 @@ export default {
132
137
  }, {
133
138
  once: true,
134
139
  });
140
+ addListener(image, EVENT_ERROR, onError = () => {
141
+ removeListener(image, EVENT_LOAD, onLoad);
142
+
143
+ if (options.loading) {
144
+ removeClass(item, CLASS_LOADING);
145
+ }
146
+ }, {
147
+ once: true,
148
+ });
135
149
  });
136
150
 
137
151
  if (options.transition) {
@@ -143,16 +157,24 @@ export default {
143
157
  }
144
158
  },
145
159
 
146
- renderList(index) {
147
- const i = index || this.index;
148
- const width = this.items[i].offsetWidth || 30;
149
- const outerWidth = width + 1; // 1 pixel of `margin-left` width
160
+ renderList() {
161
+ const { index } = this;
162
+ const item = this.items[index];
163
+
164
+ if (!item) {
165
+ return;
166
+ }
167
+
168
+ const next = item.nextElementSibling;
169
+ const gutter = parseInt(window.getComputedStyle(next || item).marginLeft, 10);
170
+ const { offsetWidth } = item;
171
+ const outerWidth = offsetWidth + gutter;
150
172
 
151
173
  // Place the active item in the center of the screen
152
174
  setStyle(this.list, assign({
153
- width: outerWidth * this.length,
175
+ width: outerWidth * this.length - gutter,
154
176
  }, getTransforms({
155
- translateX: ((this.viewerData.width - width) / 2) - (outerWidth * i),
177
+ translateX: ((this.viewerData.width - offsetWidth) / 2) - outerWidth * index,
156
178
  })));
157
179
  },
158
180
 
@@ -206,6 +228,7 @@ export default {
206
228
  y: top,
207
229
  width,
208
230
  height,
231
+ oldRatio: 1,
209
232
  ratio: width / naturalWidth,
210
233
  aspectRatio,
211
234
  naturalWidth,
package/types/index.d.ts CHANGED
@@ -88,7 +88,7 @@ declare namespace Viewer {
88
88
  className?: string;
89
89
  container?: string | HTMLElement;
90
90
  filter?: Function;
91
- fullscreen?: boolean;
91
+ fullscreen?: boolean | FullscreenOptions;
92
92
  focus?: boolean;
93
93
  hidden?(event: CustomEvent): void;
94
94
  hide?(event: CustomEvent): void;
@@ -147,7 +147,7 @@ declare class Viewer {
147
147
  move(offsetX: number, offsetY?: number): Viewer;
148
148
  moveTo(x: number, y?: number): Viewer;
149
149
  next(loop?: boolean): Viewer;
150
- play(fullscreen?: boolean): Viewer;
150
+ play(fullscreen?: boolean | FullscreenOptions): Viewer;
151
151
  prev(loop?: boolean): Viewer;
152
152
  reset(): Viewer;
153
153
  rotate(degree: number): Viewer;
package/CHANGELOG.md DELETED
@@ -1,255 +0,0 @@
1
- # Changelog
2
-
3
- ## 1.9.2 (May 29, 2021)
4
-
5
- - Avoid conflicts with other modals (#474).
6
- - Allow `ToolbarOption` to be undefined (#473).
7
-
8
- ## 1.9.1 (May 22, 2021)
9
-
10
- - Fix the missing declaration for the `focus` option (#470).
11
-
12
- ## 1.9.0 (Dec 6, 2020)
13
-
14
- - Add 6 new events: `move`, `moved`, `rotate`, `rotated`, `scale`, and `scaled`.
15
- - Add an example for limiting the moving range with the help of the `move` event.
16
-
17
- ## 1.8.0 (Nov 8, 2020)
18
-
19
- - Add a new option: `focus` .
20
- - Add ARIA attributes for better accessibility.
21
- - Add the `Tab` and `Enter` keys to the keyboard support.
22
- - Check if the `pointer` object is defined or not for better compatibility (#421).
23
-
24
- ## 1.7.1 (Sep 29, 2020)
25
-
26
- - Fix an issue in the `types/index.d.ts` file (#414).
27
-
28
- ## 1.7.0 (Sep 26, 2020)
29
-
30
- - Add 2 new events: `play` and `stop` (#411).
31
- - Let the `viewed`, `zoomed`, and `hidden` events not be canceled.
32
- - Improve the TypeScript declarations in the `types/index.d.ts` file.
33
-
34
- ## 1.6.2 (Aug 30, 2020)
35
-
36
- - Improve the `hide` method for some edge cases (#407).
37
- - Improve the wheel zoom behavior (#396).
38
- - Fix wrong usage about `this` in ES6+ (#395).
39
-
40
- ## 1.6.1 (Jun 14, 2020)
41
-
42
- - Improve image filtering.
43
-
44
- ## 1.6.0 (Jun 6, 2020)
45
-
46
- - Add a new options: `inheritedAttributes`.
47
- - Remove unnecessary `padding-right: 0px` from the `body` element when close the viewer modal (#394).
48
- - Reset the `padding-right` of the `body` element when resizing (#379).
49
- - Improve the `hide` method for unexpected calling (#367).
50
- - Ignore images without the `src` attribute (#326).
51
-
52
- ## 1.5.0 (Nov 23, 2019)
53
-
54
- - Force reflow element in a new way to avoid side-effect (#343).
55
- - Add a new option: `slideOnTouch` (#340).
56
- - Detect if the queried image is existing when updating the image list (#333).
57
-
58
- ## 1.4.0 (Oct 26, 2019)
59
-
60
- - Add two new options: `zoomOnTouch` and `zoomOnWheel` (#329).
61
-
62
- ## 1.3.7 (Oct 2, 2019)
63
-
64
- - Improve event type determining for iOS 13+ (#321).
65
- - Ignore invalid `element` parameter on the class utility functions (#317).
66
- - Do nothing if the `index` value is invalid when calling the `view` method (#312).
67
-
68
- ## 1.3.6 (Jul 4, 2019)
69
-
70
- - Avoid escaping URLs (#298, #301).
71
- - Avoid using the `innerHTML` property for security (#269).
72
-
73
- ## 1.3.5 (Jun 29, 2019)
74
-
75
- - Improve the escaping function to avoid escaping HTML entities repeatedly.
76
-
77
- ## 1.3.4 (Jun 1, 2019)
78
-
79
- - Decode image name when it comes from URL (#282).
80
- - Fix the missing fade-out transition when hiding the viewer (#275).
81
- - Escape all strings that use in HTML for better security (#269).
82
-
83
- ## 1.3.3 (Apr 6, 2019)
84
-
85
- - Fix unexpected modal exiting behavior when the mouse is pressed (#255).
86
- - Abort image downloading when cancel viewing for better performance.
87
-
88
- ## 1.3.2 (Jan 24, 2019)
89
-
90
- - Fix `Document not active` error when calling the `exit` method.
91
- - Improve wheel event listening for better performance (#102).
92
-
93
- ## 1.3.1 (Dec 9, 2018)
94
-
95
- - Ignore pointer events when not the primary button was pressed (#221).
96
- - Emulate click (single tap) and double click (double tap) in touch devices to support backdrop and image zooming (#210).
97
-
98
- ## 1.3.0 (Oct 25, 2018)
99
-
100
- - Fix wrong click action when target image is ignored by the `filter` option (#211)
101
- - Add a new option: `className` (#209).
102
-
103
- ## 1.2.1 (Oct 20, 2018)
104
-
105
- - Improve viewer instance storage to avoid side-effect.
106
- - Fix parameter error of `Object.assign` in iOS devices.
107
-
108
- ## 1.2.0 (Jul 15, 2018)
109
-
110
- - Enhance the `title` option to support to customize title content (#54, #185).
111
- - Add 2 new options: `toggleOnDblclick` (#173) and `initialViewIndex` (#183).
112
-
113
- ## 1.1.0 (May 27, 2018)
114
-
115
- - Make the touch zooming smoother (#162).
116
- - Add 2 new events: `zoom` and `zoomed` (#144).
117
-
118
- ## 1.0.1 (May 20, 2018)
119
-
120
- - Add a namespace to data attribute names (from `data-*` to `data-viewer-*`) to avoid side-effect.
121
- - Make sure the image data is a non-null object to avoid unexpected errors.
122
- - Fix broken zoom feature in iOS browsers (#167).
123
-
124
- ## 1.0.0 (Apr 1, 2018)
125
-
126
- - Add in browser checking to support import in Node.js.
127
- - Cancel update when there are no images when calling the `update` method.
128
-
129
- ## 1.0.0-rc.1 (Mar 13, 2018)
130
-
131
- - Fix the wrong image switching behavior in iOS browsers.
132
- - Fix a `TypeError` in strict mode (#149).
133
- - Fix type definitions issue of the `show` and `hide` methods.
134
-
135
- ## 1.0.0-rc (Mar 10, 2018)
136
-
137
- - Add a new option: `loading`.
138
- - Add type definitions file for TypeScript.
139
- - Enhance the `show`, `hide`, and `play` methods.
140
- - Change the default value of the `loop` option from `false` to `true`.
141
-
142
- ## 1.0.0-beta.2 (Feb 13, 2018)
143
-
144
- - Add a new option: `container`.
145
- - Recover the missing default value of the `interval` option (#133).
146
-
147
- ## 1.0.0-beta.1 (Dec 23, 2017)
148
-
149
- - Add a new option: `backdrop`.
150
-
151
- ## 1.0.0-beta (Dec 12, 2017)
152
-
153
- - Add `style` field to `package.json`.
154
- - Fall back to `document.documentElement` if `document.body` is not existing (#120).
155
- - Fix the issue of NodeList deconstructing (#118).
156
-
157
- ## 0.10.0 (Nov 5, 2017)
158
-
159
- - Add a new option: `loop`.
160
- - Enhance toolbar customization.
161
-
162
- ## 0.9.0 (Nov 4, 2017)
163
-
164
- - Add a new option: `filter`.
165
- - Support to customize the layout of the toolbar (#79).
166
- - Enhance the `prev` and `next` methods (#47).
167
- - Disallow to show again if it had shown.
168
-
169
- ## 0.8.0 (Oct 8, 2017)
170
-
171
- - Refactor - separate constants, simplify utilities, and so on.
172
- - Stop play after exited fullscreen.
173
- - Improve JSDoc.
174
-
175
- ## 0.7.2 (Aug 19, 2017)
176
-
177
- - Fixed multiple active items in the navbar (#75).
178
- - Ignore the mouse down event when the viewer is hiding (#70).
179
-
180
- ## 0.7.1 (May 14, 2017)
181
-
182
- - Support to use the viewer in a modal (#39).
183
-
184
- ## 0.7.0 (Apr 30, 2017)
185
-
186
- - Changed the `main` field value from `dist/viewer.js` (UMD) to `dist/viewer.common.js` (CommonJS).
187
- - Added `module` and `browser` fields to `package.json`.
188
- - Fixed an issue of touch zoom.
189
-
190
- ## 0.6.2 (Mar 4, 2017)
191
-
192
- - Fixed the issue of touch and move problem (#63).
193
-
194
- ## 0.6.1 (Feb 18, 2017)
195
-
196
- - Prevented the default behavior of drag action (#63).
197
-
198
- ## 0.6.0 (Jan 24, 2017)
199
-
200
- - Ported JavaScript code to ECMAScript 6.
201
- - Ported CSS code to CSSNext.
202
-
203
- ## 0.5.1 (Jan 2, 2017)
204
-
205
- - Improve event handler for Pointer Events.
206
-
207
- ## 0.5.0 (July 22, 2016)
208
-
209
- - Improve modal opening and closing.
210
- - Remove the `build` event.
211
- - Rename `built` event to `ready`.
212
- - Fixed a bug of `data-*` attributes setting and getting (#33).
213
-
214
- ## 0.4.0 (Mar 20, 2016)
215
-
216
- - Added some properties to `event.detail` of the "view" and "viewed" events.
217
-
218
- ## 0.3.3 (Mar 19, 2016)
219
-
220
- - Fix the issue of hiding the wrong element in the "view" method (#19).
221
-
222
- ## 0.3.2 (Mar 11, 2016)
223
-
224
- - Fix the error of the parameters on the `url` option when it is a function.
225
-
226
- ## 0.3.1 (Feb 2, 2016)
227
-
228
- - Added tests.
229
- - Ignored the invalid class name.
230
- - Re-render image only when viewed.
231
-
232
- ## 0.3.0 (Jan 21, 2016)
233
-
234
- - Add more available values to the "title", "toolbar" and "navbar" options.
235
- - Support to toggle the visibility of title, toolbar, and navbar between different screen widths.
236
- - Exit fullscreen when stop playing.
237
- - Fixed title not generated bug.
238
-
239
- ## 0.2.0 (Jan 1, 2016)
240
-
241
- - Added "update" method for update image dynamically.
242
- - Hides title and toolbar on small screen (width < 768px).
243
-
244
- ## 0.1.1 (Dec 28, 2015)
245
-
246
- - Supports to zoom from event triggering point.
247
- - Optimized "toggle" method.
248
- - Fixed a bug about the index of the viewing image.
249
-
250
- ## 0.1.0 (Dec 24, 2015)
251
-
252
- - Supports 2 modes: "modal" (default), "inline"
253
- - Supports 30 options: "inline", "button", "navbar", "title", "toolbar", "tooltip", "movable", "zoomable", "rotatable", "scalable", "transition", "fullscreen", "keyboard", "interval", "minWidth", "minHeight", "zoomRatio", "minZoomRatio", "maxZoomRatio", "zIndex", "zIndexInline", "url", "build", "built", "show", "shown", "hide", "hidden", "view", "viewed"
254
- - Supports 22 methods: "show", "hide", "view", "prev", "next", "move", "moveTo", "zoom", "zoomTo", "rotate", "rotateTo", "scale", "scaleX", "scaleY", "play", "stop", "full", "exit", "tooltip", "toggle", "reset", "destroy"
255
- - Supports 8 events: "build", "built", "show", "shown", "hide", "hidden", "view", "viewed"