viewerjs 1.10.5 → 1.11.1

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/dist/viewer.js CHANGED
@@ -1,11 +1,11 @@
1
1
  /*!
2
- * Viewer.js v1.10.5
2
+ * Viewer.js v1.11.1
3
3
  * https://fengyuanchen.github.io/viewerjs
4
4
  *
5
5
  * Copyright 2015-present Chen Fengyuan
6
6
  * Released under the MIT license
7
7
  *
8
- * Date: 2022-04-05T08:21:02.491Z
8
+ * Date: 2022-11-06T05:18:19.939Z
9
9
  */
10
10
 
11
11
  (function (global, factory) {
@@ -16,17 +16,14 @@
16
16
 
17
17
  function ownKeys(object, enumerableOnly) {
18
18
  var keys = Object.keys(object);
19
-
20
19
  if (Object.getOwnPropertySymbols) {
21
20
  var symbols = Object.getOwnPropertySymbols(object);
22
21
  enumerableOnly && (symbols = symbols.filter(function (sym) {
23
22
  return Object.getOwnPropertyDescriptor(object, sym).enumerable;
24
23
  })), keys.push.apply(keys, symbols);
25
24
  }
26
-
27
25
  return keys;
28
26
  }
29
-
30
27
  function _objectSpread2(target) {
31
28
  for (var i = 1; i < arguments.length; i++) {
32
29
  var source = null != arguments[i] ? arguments[i] : {};
@@ -36,10 +33,8 @@
36
33
  Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
37
34
  });
38
35
  }
39
-
40
36
  return target;
41
37
  }
42
-
43
38
  function _typeof(obj) {
44
39
  "@babel/helpers - typeof";
45
40
 
@@ -49,13 +44,11 @@
49
44
  return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
50
45
  }, _typeof(obj);
51
46
  }
52
-
53
47
  function _classCallCheck(instance, Constructor) {
54
48
  if (!(instance instanceof Constructor)) {
55
49
  throw new TypeError("Cannot call a class as a function");
56
50
  }
57
51
  }
58
-
59
52
  function _defineProperties(target, props) {
60
53
  for (var i = 0; i < props.length; i++) {
61
54
  var descriptor = props[i];
@@ -65,7 +58,6 @@
65
58
  Object.defineProperty(target, descriptor.key, descriptor);
66
59
  }
67
60
  }
68
-
69
61
  function _createClass(Constructor, protoProps, staticProps) {
70
62
  if (protoProps) _defineProperties(Constructor.prototype, protoProps);
71
63
  if (staticProps) _defineProperties(Constructor, staticProps);
@@ -74,7 +66,6 @@
74
66
  });
75
67
  return Constructor;
76
68
  }
77
-
78
69
  function _defineProperty(obj, key, value) {
79
70
  if (key in obj) {
80
71
  Object.defineProperty(obj, key, {
@@ -86,7 +77,6 @@
86
77
  } else {
87
78
  obj[key] = value;
88
79
  }
89
-
90
80
  return obj;
91
81
  }
92
82
 
@@ -97,213 +87,183 @@
97
87
  * @type {boolean}
98
88
  */
99
89
  backdrop: true,
100
-
101
90
  /**
102
91
  * Show the button on the top-right of the viewer.
103
92
  * @type {boolean}
104
93
  */
105
94
  button: true,
106
-
107
95
  /**
108
96
  * Show the navbar.
109
97
  * @type {boolean | number}
110
98
  */
111
99
  navbar: true,
112
-
113
100
  /**
114
101
  * Specify the visibility and the content of the title.
115
102
  * @type {boolean | number | Function | Array}
116
103
  */
117
104
  title: true,
118
-
119
105
  /**
120
106
  * Show the toolbar.
121
107
  * @type {boolean | number | Object}
122
108
  */
123
109
  toolbar: true,
124
-
125
110
  /**
126
111
  * Custom class name(s) to add to the viewer's root element.
127
112
  * @type {string}
128
113
  */
129
114
  className: '',
130
-
131
115
  /**
132
116
  * Define where to put the viewer in modal mode.
133
117
  * @type {string | Element}
134
118
  */
135
119
  container: 'body',
136
-
137
120
  /**
138
121
  * Filter the images for viewing. Return true if the image is viewable.
139
122
  * @type {Function}
140
123
  */
141
124
  filter: null,
142
-
143
125
  /**
144
126
  * Enable to request fullscreen when play.
145
127
  * {@link https://developer.mozilla.org/en-US/docs/Web/API/FullscreenOptions}
146
128
  * @type {boolean|FullscreenOptions}
147
129
  */
148
130
  fullscreen: true,
149
-
150
131
  /**
151
132
  * Define the extra attributes to inherit from the original image.
152
133
  * @type {Array}
153
134
  */
154
135
  inheritedAttributes: ['crossOrigin', 'decoding', 'isMap', 'loading', 'referrerPolicy', 'sizes', 'srcset', 'useMap'],
155
-
156
136
  /**
157
- * Define the initial index of image for viewing.
137
+ * Define the initial coverage of the viewing image.
138
+ * @type {number}
139
+ */
140
+ initialCoverage: 0.9,
141
+ /**
142
+ * Define the initial index of the image for viewing.
158
143
  * @type {number}
159
144
  */
160
145
  initialViewIndex: 0,
161
-
162
146
  /**
163
147
  * Enable inline mode.
164
148
  * @type {boolean}
165
149
  */
166
150
  inline: false,
167
-
168
151
  /**
169
152
  * The amount of time to delay between automatically cycling an image when playing.
170
153
  * @type {number}
171
154
  */
172
155
  interval: 5000,
173
-
174
156
  /**
175
157
  * Enable keyboard support.
176
158
  * @type {boolean}
177
159
  */
178
160
  keyboard: true,
179
-
180
161
  /**
181
162
  * Focus the viewer when initialized.
182
163
  * @type {boolean}
183
164
  */
184
165
  focus: true,
185
-
186
166
  /**
187
167
  * Indicate if show a loading spinner when load image or not.
188
168
  * @type {boolean}
189
169
  */
190
170
  loading: true,
191
-
192
171
  /**
193
172
  * Indicate if enable loop viewing or not.
194
173
  * @type {boolean}
195
174
  */
196
175
  loop: true,
197
-
198
176
  /**
199
177
  * Min width of the viewer in inline mode.
200
178
  * @type {number}
201
179
  */
202
180
  minWidth: 200,
203
-
204
181
  /**
205
182
  * Min height of the viewer in inline mode.
206
183
  * @type {number}
207
184
  */
208
185
  minHeight: 100,
209
-
210
186
  /**
211
187
  * Enable to move the image.
212
188
  * @type {boolean}
213
189
  */
214
190
  movable: true,
215
-
216
191
  /**
217
192
  * Enable to rotate the image.
218
193
  * @type {boolean}
219
194
  */
220
195
  rotatable: true,
221
-
222
196
  /**
223
197
  * Enable to scale the image.
224
198
  * @type {boolean}
225
199
  */
226
200
  scalable: true,
227
-
228
201
  /**
229
202
  * Enable to zoom the image.
230
203
  * @type {boolean}
231
204
  */
232
205
  zoomable: true,
233
-
234
206
  /**
235
207
  * Enable to zoom the current image by dragging on the touch screen.
236
208
  * @type {boolean}
237
209
  */
238
210
  zoomOnTouch: true,
239
-
240
211
  /**
241
212
  * Enable to zoom the image by wheeling mouse.
242
213
  * @type {boolean}
243
214
  */
244
215
  zoomOnWheel: true,
245
-
246
216
  /**
247
217
  * Enable to slide to the next or previous image by swiping on the touch screen.
248
218
  * @type {boolean}
249
219
  */
250
220
  slideOnTouch: true,
251
-
252
221
  /**
253
222
  * Indicate if toggle the image size between its natural size
254
223
  * and initial size when double click on the image or not.
255
224
  * @type {boolean}
256
225
  */
257
226
  toggleOnDblclick: true,
258
-
259
227
  /**
260
228
  * Show the tooltip with image ratio (percentage) when zoom in or zoom out.
261
229
  * @type {boolean}
262
230
  */
263
231
  tooltip: true,
264
-
265
232
  /**
266
233
  * Enable CSS3 Transition for some special elements.
267
234
  * @type {boolean}
268
235
  */
269
236
  transition: true,
270
-
271
237
  /**
272
238
  * Define the CSS `z-index` value of viewer in modal mode.
273
239
  * @type {number}
274
240
  */
275
241
  zIndex: 2015,
276
-
277
242
  /**
278
243
  * Define the CSS `z-index` value of viewer in inline mode.
279
244
  * @type {number}
280
245
  */
281
246
  zIndexInline: 0,
282
-
283
247
  /**
284
248
  * Define the ratio when zoom the image by wheeling mouse.
285
249
  * @type {number}
286
250
  */
287
251
  zoomRatio: 0.1,
288
-
289
252
  /**
290
253
  * Define the min ratio of the image when zoom out.
291
254
  * @type {number}
292
255
  */
293
256
  minZoomRatio: 0.01,
294
-
295
257
  /**
296
258
  * Define the max ratio of the image when zoom in.
297
259
  * @type {number}
298
260
  */
299
261
  maxZoomRatio: 100,
300
-
301
262
  /**
302
263
  * Define where to get the original image URL for viewing.
303
264
  * @type {string | Function}
304
265
  */
305
266
  url: 'src',
306
-
307
267
  /**
308
268
  * Event shortcuts.
309
269
  * @type {Function}
@@ -333,12 +293,14 @@
333
293
  var WINDOW = IS_BROWSER ? window : {};
334
294
  var IS_TOUCH_DEVICE = IS_BROWSER && WINDOW.document.documentElement ? 'ontouchstart' in WINDOW.document.documentElement : false;
335
295
  var HAS_POINTER_EVENT = IS_BROWSER ? 'PointerEvent' in WINDOW : false;
336
- var NAMESPACE = 'viewer'; // Actions
296
+ var NAMESPACE = 'viewer';
337
297
 
298
+ // Actions
338
299
  var ACTION_MOVE = 'move';
339
300
  var ACTION_SWITCH = 'switch';
340
- var ACTION_ZOOM = 'zoom'; // Classes
301
+ var ACTION_ZOOM = 'zoom';
341
302
 
303
+ // Classes
342
304
  var CLASS_ACTIVE = "".concat(NAMESPACE, "-active");
343
305
  var CLASS_CLOSE = "".concat(NAMESPACE, "-close");
344
306
  var CLASS_FADE = "".concat(NAMESPACE, "-fade");
@@ -355,8 +317,9 @@
355
317
  var CLASS_MOVE = "".concat(NAMESPACE, "-move");
356
318
  var CLASS_OPEN = "".concat(NAMESPACE, "-open");
357
319
  var CLASS_SHOW = "".concat(NAMESPACE, "-show");
358
- var CLASS_TRANSITION = "".concat(NAMESPACE, "-transition"); // Native events
320
+ var CLASS_TRANSITION = "".concat(NAMESPACE, "-transition");
359
321
 
322
+ // Native events
360
323
  var EVENT_CLICK = 'click';
361
324
  var EVENT_DBLCLICK = 'dblclick';
362
325
  var EVENT_DRAG_START = 'dragstart';
@@ -372,8 +335,9 @@
372
335
  var EVENT_POINTER_UP = HAS_POINTER_EVENT ? 'pointerup pointercancel' : EVENT_TOUCH_END;
373
336
  var EVENT_RESIZE = 'resize';
374
337
  var EVENT_TRANSITION_END = 'transitionend';
375
- var EVENT_WHEEL = 'wheel'; // Custom events
338
+ var EVENT_WHEEL = 'wheel';
376
339
 
340
+ // Custom events
377
341
  var EVENT_READY = 'ready';
378
342
  var EVENT_SHOW = 'show';
379
343
  var EVENT_SHOWN = 'shown';
@@ -390,12 +354,15 @@
390
354
  var EVENT_ZOOM = 'zoom';
391
355
  var EVENT_ZOOMED = 'zoomed';
392
356
  var EVENT_PLAY = 'play';
393
- var EVENT_STOP = 'stop'; // Data keys
357
+ var EVENT_STOP = 'stop';
394
358
 
395
- var DATA_ACTION = "".concat(NAMESPACE, "Action"); // RegExps
359
+ // Data keys
360
+ var DATA_ACTION = "".concat(NAMESPACE, "Action");
396
361
 
397
- var REGEXP_SPACES = /\s\s*/; // Misc
362
+ // RegExps
363
+ var REGEXP_SPACES = /\s\s*/;
398
364
 
365
+ // Misc
399
366
  var BUTTONS = ['zoom-in', 'zoom-out', 'one-to-one', 'reset', 'prev', 'play', 'next', 'rotate-left', 'rotate-right', 'flip-horizontal', 'flip-vertical'];
400
367
 
401
368
  /**
@@ -403,54 +370,52 @@
403
370
  * @param {*} value - The value to check.
404
371
  * @returns {boolean} Returns `true` if the given value is a string, else `false`.
405
372
  */
406
-
407
373
  function isString(value) {
408
374
  return typeof value === 'string';
409
375
  }
376
+
410
377
  /**
411
378
  * Check if the given value is not a number.
412
379
  */
413
-
414
380
  var isNaN = Number.isNaN || WINDOW.isNaN;
381
+
415
382
  /**
416
383
  * Check if the given value is a number.
417
384
  * @param {*} value - The value to check.
418
385
  * @returns {boolean} Returns `true` if the given value is a number, else `false`.
419
386
  */
420
-
421
387
  function isNumber(value) {
422
388
  return typeof value === 'number' && !isNaN(value);
423
389
  }
390
+
424
391
  /**
425
392
  * Check if the given value is undefined.
426
393
  * @param {*} value - The value to check.
427
394
  * @returns {boolean} Returns `true` if the given value is undefined, else `false`.
428
395
  */
429
-
430
396
  function isUndefined(value) {
431
397
  return typeof value === 'undefined';
432
398
  }
399
+
433
400
  /**
434
401
  * Check if the given value is an object.
435
402
  * @param {*} value - The value to check.
436
403
  * @returns {boolean} Returns `true` if the given value is an object, else `false`.
437
404
  */
438
-
439
405
  function isObject(value) {
440
406
  return _typeof(value) === 'object' && value !== null;
441
407
  }
442
408
  var hasOwnProperty = Object.prototype.hasOwnProperty;
409
+
443
410
  /**
444
411
  * Check if the given value is a plain object.
445
412
  * @param {*} value - The value to check.
446
413
  * @returns {boolean} Returns `true` if the given value is a plain object, else `false`.
447
414
  */
448
-
449
415
  function isPlainObject(value) {
450
416
  if (!isObject(value)) {
451
417
  return false;
452
418
  }
453
-
454
419
  try {
455
420
  var _constructor = value.constructor;
456
421
  var prototype = _constructor.prototype;
@@ -459,30 +424,27 @@
459
424
  return false;
460
425
  }
461
426
  }
427
+
462
428
  /**
463
429
  * Check if the given value is a function.
464
430
  * @param {*} value - The value to check.
465
431
  * @returns {boolean} Returns `true` if the given value is a function, else `false`.
466
432
  */
467
-
468
433
  function isFunction(value) {
469
434
  return typeof value === 'function';
470
435
  }
436
+
471
437
  /**
472
438
  * Iterate the given data.
473
439
  * @param {*} data - The data to iterate.
474
440
  * @param {Function} callback - The process function for each element.
475
441
  * @returns {*} The original data.
476
442
  */
477
-
478
443
  function forEach(data, callback) {
479
444
  if (data && isFunction(callback)) {
480
- if (Array.isArray(data) || isNumber(data.length)
481
- /* array-like */
482
- ) {
445
+ if (Array.isArray(data) || isNumber(data.length) /* array-like */) {
483
446
  var length = data.length;
484
447
  var i;
485
-
486
448
  for (i = 0; i < length; i += 1) {
487
449
  if (callback.call(data, data[i], i, data) === false) {
488
450
  break;
@@ -494,21 +456,19 @@
494
456
  });
495
457
  }
496
458
  }
497
-
498
459
  return data;
499
460
  }
461
+
500
462
  /**
501
463
  * Extend the given object.
502
464
  * @param {*} obj - The object to be extended.
503
465
  * @param {*} args - The rest objects which will be merged to the first object.
504
466
  * @returns {Object} The extended object.
505
467
  */
506
-
507
468
  var assign = Object.assign || function assign(obj) {
508
469
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
509
470
  args[_key - 1] = arguments[_key];
510
471
  }
511
-
512
472
  if (isObject(obj) && args.length > 0) {
513
473
  args.forEach(function (arg) {
514
474
  if (isObject(arg)) {
@@ -518,127 +478,116 @@
518
478
  }
519
479
  });
520
480
  }
521
-
522
481
  return obj;
523
482
  };
524
483
  var REGEXP_SUFFIX = /^(?:width|height|left|top|marginLeft|marginTop)$/;
484
+
525
485
  /**
526
486
  * Apply styles to the given element.
527
487
  * @param {Element} element - The target element.
528
488
  * @param {Object} styles - The styles for applying.
529
489
  */
530
-
531
490
  function setStyle(element, styles) {
532
491
  var style = element.style;
533
492
  forEach(styles, function (value, property) {
534
493
  if (REGEXP_SUFFIX.test(property) && isNumber(value)) {
535
494
  value += 'px';
536
495
  }
537
-
538
496
  style[property] = value;
539
497
  });
540
498
  }
499
+
541
500
  /**
542
501
  * Escape a string for using in HTML.
543
502
  * @param {String} value - The string to escape.
544
503
  * @returns {String} Returns the escaped string.
545
504
  */
546
-
547
505
  function escapeHTMLEntities(value) {
548
506
  return isString(value) ? value.replace(/&(?!amp;|quot;|#39;|lt;|gt;)/g, '&amp;').replace(/"/g, '&quot;').replace(/'/g, '&#39;').replace(/</g, '&lt;').replace(/>/g, '&gt;') : value;
549
507
  }
508
+
550
509
  /**
551
510
  * Check if the given element has a special class.
552
511
  * @param {Element} element - The element to check.
553
512
  * @param {string} value - The class to search.
554
513
  * @returns {boolean} Returns `true` if the special class was found.
555
514
  */
556
-
557
515
  function hasClass(element, value) {
558
516
  if (!element || !value) {
559
517
  return false;
560
518
  }
561
-
562
519
  return element.classList ? element.classList.contains(value) : element.className.indexOf(value) > -1;
563
520
  }
521
+
564
522
  /**
565
523
  * Add classes to the given element.
566
524
  * @param {Element} element - The target element.
567
525
  * @param {string} value - The classes to be added.
568
526
  */
569
-
570
527
  function addClass(element, value) {
571
528
  if (!element || !value) {
572
529
  return;
573
530
  }
574
-
575
531
  if (isNumber(element.length)) {
576
532
  forEach(element, function (elem) {
577
533
  addClass(elem, value);
578
534
  });
579
535
  return;
580
536
  }
581
-
582
537
  if (element.classList) {
583
538
  element.classList.add(value);
584
539
  return;
585
540
  }
586
-
587
541
  var className = element.className.trim();
588
-
589
542
  if (!className) {
590
543
  element.className = value;
591
544
  } else if (className.indexOf(value) < 0) {
592
545
  element.className = "".concat(className, " ").concat(value);
593
546
  }
594
547
  }
548
+
595
549
  /**
596
550
  * Remove classes from the given element.
597
551
  * @param {Element} element - The target element.
598
552
  * @param {string} value - The classes to be removed.
599
553
  */
600
-
601
554
  function removeClass(element, value) {
602
555
  if (!element || !value) {
603
556
  return;
604
557
  }
605
-
606
558
  if (isNumber(element.length)) {
607
559
  forEach(element, function (elem) {
608
560
  removeClass(elem, value);
609
561
  });
610
562
  return;
611
563
  }
612
-
613
564
  if (element.classList) {
614
565
  element.classList.remove(value);
615
566
  return;
616
567
  }
617
-
618
568
  if (element.className.indexOf(value) >= 0) {
619
569
  element.className = element.className.replace(value, '');
620
570
  }
621
571
  }
572
+
622
573
  /**
623
574
  * Add or remove classes from the given element.
624
575
  * @param {Element} element - The target element.
625
576
  * @param {string} value - The classes to be toggled.
626
577
  * @param {boolean} added - Add only.
627
578
  */
628
-
629
579
  function toggleClass(element, value, added) {
630
580
  if (!value) {
631
581
  return;
632
582
  }
633
-
634
583
  if (isNumber(element.length)) {
635
584
  forEach(element, function (elem) {
636
585
  toggleClass(elem, value, added);
637
586
  });
638
587
  return;
639
- } // IE10-11 doesn't support the second parameter of `classList.toggle`
640
-
588
+ }
641
589
 
590
+ // IE10-11 doesn't support the second parameter of `classList.toggle`
642
591
  if (added) {
643
592
  addClass(element, value);
644
593
  } else {
@@ -646,40 +595,38 @@
646
595
  }
647
596
  }
648
597
  var REGEXP_HYPHENATE = /([a-z\d])([A-Z])/g;
598
+
649
599
  /**
650
600
  * Transform the given string from camelCase to kebab-case
651
601
  * @param {string} value - The value to transform.
652
602
  * @returns {string} The transformed value.
653
603
  */
654
-
655
604
  function hyphenate(value) {
656
605
  return value.replace(REGEXP_HYPHENATE, '$1-$2').toLowerCase();
657
606
  }
607
+
658
608
  /**
659
609
  * Get data from the given element.
660
610
  * @param {Element} element - The target element.
661
611
  * @param {string} name - The data key to get.
662
612
  * @returns {string} The data value.
663
613
  */
664
-
665
614
  function getData(element, name) {
666
615
  if (isObject(element[name])) {
667
616
  return element[name];
668
617
  }
669
-
670
618
  if (element.dataset) {
671
619
  return element.dataset[name];
672
620
  }
673
-
674
621
  return element.getAttribute("data-".concat(hyphenate(name)));
675
622
  }
623
+
676
624
  /**
677
625
  * Set data to the given element.
678
626
  * @param {Element} element - The target element.
679
627
  * @param {string} name - The data key to set.
680
628
  * @param {string} data - The data value.
681
629
  */
682
-
683
630
  function setData(element, name, data) {
684
631
  if (isObject(data)) {
685
632
  element[name] = data;
@@ -689,21 +636,16 @@
689
636
  element.setAttribute("data-".concat(hyphenate(name)), data);
690
637
  }
691
638
  }
692
-
693
639
  var onceSupported = function () {
694
640
  var supported = false;
695
-
696
641
  if (IS_BROWSER) {
697
642
  var once = false;
698
-
699
643
  var listener = function listener() {};
700
-
701
644
  var options = Object.defineProperty({}, 'once', {
702
645
  get: function get() {
703
646
  supported = true;
704
647
  return once;
705
648
  },
706
-
707
649
  /**
708
650
  * This setter can fix a `TypeError` in strict mode
709
651
  * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Getter_only}
@@ -716,9 +658,9 @@
716
658
  WINDOW.addEventListener('test', listener, options);
717
659
  WINDOW.removeEventListener('test', listener, options);
718
660
  }
719
-
720
661
  return supported;
721
662
  }();
663
+
722
664
  /**
723
665
  * Remove event listener from the target element.
724
666
  * @param {Element} element - The event target.
@@ -726,32 +668,27 @@
726
668
  * @param {Function} listener - The event listener.
727
669
  * @param {Object} options - The event options.
728
670
  */
729
-
730
-
731
671
  function removeListener(element, type, listener) {
732
672
  var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
733
673
  var handler = listener;
734
674
  type.trim().split(REGEXP_SPACES).forEach(function (event) {
735
675
  if (!onceSupported) {
736
676
  var listeners = element.listeners;
737
-
738
677
  if (listeners && listeners[event] && listeners[event][listener]) {
739
678
  handler = listeners[event][listener];
740
679
  delete listeners[event][listener];
741
-
742
680
  if (Object.keys(listeners[event]).length === 0) {
743
681
  delete listeners[event];
744
682
  }
745
-
746
683
  if (Object.keys(listeners).length === 0) {
747
684
  delete element.listeners;
748
685
  }
749
686
  }
750
687
  }
751
-
752
688
  element.removeEventListener(event, handler, options);
753
689
  });
754
690
  }
691
+
755
692
  /**
756
693
  * Add event listener to the target element.
757
694
  * @param {Element} element - The event target.
@@ -759,41 +696,34 @@
759
696
  * @param {Function} listener - The event listener.
760
697
  * @param {Object} options - The event options.
761
698
  */
762
-
763
699
  function addListener(element, type, listener) {
764
700
  var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
765
701
  var _handler = listener;
766
702
  type.trim().split(REGEXP_SPACES).forEach(function (event) {
767
703
  if (options.once && !onceSupported) {
768
704
  var _element$listeners = element.listeners,
769
- listeners = _element$listeners === void 0 ? {} : _element$listeners;
770
-
705
+ listeners = _element$listeners === void 0 ? {} : _element$listeners;
771
706
  _handler = function handler() {
772
707
  delete listeners[event][listener];
773
708
  element.removeEventListener(event, _handler, options);
774
-
775
709
  for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
776
710
  args[_key2] = arguments[_key2];
777
711
  }
778
-
779
712
  listener.apply(element, args);
780
713
  };
781
-
782
714
  if (!listeners[event]) {
783
715
  listeners[event] = {};
784
716
  }
785
-
786
717
  if (listeners[event][listener]) {
787
718
  element.removeEventListener(event, listeners[event][listener], options);
788
719
  }
789
-
790
720
  listeners[event][listener] = _handler;
791
721
  element.listeners = listeners;
792
722
  }
793
-
794
723
  element.addEventListener(event, _handler, options);
795
724
  });
796
725
  }
726
+
797
727
  /**
798
728
  * Dispatch event on the target element.
799
729
  * @param {Element} element - The event target.
@@ -802,10 +732,10 @@
802
732
  * @param {Object} options - The additional event options.
803
733
  * @returns {boolean} Indicate if the event is default prevented or not.
804
734
  */
805
-
806
735
  function dispatchEvent(element, type, data, options) {
807
- var event; // Event and CustomEvent on IE9-11 are global objects, not constructors
736
+ var event;
808
737
 
738
+ // Event and CustomEvent on IE9-11 are global objects, not constructors
809
739
  if (isFunction(Event) && isFunction(CustomEvent)) {
810
740
  event = new CustomEvent(type, _objectSpread2({
811
741
  bubbles: true,
@@ -816,15 +746,14 @@
816
746
  event = document.createEvent('CustomEvent');
817
747
  event.initCustomEvent(type, true, true, data);
818
748
  }
819
-
820
749
  return element.dispatchEvent(event);
821
750
  }
751
+
822
752
  /**
823
753
  * Get the offset base on the document.
824
754
  * @param {Element} element - The target element.
825
755
  * @returns {Object} The offset data.
826
756
  */
827
-
828
757
  function getOffset(element) {
829
758
  var box = element.getBoundingClientRect();
830
759
  return {
@@ -832,41 +761,36 @@
832
761
  top: box.top + (window.pageYOffset - document.documentElement.clientTop)
833
762
  };
834
763
  }
764
+
835
765
  /**
836
766
  * Get transforms base on the given object.
837
767
  * @param {Object} obj - The target object.
838
768
  * @returns {string} A string contains transform values.
839
769
  */
840
-
841
770
  function getTransforms(_ref) {
842
771
  var rotate = _ref.rotate,
843
- scaleX = _ref.scaleX,
844
- scaleY = _ref.scaleY,
845
- translateX = _ref.translateX,
846
- translateY = _ref.translateY;
772
+ scaleX = _ref.scaleX,
773
+ scaleY = _ref.scaleY,
774
+ translateX = _ref.translateX,
775
+ translateY = _ref.translateY;
847
776
  var values = [];
848
-
849
777
  if (isNumber(translateX) && translateX !== 0) {
850
778
  values.push("translateX(".concat(translateX, "px)"));
851
779
  }
852
-
853
780
  if (isNumber(translateY) && translateY !== 0) {
854
781
  values.push("translateY(".concat(translateY, "px)"));
855
- } // Rotate should come first before scale to match orientation transform
856
-
782
+ }
857
783
 
784
+ // Rotate should come first before scale to match orientation transform
858
785
  if (isNumber(rotate) && rotate !== 0) {
859
786
  values.push("rotate(".concat(rotate, "deg)"));
860
787
  }
861
-
862
788
  if (isNumber(scaleX) && scaleX !== 1) {
863
789
  values.push("scaleX(".concat(scaleX, ")"));
864
790
  }
865
-
866
791
  if (isNumber(scaleY) && scaleY !== 1) {
867
792
  values.push("scaleY(".concat(scaleY, ")"));
868
793
  }
869
-
870
794
  var transform = values.length ? values.join(' ') : 'none';
871
795
  return {
872
796
  WebkitTransform: transform,
@@ -874,6 +798,7 @@
874
798
  transform: transform
875
799
  };
876
800
  }
801
+
877
802
  /**
878
803
  * Get an image name from an image url.
879
804
  * @param {string} url - The target url.
@@ -882,11 +807,11 @@
882
807
  * getImageNameFromURL('https://domain.com/path/to/picture.jpg?size=1280×960')
883
808
  * @returns {string} A string contains the image name.
884
809
  */
885
-
886
810
  function getImageNameFromURL(url) {
887
811
  return isString(url) ? decodeURIComponent(url.replace(/^.*\//, '').replace(/[?&#].*$/, '')) : '';
888
812
  }
889
813
  var IS_SAFARI = WINDOW.navigator && /(Macintosh|iPhone|iPod|iPad).*AppleWebKit/i.test(WINDOW.navigator.userAgent);
814
+
890
815
  /**
891
816
  * Get an image's natural sizes.
892
817
  * @param {string} image - The target image.
@@ -894,72 +819,63 @@
894
819
  * @param {Function} callback - The callback function.
895
820
  * @returns {HTMLImageElement} The new image.
896
821
  */
897
-
898
822
  function getImageNaturalSizes(image, options, callback) {
899
- var newImage = document.createElement('img'); // Modern browsers (except Safari)
823
+ var newImage = document.createElement('img');
900
824
 
825
+ // Modern browsers (except Safari)
901
826
  if (image.naturalWidth && !IS_SAFARI) {
902
827
  callback(image.naturalWidth, image.naturalHeight);
903
828
  return newImage;
904
829
  }
905
-
906
830
  var body = document.body || document.documentElement;
907
-
908
831
  newImage.onload = function () {
909
832
  callback(newImage.width, newImage.height);
910
-
911
833
  if (!IS_SAFARI) {
912
834
  body.removeChild(newImage);
913
835
  }
914
836
  };
915
-
916
837
  forEach(options.inheritedAttributes, function (name) {
917
838
  var value = image.getAttribute(name);
918
-
919
839
  if (value !== null) {
920
840
  newImage.setAttribute(name, value);
921
841
  }
922
842
  });
923
- newImage.src = image.src; // iOS Safari will convert the image automatically
924
- // with its orientation once append it into DOM
843
+ newImage.src = image.src;
925
844
 
845
+ // iOS Safari will convert the image automatically
846
+ // with its orientation once append it into DOM
926
847
  if (!IS_SAFARI) {
927
848
  newImage.style.cssText = 'left:0;' + 'max-height:none!important;' + 'max-width:none!important;' + 'min-height:0!important;' + 'min-width:0!important;' + 'opacity:0;' + 'position:absolute;' + 'top:0;' + 'z-index:-1;';
928
849
  body.appendChild(newImage);
929
850
  }
930
-
931
851
  return newImage;
932
852
  }
853
+
933
854
  /**
934
855
  * Get the related class name of a responsive type number.
935
856
  * @param {string} type - The responsive type.
936
857
  * @returns {string} The related class name.
937
858
  */
938
-
939
859
  function getResponsiveClass(type) {
940
860
  switch (type) {
941
861
  case 2:
942
862
  return CLASS_HIDE_XS_DOWN;
943
-
944
863
  case 3:
945
864
  return CLASS_HIDE_SM_DOWN;
946
-
947
865
  case 4:
948
866
  return CLASS_HIDE_MD_DOWN;
949
-
950
867
  default:
951
868
  return '';
952
869
  }
953
870
  }
871
+
954
872
  /**
955
873
  * Get the max ratio of a group of pointers.
956
874
  * @param {string} pointers - The target pointers.
957
875
  * @returns {number} The result ratio.
958
876
  */
959
-
960
877
  function getMaxZoomRatio(pointers) {
961
878
  var pointers2 = _objectSpread2({}, pointers);
962
-
963
879
  var ratios = [];
964
880
  forEach(pointers, function (pointer, pointerId) {
965
881
  delete pointers2[pointerId];
@@ -979,16 +895,16 @@
979
895
  });
980
896
  return ratios[0];
981
897
  }
898
+
982
899
  /**
983
900
  * Get a pointer from an event object.
984
901
  * @param {Object} event - The target event object.
985
902
  * @param {boolean} endOnly - Indicates if only returns the end point coordinate or not.
986
903
  * @returns {Object} The result pointer contains start and/or end point coordinates.
987
904
  */
988
-
989
905
  function getPointer(_ref2, endOnly) {
990
906
  var pageX = _ref2.pageX,
991
- pageY = _ref2.pageY;
907
+ pageY = _ref2.pageY;
992
908
  var end = {
993
909
  endX: pageX,
994
910
  endY: pageY
@@ -999,19 +915,19 @@
999
915
  startY: pageY
1000
916
  }, end);
1001
917
  }
918
+
1002
919
  /**
1003
920
  * Get the center point coordinate of a group of pointers.
1004
921
  * @param {Object} pointers - The target pointers.
1005
922
  * @returns {Object} The center point coordinate.
1006
923
  */
1007
-
1008
924
  function getPointersCenter(pointers) {
1009
925
  var pageX = 0;
1010
926
  var pageY = 0;
1011
927
  var count = 0;
1012
928
  forEach(pointers, function (_ref3) {
1013
929
  var startX = _ref3.startX,
1014
- startY = _ref3.startY;
930
+ startY = _ref3.startY;
1015
931
  pageX += startX;
1016
932
  pageY += startY;
1017
933
  count += 1;
@@ -1047,9 +963,8 @@
1047
963
  },
1048
964
  initViewer: function initViewer() {
1049
965
  var options = this.options,
1050
- parent = this.parent;
966
+ parent = this.parent;
1051
967
  var viewerData;
1052
-
1053
968
  if (options.inline) {
1054
969
  viewerData = {
1055
970
  width: Math.max(parent.offsetWidth, options.minWidth),
@@ -1057,11 +972,9 @@
1057
972
  };
1058
973
  this.parentData = viewerData;
1059
974
  }
1060
-
1061
975
  if (this.fulled || !viewerData) {
1062
976
  viewerData = this.containerData;
1063
977
  }
1064
-
1065
978
  this.viewerData = assign({}, viewerData);
1066
979
  },
1067
980
  renderViewer: function renderViewer() {
@@ -1071,40 +984,37 @@
1071
984
  },
1072
985
  initList: function initList() {
1073
986
  var _this = this;
1074
-
1075
987
  var element = this.element,
1076
- options = this.options,
1077
- list = this.list;
1078
- var items = []; // initList may be called in this.update, so should keep idempotent
988
+ options = this.options,
989
+ list = this.list;
990
+ var items = [];
1079
991
 
992
+ // initList may be called in this.update, so should keep idempotent
1080
993
  list.innerHTML = '';
1081
994
  forEach(this.images, function (image, index) {
1082
995
  var src = image.src;
1083
996
  var alt = image.alt || getImageNameFromURL(src);
1084
-
1085
997
  var url = _this.getImageURL(image);
1086
-
1087
998
  if (src || url) {
1088
999
  var item = document.createElement('li');
1089
1000
  var img = document.createElement('img');
1090
1001
  forEach(options.inheritedAttributes, function (name) {
1091
1002
  var value = image.getAttribute(name);
1092
-
1093
1003
  if (value !== null) {
1094
1004
  img.setAttribute(name, value);
1095
1005
  }
1096
1006
  });
1097
- img.src = src || url;
1007
+ if (options.navbar) {
1008
+ img.src = src || url;
1009
+ }
1098
1010
  img.alt = alt;
1099
1011
  img.setAttribute('data-original-url', url || src);
1100
1012
  item.setAttribute('data-index', index);
1101
1013
  item.setAttribute('data-viewer-action', 'view');
1102
1014
  item.setAttribute('role', 'button');
1103
-
1104
1015
  if (options.keyboard) {
1105
1016
  item.setAttribute('tabindex', 0);
1106
1017
  }
1107
-
1108
1018
  item.appendChild(img);
1109
1019
  list.appendChild(item);
1110
1020
  items.push(item);
@@ -1116,25 +1026,20 @@
1116
1026
  var onLoad;
1117
1027
  var onError;
1118
1028
  setData(image, 'filled', true);
1119
-
1120
1029
  if (options.loading) {
1121
1030
  addClass(item, CLASS_LOADING);
1122
1031
  }
1123
-
1124
1032
  addListener(image, EVENT_LOAD, onLoad = function onLoad(event) {
1125
1033
  removeListener(image, EVENT_ERROR, onError);
1126
-
1127
1034
  if (options.loading) {
1128
1035
  removeClass(item, CLASS_LOADING);
1129
1036
  }
1130
-
1131
1037
  _this.loadImage(event);
1132
1038
  }, {
1133
1039
  once: true
1134
1040
  });
1135
1041
  addListener(image, EVENT_ERROR, onError = function onError() {
1136
1042
  removeListener(image, EVENT_LOAD, onLoad);
1137
-
1138
1043
  if (options.loading) {
1139
1044
  removeClass(item, CLASS_LOADING);
1140
1045
  }
@@ -1142,7 +1047,6 @@
1142
1047
  once: true
1143
1048
  });
1144
1049
  });
1145
-
1146
1050
  if (options.transition) {
1147
1051
  addListener(element, EVENT_VIEWED, function () {
1148
1052
  addClass(list, CLASS_TRANSITION);
@@ -1154,16 +1058,15 @@
1154
1058
  renderList: function renderList() {
1155
1059
  var index = this.index;
1156
1060
  var item = this.items[index];
1157
-
1158
1061
  if (!item) {
1159
1062
  return;
1160
1063
  }
1161
-
1162
1064
  var next = item.nextElementSibling;
1163
1065
  var gutter = parseInt(window.getComputedStyle(next || item).marginLeft, 10);
1164
1066
  var offsetWidth = item.offsetWidth;
1165
- var outerWidth = offsetWidth + gutter; // Place the active item in the center of the screen
1067
+ var outerWidth = offsetWidth + gutter;
1166
1068
 
1069
+ // Place the active item in the center of the screen
1167
1070
  setStyle(this.list, assign({
1168
1071
  width: outerWidth * this.length - gutter
1169
1072
  }, getTransforms({
@@ -1180,10 +1083,9 @@
1180
1083
  },
1181
1084
  initImage: function initImage(done) {
1182
1085
  var _this2 = this;
1183
-
1184
1086
  var options = this.options,
1185
- image = this.image,
1186
- viewerData = this.viewerData;
1087
+ image = this.image,
1088
+ viewerData = this.viewerData;
1187
1089
  var footerHeight = this.footer.offsetHeight;
1188
1090
  var viewerWidth = viewerData.width;
1189
1091
  var viewerHeight = Math.max(viewerData.height - footerHeight, footerHeight);
@@ -1196,18 +1098,18 @@
1196
1098
  };
1197
1099
  sizingImage = getImageNaturalSizes(image, options, function (naturalWidth, naturalHeight) {
1198
1100
  var aspectRatio = naturalWidth / naturalHeight;
1101
+ var initialCoverage = Math.max(0, Math.min(1, options.initialCoverage));
1199
1102
  var width = viewerWidth;
1200
1103
  var height = viewerHeight;
1201
1104
  _this2.imageInitializing = false;
1202
-
1203
1105
  if (viewerHeight * aspectRatio > viewerWidth) {
1204
1106
  height = viewerWidth / aspectRatio;
1205
1107
  } else {
1206
1108
  width = viewerHeight * aspectRatio;
1207
1109
  }
1208
-
1209
- width = Math.min(width * 0.9, naturalWidth);
1210
- height = Math.min(height * 0.9, naturalHeight);
1110
+ initialCoverage = isNumber(initialCoverage) ? initialCoverage : 0.9;
1111
+ width = Math.min(width * initialCoverage, naturalWidth);
1112
+ height = Math.min(height * initialCoverage, naturalHeight);
1211
1113
  var left = (viewerWidth - width) / 2;
1212
1114
  var top = (viewerHeight - height) / 2;
1213
1115
  var imageData = {
@@ -1224,22 +1126,18 @@
1224
1126
  naturalHeight: naturalHeight
1225
1127
  };
1226
1128
  var initialImageData = assign({}, imageData);
1227
-
1228
1129
  if (options.rotatable) {
1229
1130
  imageData.rotate = oldImageData.rotate || 0;
1230
1131
  initialImageData.rotate = 0;
1231
1132
  }
1232
-
1233
1133
  if (options.scalable) {
1234
1134
  imageData.scaleX = oldImageData.scaleX || 1;
1235
1135
  imageData.scaleY = oldImageData.scaleY || 1;
1236
1136
  initialImageData.scaleX = 1;
1237
1137
  initialImageData.scaleY = 1;
1238
1138
  }
1239
-
1240
1139
  _this2.imageData = imageData;
1241
1140
  _this2.initialImageData = initialImageData;
1242
-
1243
1141
  if (done) {
1244
1142
  done();
1245
1143
  }
@@ -1247,9 +1145,8 @@
1247
1145
  },
1248
1146
  renderImage: function renderImage(done) {
1249
1147
  var _this3 = this;
1250
-
1251
1148
  var image = this.image,
1252
- imageData = this.imageData;
1149
+ imageData = this.imageData;
1253
1150
  setStyle(image, assign({
1254
1151
  width: imageData.width,
1255
1152
  height: imageData.height,
@@ -1257,14 +1154,12 @@
1257
1154
  marginLeft: imageData.x,
1258
1155
  marginTop: imageData.y
1259
1156
  }, getTransforms(imageData)));
1260
-
1261
1157
  if (done) {
1262
1158
  if ((this.viewing || this.moving || this.rotating || this.scaling || this.zooming) && this.options.transition && hasClass(image, CLASS_TRANSITION)) {
1263
1159
  var onTransitionEnd = function onTransitionEnd() {
1264
1160
  _this3.imageRendering = false;
1265
1161
  done();
1266
1162
  };
1267
-
1268
1163
  this.imageRendering = {
1269
1164
  abort: function abort() {
1270
1165
  removeListener(image, EVENT_TRANSITION_END, onTransitionEnd);
@@ -1282,11 +1177,9 @@
1282
1177
  // this.image only defined after viewed
1283
1178
  if (this.viewing || this.viewed) {
1284
1179
  var image = this.image;
1285
-
1286
1180
  if (this.viewing) {
1287
1181
  this.viewing.abort();
1288
1182
  }
1289
-
1290
1183
  image.parentNode.removeChild(image);
1291
1184
  this.image = null;
1292
1185
  }
@@ -1296,8 +1189,8 @@
1296
1189
  var events = {
1297
1190
  bind: function bind() {
1298
1191
  var options = this.options,
1299
- viewer = this.viewer,
1300
- canvas = this.canvas;
1192
+ viewer = this.viewer,
1193
+ canvas = this.canvas;
1301
1194
  var document = this.element.ownerDocument;
1302
1195
  addListener(viewer, EVENT_CLICK, this.onClick = this.click.bind(this));
1303
1196
  addListener(viewer, EVENT_DRAG_START, this.onDragStart = this.dragstart.bind(this));
@@ -1306,22 +1199,20 @@
1306
1199
  addListener(document, EVENT_POINTER_UP, this.onPointerUp = this.pointerup.bind(this));
1307
1200
  addListener(document, EVENT_KEY_DOWN, this.onKeyDown = this.keydown.bind(this));
1308
1201
  addListener(window, EVENT_RESIZE, this.onResize = this.resize.bind(this));
1309
-
1310
1202
  if (options.zoomable && options.zoomOnWheel) {
1311
1203
  addListener(viewer, EVENT_WHEEL, this.onWheel = this.wheel.bind(this), {
1312
1204
  passive: false,
1313
1205
  capture: true
1314
1206
  });
1315
1207
  }
1316
-
1317
1208
  if (options.toggleOnDblclick) {
1318
1209
  addListener(canvas, EVENT_DBLCLICK, this.onDblclick = this.dblclick.bind(this));
1319
1210
  }
1320
1211
  },
1321
1212
  unbind: function unbind() {
1322
1213
  var options = this.options,
1323
- viewer = this.viewer,
1324
- canvas = this.canvas;
1214
+ viewer = this.viewer,
1215
+ canvas = this.canvas;
1325
1216
  var document = this.element.ownerDocument;
1326
1217
  removeListener(viewer, EVENT_CLICK, this.onClick);
1327
1218
  removeListener(viewer, EVENT_DRAG_START, this.onDragStart);
@@ -1330,14 +1221,12 @@
1330
1221
  removeListener(document, EVENT_POINTER_UP, this.onPointerUp);
1331
1222
  removeListener(document, EVENT_KEY_DOWN, this.onKeyDown);
1332
1223
  removeListener(window, EVENT_RESIZE, this.onResize);
1333
-
1334
1224
  if (options.zoomable && options.zoomOnWheel) {
1335
1225
  removeListener(viewer, EVENT_WHEEL, this.onWheel, {
1336
1226
  passive: false,
1337
1227
  capture: true
1338
1228
  });
1339
1229
  }
1340
-
1341
1230
  if (options.toggleOnDblclick) {
1342
1231
  removeListener(canvas, EVENT_DBLCLICK, this.onDblclick);
1343
1232
  }
@@ -1347,20 +1236,18 @@
1347
1236
  var handlers = {
1348
1237
  click: function click(event) {
1349
1238
  var options = this.options,
1350
- imageData = this.imageData;
1239
+ imageData = this.imageData;
1351
1240
  var target = event.target;
1352
1241
  var action = getData(target, DATA_ACTION);
1353
-
1354
1242
  if (!action && target.localName === 'img' && target.parentElement.localName === 'li') {
1355
1243
  target = target.parentElement;
1356
1244
  action = getData(target, DATA_ACTION);
1357
- } // Cancel the emulated click when the native click event was triggered.
1358
-
1245
+ }
1359
1246
 
1247
+ // Cancel the emulated click when the native click event was triggered.
1360
1248
  if (IS_TOUCH_DEVICE && event.isTrusted && target === this.canvas) {
1361
1249
  clearTimeout(this.clickCanvasTimeout);
1362
1250
  }
1363
-
1364
1251
  switch (action) {
1365
1252
  case 'mix':
1366
1253
  if (this.played) {
@@ -1374,115 +1261,91 @@
1374
1261
  } else {
1375
1262
  this.hide();
1376
1263
  }
1377
-
1378
1264
  break;
1379
-
1380
1265
  case 'hide':
1381
1266
  this.hide();
1382
1267
  break;
1383
-
1384
1268
  case 'view':
1385
1269
  this.view(getData(target, 'index'));
1386
1270
  break;
1387
-
1388
1271
  case 'zoom-in':
1389
1272
  this.zoom(0.1, true);
1390
1273
  break;
1391
-
1392
1274
  case 'zoom-out':
1393
1275
  this.zoom(-0.1, true);
1394
1276
  break;
1395
-
1396
1277
  case 'one-to-one':
1397
1278
  this.toggle();
1398
1279
  break;
1399
-
1400
1280
  case 'reset':
1401
1281
  this.reset();
1402
1282
  break;
1403
-
1404
1283
  case 'prev':
1405
1284
  this.prev(options.loop);
1406
1285
  break;
1407
-
1408
1286
  case 'play':
1409
1287
  this.play(options.fullscreen);
1410
1288
  break;
1411
-
1412
1289
  case 'next':
1413
1290
  this.next(options.loop);
1414
1291
  break;
1415
-
1416
1292
  case 'rotate-left':
1417
1293
  this.rotate(-90);
1418
1294
  break;
1419
-
1420
1295
  case 'rotate-right':
1421
1296
  this.rotate(90);
1422
1297
  break;
1423
-
1424
1298
  case 'flip-horizontal':
1425
1299
  this.scaleX(-imageData.scaleX || -1);
1426
1300
  break;
1427
-
1428
1301
  case 'flip-vertical':
1429
1302
  this.scaleY(-imageData.scaleY || -1);
1430
1303
  break;
1431
-
1432
1304
  default:
1433
1305
  if (this.played) {
1434
1306
  this.stop();
1435
1307
  }
1436
-
1437
1308
  }
1438
1309
  },
1439
1310
  dblclick: function dblclick(event) {
1440
1311
  event.preventDefault();
1441
-
1442
1312
  if (this.viewed && event.target === this.image) {
1443
1313
  // Cancel the emulated double click when the native dblclick event was triggered.
1444
1314
  if (IS_TOUCH_DEVICE && event.isTrusted) {
1445
1315
  clearTimeout(this.doubleClickImageTimeout);
1446
- } // XXX: No pageX/Y properties in custom event, fallback to the original event.
1447
-
1316
+ }
1448
1317
 
1318
+ // XXX: No pageX/Y properties in custom event, fallback to the original event.
1449
1319
  this.toggle(event.isTrusted ? event : event.detail && event.detail.originalEvent);
1450
1320
  }
1451
1321
  },
1452
1322
  load: function load() {
1453
1323
  var _this = this;
1454
-
1455
1324
  if (this.timeout) {
1456
1325
  clearTimeout(this.timeout);
1457
1326
  this.timeout = false;
1458
1327
  }
1459
-
1460
1328
  var element = this.element,
1461
- options = this.options,
1462
- image = this.image,
1463
- index = this.index,
1464
- viewerData = this.viewerData;
1329
+ options = this.options,
1330
+ image = this.image,
1331
+ index = this.index,
1332
+ viewerData = this.viewerData;
1465
1333
  removeClass(image, CLASS_INVISIBLE);
1466
-
1467
1334
  if (options.loading) {
1468
1335
  removeClass(this.canvas, CLASS_LOADING);
1469
1336
  }
1470
-
1471
1337
  image.style.cssText = 'height:0;' + "margin-left:".concat(viewerData.width / 2, "px;") + "margin-top:".concat(viewerData.height / 2, "px;") + 'max-width:none!important;' + 'position:relative;' + 'width:0;';
1472
1338
  this.initImage(function () {
1473
1339
  toggleClass(image, CLASS_MOVE, options.movable);
1474
1340
  toggleClass(image, CLASS_TRANSITION, options.transition);
1475
-
1476
1341
  _this.renderImage(function () {
1477
1342
  _this.viewed = true;
1478
1343
  _this.viewing = false;
1479
-
1480
1344
  if (isFunction(options.viewed)) {
1481
1345
  addListener(element, EVENT_VIEWED, options.viewed, {
1482
1346
  once: true
1483
1347
  });
1484
1348
  }
1485
-
1486
1349
  dispatchEvent(element, EVENT_VIEWED, {
1487
1350
  originalImage: _this.images[index],
1488
1351
  index: index,
@@ -1503,7 +1366,6 @@
1503
1366
  var aspectRatio = naturalWidth / naturalHeight;
1504
1367
  var width = parentWidth;
1505
1368
  var height = parentHeight;
1506
-
1507
1369
  if (parentHeight * aspectRatio > parentWidth) {
1508
1370
  if (filled) {
1509
1371
  width = parentHeight * aspectRatio;
@@ -1515,7 +1377,6 @@
1515
1377
  } else {
1516
1378
  width = parentHeight * aspectRatio;
1517
1379
  }
1518
-
1519
1380
  setStyle(image, assign({
1520
1381
  width: width,
1521
1382
  height: height
@@ -1527,27 +1388,21 @@
1527
1388
  },
1528
1389
  keydown: function keydown(event) {
1529
1390
  var options = this.options;
1530
-
1531
1391
  if (!options.keyboard) {
1532
1392
  return;
1533
1393
  }
1534
-
1535
1394
  var keyCode = event.keyCode || event.which || event.charCode;
1536
-
1537
1395
  switch (keyCode) {
1538
1396
  // Enter
1539
1397
  case 13:
1540
1398
  if (this.viewer.contains(event.target)) {
1541
1399
  this.click(event);
1542
1400
  }
1543
-
1544
1401
  break;
1545
1402
  }
1546
-
1547
1403
  if (!this.fulled) {
1548
1404
  return;
1549
1405
  }
1550
-
1551
1406
  switch (keyCode) {
1552
1407
  // Escape
1553
1408
  case 27:
@@ -1560,54 +1415,62 @@
1560
1415
  } else {
1561
1416
  this.hide();
1562
1417
  }
1563
-
1564
1418
  break;
1565
- // Space
1566
1419
 
1420
+ // Space
1567
1421
  case 32:
1568
1422
  if (this.played) {
1569
1423
  this.stop();
1570
1424
  }
1571
-
1572
1425
  break;
1573
- // ArrowLeft
1574
1426
 
1427
+ // ArrowLeft
1575
1428
  case 37:
1576
- this.prev(options.loop);
1429
+ if (this.played && this.playing) {
1430
+ this.playing.prev();
1431
+ } else {
1432
+ this.prev(options.loop);
1433
+ }
1577
1434
  break;
1578
- // ArrowUp
1579
1435
 
1436
+ // ArrowUp
1580
1437
  case 38:
1581
1438
  // Prevent scroll on Firefox
1582
- event.preventDefault(); // Zoom in
1439
+ event.preventDefault();
1583
1440
 
1441
+ // Zoom in
1584
1442
  this.zoom(options.zoomRatio, true);
1585
1443
  break;
1586
- // ArrowRight
1587
1444
 
1445
+ // ArrowRight
1588
1446
  case 39:
1589
- this.next(options.loop);
1447
+ if (this.played && this.playing) {
1448
+ this.playing.next();
1449
+ } else {
1450
+ this.next(options.loop);
1451
+ }
1590
1452
  break;
1591
- // ArrowDown
1592
1453
 
1454
+ // ArrowDown
1593
1455
  case 40:
1594
1456
  // Prevent scroll on Firefox
1595
- event.preventDefault(); // Zoom out
1457
+ event.preventDefault();
1596
1458
 
1459
+ // Zoom out
1597
1460
  this.zoom(-options.zoomRatio, true);
1598
1461
  break;
1462
+
1599
1463
  // Ctrl + 0
1464
+ case 48:
1465
+ // Fall through
1600
1466
 
1601
- case 48: // Fall through
1602
1467
  // Ctrl + 1
1603
1468
  // eslint-disable-next-line no-fallthrough
1604
-
1605
1469
  case 49:
1606
1470
  if (event.ctrlKey) {
1607
1471
  event.preventDefault();
1608
1472
  this.toggle();
1609
1473
  }
1610
-
1611
1474
  break;
1612
1475
  }
1613
1476
  },
@@ -1618,20 +1481,23 @@
1618
1481
  },
1619
1482
  pointerdown: function pointerdown(event) {
1620
1483
  var options = this.options,
1621
- pointers = this.pointers;
1484
+ pointers = this.pointers;
1622
1485
  var buttons = event.buttons,
1623
- button = event.button;
1486
+ button = event.button;
1487
+ if (!this.viewed || this.showing || this.viewing || this.hiding
1488
+
1489
+ // Handle mouse event and pointer event and ignore touch event
1490
+ || (event.type === 'mousedown' || event.type === 'pointerdown' && event.pointerType === 'mouse') && (
1491
+ // No primary button (Usually the left button)
1492
+ isNumber(buttons) && buttons !== 1 || isNumber(button) && button !== 0
1624
1493
 
1625
- if (!this.viewed || this.showing || this.viewing || this.hiding // Handle mouse event and pointer event and ignore touch event
1626
- || (event.type === 'mousedown' || event.type === 'pointerdown' && event.pointerType === 'mouse') && ( // No primary button (Usually the left button)
1627
- isNumber(buttons) && buttons !== 1 || isNumber(button) && button !== 0 // Open context menu
1494
+ // Open context menu
1628
1495
  || event.ctrlKey)) {
1629
1496
  return;
1630
- } // Prevent default behaviours as page zooming in touch devices.
1631
-
1497
+ }
1632
1498
 
1499
+ // Prevent default behaviours as page zooming in touch devices.
1633
1500
  event.preventDefault();
1634
-
1635
1501
  if (event.changedTouches) {
1636
1502
  forEach(event.changedTouches, function (touch) {
1637
1503
  pointers[touch.identifier] = getPointer(touch);
@@ -1639,31 +1505,24 @@
1639
1505
  } else {
1640
1506
  pointers[event.pointerId || 0] = getPointer(event);
1641
1507
  }
1642
-
1643
1508
  var action = options.movable ? ACTION_MOVE : false;
1644
-
1645
1509
  if (options.zoomOnTouch && options.zoomable && Object.keys(pointers).length > 1) {
1646
1510
  action = ACTION_ZOOM;
1647
1511
  } else if (options.slideOnTouch && (event.pointerType === 'touch' || event.type === 'touchstart') && this.isSwitchable()) {
1648
1512
  action = ACTION_SWITCH;
1649
1513
  }
1650
-
1651
1514
  if (options.transition && (action === ACTION_MOVE || action === ACTION_ZOOM)) {
1652
1515
  removeClass(this.image, CLASS_TRANSITION);
1653
1516
  }
1654
-
1655
1517
  this.action = action;
1656
1518
  },
1657
1519
  pointermove: function pointermove(event) {
1658
1520
  var pointers = this.pointers,
1659
- action = this.action;
1660
-
1521
+ action = this.action;
1661
1522
  if (!this.viewed || !action) {
1662
1523
  return;
1663
1524
  }
1664
-
1665
1525
  event.preventDefault();
1666
-
1667
1526
  if (event.changedTouches) {
1668
1527
  forEach(event.changedTouches, function (touch) {
1669
1528
  assign(pointers[touch.identifier] || {}, getPointer(touch, true));
@@ -1671,17 +1530,14 @@
1671
1530
  } else {
1672
1531
  assign(pointers[event.pointerId || 0] || {}, getPointer(event, true));
1673
1532
  }
1674
-
1675
1533
  this.change(event);
1676
1534
  },
1677
1535
  pointerup: function pointerup(event) {
1678
1536
  var _this2 = this;
1679
-
1680
1537
  var options = this.options,
1681
- action = this.action,
1682
- pointers = this.pointers;
1538
+ action = this.action,
1539
+ pointers = this.pointers;
1683
1540
  var pointer;
1684
-
1685
1541
  if (event.changedTouches) {
1686
1542
  forEach(event.changedTouches, function (touch) {
1687
1543
  pointer = pointers[touch.identifier];
@@ -1691,42 +1547,39 @@
1691
1547
  pointer = pointers[event.pointerId || 0];
1692
1548
  delete pointers[event.pointerId || 0];
1693
1549
  }
1694
-
1695
1550
  if (!action) {
1696
1551
  return;
1697
1552
  }
1698
-
1699
1553
  event.preventDefault();
1700
-
1701
1554
  if (options.transition && (action === ACTION_MOVE || action === ACTION_ZOOM)) {
1702
1555
  addClass(this.image, CLASS_TRANSITION);
1703
1556
  }
1557
+ this.action = false;
1704
1558
 
1705
- this.action = false; // Emulate click and double click in touch devices to support backdrop and image zooming (#210).
1706
-
1559
+ // Emulate click and double click in touch devices to support backdrop and image zooming (#210).
1707
1560
  if (IS_TOUCH_DEVICE && action !== ACTION_ZOOM && pointer && Date.now() - pointer.timeStamp < 500) {
1708
1561
  clearTimeout(this.clickCanvasTimeout);
1709
1562
  clearTimeout(this.doubleClickImageTimeout);
1710
-
1711
1563
  if (options.toggleOnDblclick && this.viewed && event.target === this.image) {
1712
1564
  if (this.imageClicked) {
1713
- this.imageClicked = false; // This timeout will be cleared later when a native dblclick event is triggering
1565
+ this.imageClicked = false;
1714
1566
 
1567
+ // This timeout will be cleared later when a native dblclick event is triggering
1715
1568
  this.doubleClickImageTimeout = setTimeout(function () {
1716
1569
  dispatchEvent(_this2.image, EVENT_DBLCLICK, {
1717
1570
  originalEvent: event
1718
1571
  });
1719
1572
  }, 50);
1720
1573
  } else {
1721
- this.imageClicked = true; // The default timing of a double click in Windows is 500 ms
1574
+ this.imageClicked = true;
1722
1575
 
1576
+ // The default timing of a double click in Windows is 500 ms
1723
1577
  this.doubleClickImageTimeout = setTimeout(function () {
1724
1578
  _this2.imageClicked = false;
1725
1579
  }, 500);
1726
1580
  }
1727
1581
  } else {
1728
1582
  this.imageClicked = false;
1729
-
1730
1583
  if (options.backdrop && options.backdrop !== 'static' && event.target === this.canvas) {
1731
1584
  // This timeout will be cleared later when a native click event is triggering
1732
1585
  this.clickCanvasTimeout = setTimeout(function () {
@@ -1740,34 +1593,28 @@
1740
1593
  },
1741
1594
  resize: function resize() {
1742
1595
  var _this3 = this;
1743
-
1744
1596
  if (!this.isShown || this.hiding) {
1745
1597
  return;
1746
1598
  }
1747
-
1748
1599
  if (this.fulled) {
1749
1600
  this.close();
1750
1601
  this.initBody();
1751
1602
  this.open();
1752
1603
  }
1753
-
1754
1604
  this.initContainer();
1755
1605
  this.initViewer();
1756
1606
  this.renderViewer();
1757
1607
  this.renderList();
1758
-
1759
1608
  if (this.viewed) {
1760
1609
  this.initImage(function () {
1761
1610
  _this3.renderImage();
1762
1611
  });
1763
1612
  }
1764
-
1765
1613
  if (this.played) {
1766
1614
  if (this.options.fullscreen && this.fulled && !(document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement)) {
1767
1615
  this.stop();
1768
1616
  return;
1769
1617
  }
1770
-
1771
1618
  forEach(this.player.getElementsByTagName('img'), function (image) {
1772
1619
  addListener(image, EVENT_LOAD, _this3.loadImage.bind(_this3), {
1773
1620
  once: true
@@ -1778,24 +1625,21 @@
1778
1625
  },
1779
1626
  wheel: function wheel(event) {
1780
1627
  var _this4 = this;
1781
-
1782
1628
  if (!this.viewed) {
1783
1629
  return;
1784
1630
  }
1631
+ event.preventDefault();
1785
1632
 
1786
- event.preventDefault(); // Limit wheel speed to prevent zoom too fast
1787
-
1633
+ // Limit wheel speed to prevent zoom too fast
1788
1634
  if (this.wheeling) {
1789
1635
  return;
1790
1636
  }
1791
-
1792
1637
  this.wheeling = true;
1793
1638
  setTimeout(function () {
1794
1639
  _this4.wheeling = false;
1795
1640
  }, 50);
1796
1641
  var ratio = Number(this.options.zoomRatio) || 0.1;
1797
1642
  var delta = 1;
1798
-
1799
1643
  if (event.deltaY) {
1800
1644
  delta = event.deltaY > 0 ? 1 : -1;
1801
1645
  } else if (event.wheelDelta) {
@@ -1803,8 +1647,7 @@
1803
1647
  } else if (event.detail) {
1804
1648
  delta = event.detail > 0 ? 1 : -1;
1805
1649
  }
1806
-
1807
- this.zoom(-delta * ratio, true, event);
1650
+ this.zoom(-delta * ratio, true, null, event);
1808
1651
  }
1809
1652
  };
1810
1653
 
@@ -1816,36 +1659,28 @@
1816
1659
  show: function show() {
1817
1660
  var immediate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
1818
1661
  var element = this.element,
1819
- options = this.options;
1820
-
1662
+ options = this.options;
1821
1663
  if (options.inline || this.showing || this.isShown || this.showing) {
1822
1664
  return this;
1823
1665
  }
1824
-
1825
1666
  if (!this.ready) {
1826
1667
  this.build();
1827
-
1828
1668
  if (this.ready) {
1829
1669
  this.show(immediate);
1830
1670
  }
1831
-
1832
1671
  return this;
1833
1672
  }
1834
-
1835
1673
  if (isFunction(options.show)) {
1836
1674
  addListener(element, EVENT_SHOW, options.show, {
1837
1675
  once: true
1838
1676
  });
1839
1677
  }
1840
-
1841
1678
  if (dispatchEvent(element, EVENT_SHOW) === false || !this.ready) {
1842
1679
  return this;
1843
1680
  }
1844
-
1845
1681
  if (this.hiding) {
1846
1682
  this.transitioning.abort();
1847
1683
  }
1848
-
1849
1684
  this.showing = true;
1850
1685
  this.open();
1851
1686
  var viewer = this.viewer;
@@ -1854,7 +1689,6 @@
1854
1689
  viewer.setAttribute('aria-labelledby', this.title.id);
1855
1690
  viewer.setAttribute('aria-modal', true);
1856
1691
  viewer.removeAttribute('aria-hidden');
1857
-
1858
1692
  if (options.transition && !immediate) {
1859
1693
  var shown = this.shown.bind(this);
1860
1694
  this.transitioning = {
@@ -1863,8 +1697,9 @@
1863
1697
  removeClass(viewer, CLASS_IN);
1864
1698
  }
1865
1699
  };
1866
- addClass(viewer, CLASS_TRANSITION); // Force reflow to enable CSS3 transition
1700
+ addClass(viewer, CLASS_TRANSITION);
1867
1701
 
1702
+ // Force reflow to enable CSS3 transition
1868
1703
  viewer.initialOffsetWidth = viewer.offsetWidth;
1869
1704
  addListener(viewer, EVENT_TRANSITION_END, shown, {
1870
1705
  once: true
@@ -1874,10 +1709,8 @@
1874
1709
  addClass(viewer, CLASS_IN);
1875
1710
  this.shown();
1876
1711
  }
1877
-
1878
1712
  return this;
1879
1713
  },
1880
-
1881
1714
  /**
1882
1715
  * Hide the viewer (only available in modal mode)
1883
1716
  * @param {boolean} [immediate=false] - Indicates if hide the viewer immediately or not.
@@ -1885,56 +1718,43 @@
1885
1718
  */
1886
1719
  hide: function hide() {
1887
1720
  var _this = this;
1888
-
1889
1721
  var immediate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
1890
1722
  var element = this.element,
1891
- options = this.options;
1892
-
1723
+ options = this.options;
1893
1724
  if (options.inline || this.hiding || !(this.isShown || this.showing)) {
1894
1725
  return this;
1895
1726
  }
1896
-
1897
1727
  if (isFunction(options.hide)) {
1898
1728
  addListener(element, EVENT_HIDE, options.hide, {
1899
1729
  once: true
1900
1730
  });
1901
1731
  }
1902
-
1903
1732
  if (dispatchEvent(element, EVENT_HIDE) === false) {
1904
1733
  return this;
1905
1734
  }
1906
-
1907
1735
  if (this.showing) {
1908
1736
  this.transitioning.abort();
1909
1737
  }
1910
-
1911
1738
  this.hiding = true;
1912
-
1913
1739
  if (this.played) {
1914
1740
  this.stop();
1915
1741
  } else if (this.viewing) {
1916
1742
  this.viewing.abort();
1917
1743
  }
1918
-
1919
1744
  var viewer = this.viewer,
1920
- image = this.image;
1921
-
1745
+ image = this.image;
1922
1746
  var hideImmediately = function hideImmediately() {
1923
1747
  removeClass(viewer, CLASS_IN);
1924
-
1925
1748
  _this.hidden();
1926
1749
  };
1927
-
1928
1750
  if (options.transition && !immediate) {
1929
1751
  var onViewerTransitionEnd = function onViewerTransitionEnd(event) {
1930
1752
  // Ignore all propagating `transitionend` events (#275).
1931
1753
  if (event && event.target === viewer) {
1932
1754
  removeListener(viewer, EVENT_TRANSITION_END, onViewerTransitionEnd);
1933
-
1934
1755
  _this.hidden();
1935
1756
  }
1936
1757
  };
1937
-
1938
1758
  var onImageTransitionEnd = function onImageTransitionEnd() {
1939
1759
  // In case of show the viewer by `viewer.show(true)` previously (#407).
1940
1760
  if (hasClass(viewer, CLASS_TRANSITION)) {
@@ -1944,7 +1764,6 @@
1944
1764
  hideImmediately();
1945
1765
  }
1946
1766
  };
1947
-
1948
1767
  this.transitioning = {
1949
1768
  abort: function abort() {
1950
1769
  if (_this.viewed && hasClass(image, CLASS_TRANSITION)) {
@@ -1953,24 +1772,23 @@
1953
1772
  removeListener(viewer, EVENT_TRANSITION_END, onViewerTransitionEnd);
1954
1773
  }
1955
1774
  }
1956
- }; // In case of hiding the viewer when holding on the image (#255),
1957
- // note that the `CLASS_TRANSITION` class will be removed on pointer down.
1775
+ };
1958
1776
 
1777
+ // In case of hiding the viewer when holding on the image (#255),
1778
+ // note that the `CLASS_TRANSITION` class will be removed on pointer down.
1959
1779
  if (this.viewed && hasClass(image, CLASS_TRANSITION)) {
1960
1780
  addListener(image, EVENT_TRANSITION_END, onImageTransitionEnd, {
1961
1781
  once: true
1962
1782
  });
1963
- this.zoomTo(0, false, null, true);
1783
+ this.zoomTo(0, false, null, null, true);
1964
1784
  } else {
1965
1785
  onImageTransitionEnd();
1966
1786
  }
1967
1787
  } else {
1968
1788
  hideImmediately();
1969
1789
  }
1970
-
1971
1790
  return this;
1972
1791
  },
1973
-
1974
1792
  /**
1975
1793
  * View one of the images with image's index
1976
1794
  * @param {number} index - The index of the image to view.
@@ -1978,27 +1796,22 @@
1978
1796
  */
1979
1797
  view: function view() {
1980
1798
  var _this2 = this;
1981
-
1982
1799
  var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.options.initialViewIndex;
1983
1800
  index = Number(index) || 0;
1984
-
1985
1801
  if (this.hiding || this.played || index < 0 || index >= this.length || this.viewed && index === this.index) {
1986
1802
  return this;
1987
1803
  }
1988
-
1989
1804
  if (!this.isShown) {
1990
1805
  this.index = index;
1991
1806
  return this.show();
1992
1807
  }
1993
-
1994
1808
  if (this.viewing) {
1995
1809
  this.viewing.abort();
1996
1810
  }
1997
-
1998
1811
  var element = this.element,
1999
- options = this.options,
2000
- title = this.title,
2001
- canvas = this.canvas;
1812
+ options = this.options,
1813
+ title = this.title,
1814
+ canvas = this.canvas;
2002
1815
  var item = this.items[index];
2003
1816
  var img = item.querySelector('img');
2004
1817
  var url = getData(img, 'originalUrl');
@@ -2006,20 +1819,17 @@
2006
1819
  var image = document.createElement('img');
2007
1820
  forEach(options.inheritedAttributes, function (name) {
2008
1821
  var value = img.getAttribute(name);
2009
-
2010
1822
  if (value !== null) {
2011
1823
  image.setAttribute(name, value);
2012
1824
  }
2013
1825
  });
2014
1826
  image.src = url;
2015
1827
  image.alt = alt;
2016
-
2017
1828
  if (isFunction(options.view)) {
2018
1829
  addListener(element, EVENT_VIEW, options.view, {
2019
1830
  once: true
2020
1831
  });
2021
1832
  }
2022
-
2023
1833
  if (dispatchEvent(element, EVENT_VIEW, {
2024
1834
  originalImage: this.images[index],
2025
1835
  index: index,
@@ -2027,44 +1837,39 @@
2027
1837
  }) === false || !this.isShown || this.hiding || this.played) {
2028
1838
  return this;
2029
1839
  }
2030
-
2031
1840
  var activeItem = this.items[this.index];
2032
-
2033
1841
  if (activeItem) {
2034
1842
  removeClass(activeItem, CLASS_ACTIVE);
2035
1843
  activeItem.removeAttribute('aria-selected');
2036
1844
  }
2037
-
2038
1845
  addClass(item, CLASS_ACTIVE);
2039
1846
  item.setAttribute('aria-selected', true);
2040
-
2041
1847
  if (options.focus) {
2042
1848
  item.focus();
2043
1849
  }
2044
-
2045
1850
  this.image = image;
2046
1851
  this.viewed = false;
2047
1852
  this.index = index;
2048
1853
  this.imageData = {};
2049
1854
  addClass(image, CLASS_INVISIBLE);
2050
-
2051
1855
  if (options.loading) {
2052
1856
  addClass(canvas, CLASS_LOADING);
2053
1857
  }
2054
-
2055
1858
  canvas.innerHTML = '';
2056
- canvas.appendChild(image); // Center current item
1859
+ canvas.appendChild(image);
2057
1860
 
2058
- this.renderList(); // Clear title
1861
+ // Center current item
1862
+ this.renderList();
2059
1863
 
2060
- title.innerHTML = ''; // Generate title after viewed
1864
+ // Clear title
1865
+ title.innerHTML = '';
2061
1866
 
1867
+ // Generate title after viewed
2062
1868
  var onViewed = function onViewed() {
2063
1869
  var imageData = _this2.imageData;
2064
1870
  var render = Array.isArray(options.title) ? options.title[1] : options.title;
2065
1871
  title.innerHTML = escapeHTMLEntities(isFunction(render) ? render.call(_this2, image, imageData) : "".concat(alt, " (").concat(imageData.naturalWidth, " \xD7 ").concat(imageData.naturalHeight, ")"));
2066
1872
  };
2067
-
2068
1873
  var onLoad;
2069
1874
  var onError;
2070
1875
  addListener(element, EVENT_VIEWED, onViewed, {
@@ -2073,7 +1878,6 @@
2073
1878
  this.viewing = {
2074
1879
  abort: function abort() {
2075
1880
  removeListener(element, EVENT_VIEWED, onViewed);
2076
-
2077
1881
  if (image.complete) {
2078
1882
  if (_this2.imageRendering) {
2079
1883
  _this2.imageRendering.abort();
@@ -2084,55 +1888,46 @@
2084
1888
  // Cancel download to save bandwidth.
2085
1889
  image.src = '';
2086
1890
  removeListener(image, EVENT_LOAD, onLoad);
2087
-
2088
1891
  if (_this2.timeout) {
2089
1892
  clearTimeout(_this2.timeout);
2090
1893
  }
2091
1894
  }
2092
1895
  }
2093
1896
  };
2094
-
2095
1897
  if (image.complete) {
2096
1898
  this.load();
2097
1899
  } else {
2098
1900
  addListener(image, EVENT_LOAD, onLoad = function onLoad() {
2099
1901
  removeListener(image, EVENT_ERROR, onError);
2100
-
2101
1902
  _this2.load();
2102
1903
  }, {
2103
1904
  once: true
2104
1905
  });
2105
1906
  addListener(image, EVENT_ERROR, onError = function onError() {
2106
1907
  removeListener(image, EVENT_LOAD, onLoad);
2107
-
2108
1908
  if (_this2.timeout) {
2109
1909
  clearTimeout(_this2.timeout);
2110
1910
  _this2.timeout = false;
2111
1911
  }
2112
-
2113
1912
  removeClass(image, CLASS_INVISIBLE);
2114
-
2115
1913
  if (options.loading) {
2116
1914
  removeClass(_this2.canvas, CLASS_LOADING);
2117
1915
  }
2118
1916
  }, {
2119
1917
  once: true
2120
1918
  });
2121
-
2122
1919
  if (this.timeout) {
2123
1920
  clearTimeout(this.timeout);
2124
- } // Make the image visible if it fails to load within 1s
2125
-
1921
+ }
2126
1922
 
1923
+ // Make the image visible if it fails to load within 1s
2127
1924
  this.timeout = setTimeout(function () {
2128
1925
  removeClass(image, CLASS_INVISIBLE);
2129
1926
  _this2.timeout = false;
2130
1927
  }, 1000);
2131
1928
  }
2132
-
2133
1929
  return this;
2134
1930
  },
2135
-
2136
1931
  /**
2137
1932
  * View the previous image
2138
1933
  * @param {boolean} [loop=false] - Indicate if view the last one
@@ -2142,15 +1937,12 @@
2142
1937
  prev: function prev() {
2143
1938
  var loop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
2144
1939
  var index = this.index - 1;
2145
-
2146
1940
  if (index < 0) {
2147
1941
  index = loop ? this.length - 1 : 0;
2148
1942
  }
2149
-
2150
1943
  this.view(index);
2151
1944
  return this;
2152
1945
  },
2153
-
2154
1946
  /**
2155
1947
  * View the next image
2156
1948
  * @param {boolean} [loop=false] - Indicate if view the first one
@@ -2161,15 +1953,12 @@
2161
1953
  var loop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
2162
1954
  var maxIndex = this.length - 1;
2163
1955
  var index = this.index + 1;
2164
-
2165
1956
  if (index > maxIndex) {
2166
1957
  index = loop ? 0 : maxIndex;
2167
1958
  }
2168
-
2169
1959
  this.view(index);
2170
1960
  return this;
2171
1961
  },
2172
-
2173
1962
  /**
2174
1963
  * Move the image with relative offsets.
2175
1964
  * @param {number} x - The moving distance in the horizontal direction.
@@ -2182,7 +1971,6 @@
2182
1971
  this.moveTo(isUndefined(x) ? x : imageData.x + Number(x), isUndefined(y) ? y : imageData.y + Number(y));
2183
1972
  return this;
2184
1973
  },
2185
-
2186
1974
  /**
2187
1975
  * Move the image to an absolute point.
2188
1976
  * @param {number} x - The new position in the horizontal direction.
@@ -2192,41 +1980,33 @@
2192
1980
  */
2193
1981
  moveTo: function moveTo(x) {
2194
1982
  var _this3 = this;
2195
-
2196
1983
  var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x;
2197
-
2198
1984
  var _originalEvent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
2199
-
2200
1985
  var element = this.element,
2201
- options = this.options,
2202
- imageData = this.imageData;
1986
+ options = this.options,
1987
+ imageData = this.imageData;
2203
1988
  x = Number(x);
2204
1989
  y = Number(y);
2205
-
2206
1990
  if (this.viewed && !this.played && options.movable) {
2207
1991
  var oldX = imageData.x;
2208
1992
  var oldY = imageData.y;
2209
1993
  var changed = false;
2210
-
2211
1994
  if (isNumber(x)) {
2212
1995
  changed = true;
2213
1996
  } else {
2214
1997
  x = oldX;
2215
1998
  }
2216
-
2217
1999
  if (isNumber(y)) {
2218
2000
  changed = true;
2219
2001
  } else {
2220
2002
  y = oldY;
2221
2003
  }
2222
-
2223
2004
  if (changed) {
2224
2005
  if (isFunction(options.move)) {
2225
2006
  addListener(element, EVENT_MOVE, options.move, {
2226
2007
  once: true
2227
2008
  });
2228
2009
  }
2229
-
2230
2010
  if (dispatchEvent(element, EVENT_MOVE, {
2231
2011
  x: x,
2232
2012
  y: y,
@@ -2236,7 +2016,6 @@
2236
2016
  }) === false) {
2237
2017
  return this;
2238
2018
  }
2239
-
2240
2019
  imageData.x = x;
2241
2020
  imageData.y = y;
2242
2021
  imageData.left = x;
@@ -2244,13 +2023,11 @@
2244
2023
  this.moving = true;
2245
2024
  this.renderImage(function () {
2246
2025
  _this3.moving = false;
2247
-
2248
2026
  if (isFunction(options.moved)) {
2249
2027
  addListener(element, EVENT_MOVED, options.moved, {
2250
2028
  once: true
2251
2029
  });
2252
2030
  }
2253
-
2254
2031
  dispatchEvent(element, EVENT_MOVED, {
2255
2032
  x: x,
2256
2033
  y: y,
@@ -2263,10 +2040,8 @@
2263
2040
  });
2264
2041
  }
2265
2042
  }
2266
-
2267
2043
  return this;
2268
2044
  },
2269
-
2270
2045
  /**
2271
2046
  * Rotate the image with a relative degree.
2272
2047
  * @param {number} degree - The rotate degree.
@@ -2276,7 +2051,6 @@
2276
2051
  this.rotateTo((this.imageData.rotate || 0) + Number(degree));
2277
2052
  return this;
2278
2053
  },
2279
-
2280
2054
  /**
2281
2055
  * Rotate the image to an absolute degree.
2282
2056
  * @param {number} degree - The rotate degree.
@@ -2284,39 +2058,32 @@
2284
2058
  */
2285
2059
  rotateTo: function rotateTo(degree) {
2286
2060
  var _this4 = this;
2287
-
2288
2061
  var element = this.element,
2289
- options = this.options,
2290
- imageData = this.imageData;
2062
+ options = this.options,
2063
+ imageData = this.imageData;
2291
2064
  degree = Number(degree);
2292
-
2293
2065
  if (isNumber(degree) && this.viewed && !this.played && options.rotatable) {
2294
2066
  var oldDegree = imageData.rotate;
2295
-
2296
2067
  if (isFunction(options.rotate)) {
2297
2068
  addListener(element, EVENT_ROTATE, options.rotate, {
2298
2069
  once: true
2299
2070
  });
2300
2071
  }
2301
-
2302
2072
  if (dispatchEvent(element, EVENT_ROTATE, {
2303
2073
  degree: degree,
2304
2074
  oldDegree: oldDegree
2305
2075
  }) === false) {
2306
2076
  return this;
2307
2077
  }
2308
-
2309
2078
  imageData.rotate = degree;
2310
2079
  this.rotating = true;
2311
2080
  this.renderImage(function () {
2312
2081
  _this4.rotating = false;
2313
-
2314
2082
  if (isFunction(options.rotated)) {
2315
2083
  addListener(element, EVENT_ROTATED, options.rotated, {
2316
2084
  once: true
2317
2085
  });
2318
2086
  }
2319
-
2320
2087
  dispatchEvent(element, EVENT_ROTATED, {
2321
2088
  degree: degree,
2322
2089
  oldDegree: oldDegree
@@ -2325,10 +2092,8 @@
2325
2092
  });
2326
2093
  });
2327
2094
  }
2328
-
2329
2095
  return this;
2330
2096
  },
2331
-
2332
2097
  /**
2333
2098
  * Scale the image on the x-axis.
2334
2099
  * @param {number} scaleX - The scale ratio on the x-axis.
@@ -2338,7 +2103,6 @@
2338
2103
  this.scale(_scaleX, this.imageData.scaleY);
2339
2104
  return this;
2340
2105
  },
2341
-
2342
2106
  /**
2343
2107
  * Scale the image on the y-axis.
2344
2108
  * @param {number} scaleY - The scale ratio on the y-axis.
@@ -2348,7 +2112,6 @@
2348
2112
  this.scale(this.imageData.scaleX, _scaleY);
2349
2113
  return this;
2350
2114
  },
2351
-
2352
2115
  /**
2353
2116
  * Scale the image.
2354
2117
  * @param {number} scaleX - The scale ratio on the x-axis.
@@ -2357,38 +2120,32 @@
2357
2120
  */
2358
2121
  scale: function scale(scaleX) {
2359
2122
  var _this5 = this;
2360
-
2361
2123
  var scaleY = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : scaleX;
2362
2124
  var element = this.element,
2363
- options = this.options,
2364
- imageData = this.imageData;
2125
+ options = this.options,
2126
+ imageData = this.imageData;
2365
2127
  scaleX = Number(scaleX);
2366
2128
  scaleY = Number(scaleY);
2367
-
2368
2129
  if (this.viewed && !this.played && options.scalable) {
2369
2130
  var oldScaleX = imageData.scaleX;
2370
2131
  var oldScaleY = imageData.scaleY;
2371
2132
  var changed = false;
2372
-
2373
2133
  if (isNumber(scaleX)) {
2374
2134
  changed = true;
2375
2135
  } else {
2376
2136
  scaleX = oldScaleX;
2377
2137
  }
2378
-
2379
2138
  if (isNumber(scaleY)) {
2380
2139
  changed = true;
2381
2140
  } else {
2382
2141
  scaleY = oldScaleY;
2383
2142
  }
2384
-
2385
2143
  if (changed) {
2386
2144
  if (isFunction(options.scale)) {
2387
2145
  addListener(element, EVENT_SCALE, options.scale, {
2388
2146
  once: true
2389
2147
  });
2390
2148
  }
2391
-
2392
2149
  if (dispatchEvent(element, EVENT_SCALE, {
2393
2150
  scaleX: scaleX,
2394
2151
  scaleY: scaleY,
@@ -2397,19 +2154,16 @@
2397
2154
  }) === false) {
2398
2155
  return this;
2399
2156
  }
2400
-
2401
2157
  imageData.scaleX = scaleX;
2402
2158
  imageData.scaleY = scaleY;
2403
2159
  this.scaling = true;
2404
2160
  this.renderImage(function () {
2405
2161
  _this5.scaling = false;
2406
-
2407
2162
  if (isFunction(options.scaled)) {
2408
2163
  addListener(element, EVENT_SCALED, options.scaled, {
2409
2164
  once: true
2410
2165
  });
2411
2166
  }
2412
-
2413
2167
  dispatchEvent(element, EVENT_SCALED, {
2414
2168
  scaleX: scaleX,
2415
2169
  scaleY: scaleY,
@@ -2421,103 +2175,88 @@
2421
2175
  });
2422
2176
  }
2423
2177
  }
2424
-
2425
2178
  return this;
2426
2179
  },
2427
-
2428
2180
  /**
2429
2181
  * Zoom the image with a relative ratio.
2430
2182
  * @param {number} ratio - The target ratio.
2431
- * @param {boolean} [hasTooltip=false] - Indicates if it has a tooltip or not.
2183
+ * @param {boolean} [showTooltip=false] - Indicates whether to show the tooltip.
2184
+ * @param {Object} [pivot] - The pivot point coordinate for zooming.
2432
2185
  * @param {Event} [_originalEvent=null] - The original event if any.
2433
2186
  * @returns {Viewer} this
2434
2187
  */
2435
2188
  zoom: function zoom(ratio) {
2436
- var hasTooltip = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
2437
-
2438
- var _originalEvent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
2439
-
2189
+ var showTooltip = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
2190
+ var pivot = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
2191
+ var _originalEvent = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
2440
2192
  var imageData = this.imageData;
2441
2193
  ratio = Number(ratio);
2442
-
2443
2194
  if (ratio < 0) {
2444
2195
  ratio = 1 / (1 - ratio);
2445
2196
  } else {
2446
2197
  ratio = 1 + ratio;
2447
2198
  }
2448
-
2449
- this.zoomTo(imageData.width * ratio / imageData.naturalWidth, hasTooltip, _originalEvent);
2199
+ this.zoomTo(imageData.width * ratio / imageData.naturalWidth, showTooltip, pivot, _originalEvent);
2450
2200
  return this;
2451
2201
  },
2452
-
2453
2202
  /**
2454
2203
  * Zoom the image to an absolute ratio.
2455
2204
  * @param {number} ratio - The target ratio.
2456
- * @param {boolean} [hasTooltip=false] - Indicates if it has a tooltip or not.
2205
+ * @param {boolean} [showTooltip] - Indicates whether to show the tooltip.
2206
+ * @param {Object} [pivot] - The pivot point coordinate for zooming.
2457
2207
  * @param {Event} [_originalEvent=null] - The original event if any.
2458
2208
  * @param {Event} [_zoomable=false] - Indicates if the current zoom is available or not.
2459
2209
  * @returns {Viewer} this
2460
2210
  */
2461
2211
  zoomTo: function zoomTo(ratio) {
2462
2212
  var _this6 = this;
2463
-
2464
- var hasTooltip = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
2465
-
2466
- var _originalEvent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
2467
-
2468
- var _zoomable = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
2469
-
2213
+ var showTooltip = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
2214
+ var pivot = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
2215
+ var _originalEvent = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
2216
+ var _zoomable = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
2470
2217
  var element = this.element,
2471
- options = this.options,
2472
- pointers = this.pointers,
2473
- imageData = this.imageData;
2218
+ options = this.options,
2219
+ pointers = this.pointers,
2220
+ imageData = this.imageData;
2474
2221
  var x = imageData.x,
2475
- y = imageData.y,
2476
- width = imageData.width,
2477
- height = imageData.height,
2478
- naturalWidth = imageData.naturalWidth,
2479
- naturalHeight = imageData.naturalHeight;
2222
+ y = imageData.y,
2223
+ width = imageData.width,
2224
+ height = imageData.height,
2225
+ naturalWidth = imageData.naturalWidth,
2226
+ naturalHeight = imageData.naturalHeight;
2480
2227
  ratio = Math.max(0, ratio);
2481
-
2482
2228
  if (isNumber(ratio) && this.viewed && !this.played && (_zoomable || options.zoomable)) {
2483
2229
  if (!_zoomable) {
2484
2230
  var minZoomRatio = Math.max(0.01, options.minZoomRatio);
2485
2231
  var maxZoomRatio = Math.min(100, options.maxZoomRatio);
2486
2232
  ratio = Math.min(Math.max(ratio, minZoomRatio), maxZoomRatio);
2487
2233
  }
2488
-
2489
2234
  if (_originalEvent) {
2490
2235
  switch (_originalEvent.type) {
2491
2236
  case 'wheel':
2492
2237
  if (options.zoomRatio >= 0.055 && ratio > 0.95 && ratio < 1.05) {
2493
2238
  ratio = 1;
2494
2239
  }
2495
-
2496
2240
  break;
2497
-
2498
2241
  case 'pointermove':
2499
2242
  case 'touchmove':
2500
2243
  case 'mousemove':
2501
2244
  if (ratio > 0.99 && ratio < 1.01) {
2502
2245
  ratio = 1;
2503
2246
  }
2504
-
2505
2247
  break;
2506
2248
  }
2507
2249
  }
2508
-
2509
2250
  var newWidth = naturalWidth * ratio;
2510
2251
  var newHeight = naturalHeight * ratio;
2511
2252
  var offsetWidth = newWidth - width;
2512
2253
  var offsetHeight = newHeight - height;
2513
2254
  var oldRatio = imageData.ratio;
2514
-
2515
2255
  if (isFunction(options.zoom)) {
2516
2256
  addListener(element, EVENT_ZOOM, options.zoom, {
2517
2257
  once: true
2518
2258
  });
2519
2259
  }
2520
-
2521
2260
  if (dispatchEvent(element, EVENT_ZOOM, {
2522
2261
  ratio: ratio,
2523
2262
  oldRatio: oldRatio,
@@ -2525,24 +2264,25 @@
2525
2264
  }) === false) {
2526
2265
  return this;
2527
2266
  }
2528
-
2529
2267
  this.zooming = true;
2530
-
2531
2268
  if (_originalEvent) {
2532
2269
  var offset = getOffset(this.viewer);
2533
2270
  var center = pointers && Object.keys(pointers).length > 0 ? getPointersCenter(pointers) : {
2534
2271
  pageX: _originalEvent.pageX,
2535
2272
  pageY: _originalEvent.pageY
2536
- }; // Zoom from the triggering point of the event
2273
+ };
2537
2274
 
2275
+ // Zoom from the triggering point of the event
2538
2276
  imageData.x -= offsetWidth * ((center.pageX - offset.left - x) / width);
2539
2277
  imageData.y -= offsetHeight * ((center.pageY - offset.top - y) / height);
2278
+ } else if (isPlainObject(pivot) && isNumber(pivot.x) && isNumber(pivot.y)) {
2279
+ imageData.x -= offsetWidth * ((pivot.x - x) / width);
2280
+ imageData.y -= offsetHeight * ((pivot.y - y) / height);
2540
2281
  } else {
2541
2282
  // Zoom from the center of the image
2542
2283
  imageData.x -= offsetWidth / 2;
2543
2284
  imageData.y -= offsetHeight / 2;
2544
2285
  }
2545
-
2546
2286
  imageData.left = imageData.x;
2547
2287
  imageData.top = imageData.y;
2548
2288
  imageData.width = newWidth;
@@ -2551,13 +2291,11 @@
2551
2291
  imageData.ratio = ratio;
2552
2292
  this.renderImage(function () {
2553
2293
  _this6.zooming = false;
2554
-
2555
2294
  if (isFunction(options.zoomed)) {
2556
2295
  addListener(element, EVENT_ZOOMED, options.zoomed, {
2557
2296
  once: true
2558
2297
  });
2559
2298
  }
2560
-
2561
2299
  dispatchEvent(element, EVENT_ZOOMED, {
2562
2300
  ratio: ratio,
2563
2301
  oldRatio: oldRatio,
@@ -2566,15 +2304,12 @@
2566
2304
  cancelable: false
2567
2305
  });
2568
2306
  });
2569
-
2570
- if (hasTooltip) {
2307
+ if (showTooltip) {
2571
2308
  this.tooltip();
2572
2309
  }
2573
2310
  }
2574
-
2575
2311
  return this;
2576
2312
  },
2577
-
2578
2313
  /**
2579
2314
  * Play the images
2580
2315
  * @param {boolean|FullscreenOptions} [fullscreen=false] - Indicate if request fullscreen or not.
@@ -2582,26 +2317,20 @@
2582
2317
  */
2583
2318
  play: function play() {
2584
2319
  var _this7 = this;
2585
-
2586
2320
  var fullscreen = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
2587
-
2588
2321
  if (!this.isShown || this.played) {
2589
2322
  return this;
2590
2323
  }
2591
-
2592
2324
  var element = this.element,
2593
- options = this.options;
2594
-
2325
+ options = this.options;
2595
2326
  if (isFunction(options.play)) {
2596
2327
  addListener(element, EVENT_PLAY, options.play, {
2597
2328
  once: true
2598
2329
  });
2599
2330
  }
2600
-
2601
2331
  if (dispatchEvent(element, EVENT_PLAY) === false) {
2602
2332
  return this;
2603
2333
  }
2604
-
2605
2334
  var player = this.player;
2606
2335
  var onLoad = this.loadImage.bind(this);
2607
2336
  var list = [];
@@ -2609,11 +2338,9 @@
2609
2338
  var index = 0;
2610
2339
  this.played = true;
2611
2340
  this.onLoadWhenPlay = onLoad;
2612
-
2613
2341
  if (fullscreen) {
2614
2342
  this.requestFullscreen(fullscreen);
2615
2343
  }
2616
-
2617
2344
  addClass(player, CLASS_SHOW);
2618
2345
  forEach(this.items, function (item, i) {
2619
2346
  var img = item.querySelector('img');
@@ -2624,61 +2351,63 @@
2624
2351
  total += 1;
2625
2352
  addClass(image, CLASS_FADE);
2626
2353
  toggleClass(image, CLASS_TRANSITION, options.transition);
2627
-
2628
2354
  if (hasClass(item, CLASS_ACTIVE)) {
2629
2355
  addClass(image, CLASS_IN);
2630
2356
  index = i;
2631
2357
  }
2632
-
2633
2358
  list.push(image);
2634
2359
  addListener(image, EVENT_LOAD, onLoad, {
2635
2360
  once: true
2636
2361
  });
2637
2362
  player.appendChild(image);
2638
2363
  });
2639
-
2640
2364
  if (isNumber(options.interval) && options.interval > 0) {
2641
- var play = function play() {
2642
- _this7.playing = setTimeout(function () {
2643
- removeClass(list[index], CLASS_IN);
2644
- index += 1;
2645
- index = index < total ? index : 0;
2646
- addClass(list[index], CLASS_IN);
2647
- play();
2648
- }, options.interval);
2365
+ var prev = function prev() {
2366
+ clearTimeout(_this7.playing.timeout);
2367
+ removeClass(list[index], CLASS_IN);
2368
+ index -= 1;
2369
+ index = index >= 0 ? index : total - 1;
2370
+ addClass(list[index], CLASS_IN);
2371
+ _this7.playing.timeout = setTimeout(prev, options.interval);
2372
+ };
2373
+ var next = function next() {
2374
+ clearTimeout(_this7.playing.timeout);
2375
+ removeClass(list[index], CLASS_IN);
2376
+ index += 1;
2377
+ index = index < total ? index : 0;
2378
+ addClass(list[index], CLASS_IN);
2379
+ _this7.playing.timeout = setTimeout(next, options.interval);
2649
2380
  };
2650
-
2651
2381
  if (total > 1) {
2652
- play();
2382
+ this.playing = {
2383
+ prev: prev,
2384
+ next: next,
2385
+ timeout: setTimeout(next, options.interval)
2386
+ };
2653
2387
  }
2654
2388
  }
2655
-
2656
2389
  return this;
2657
2390
  },
2658
2391
  // Stop play
2659
2392
  stop: function stop() {
2660
2393
  var _this8 = this;
2661
-
2662
2394
  if (!this.played) {
2663
2395
  return this;
2664
2396
  }
2665
-
2666
2397
  var element = this.element,
2667
- options = this.options;
2668
-
2398
+ options = this.options;
2669
2399
  if (isFunction(options.stop)) {
2670
2400
  addListener(element, EVENT_STOP, options.stop, {
2671
2401
  once: true
2672
2402
  });
2673
2403
  }
2674
-
2675
2404
  if (dispatchEvent(element, EVENT_STOP) === false) {
2676
2405
  return this;
2677
2406
  }
2678
-
2679
2407
  var player = this.player;
2408
+ clearTimeout(this.playing.timeout);
2409
+ this.playing = false;
2680
2410
  this.played = false;
2681
- clearTimeout(this.playing);
2682
2411
  forEach(player.getElementsByTagName('img'), function (image) {
2683
2412
  removeListener(image, EVENT_LOAD, _this8.onLoadWhenPlay);
2684
2413
  });
@@ -2690,28 +2419,22 @@
2690
2419
  // Enter modal mode (only available in inline mode)
2691
2420
  full: function full() {
2692
2421
  var _this9 = this;
2693
-
2694
2422
  var options = this.options,
2695
- viewer = this.viewer,
2696
- image = this.image,
2697
- list = this.list;
2698
-
2423
+ viewer = this.viewer,
2424
+ image = this.image,
2425
+ list = this.list;
2699
2426
  if (!this.isShown || this.played || this.fulled || !options.inline) {
2700
2427
  return this;
2701
2428
  }
2702
-
2703
2429
  this.fulled = true;
2704
2430
  this.open();
2705
2431
  addClass(this.button, CLASS_FULLSCREEN_EXIT);
2706
-
2707
2432
  if (options.transition) {
2708
2433
  removeClass(list, CLASS_TRANSITION);
2709
-
2710
2434
  if (this.viewed) {
2711
2435
  removeClass(image, CLASS_TRANSITION);
2712
2436
  }
2713
2437
  }
2714
-
2715
2438
  addClass(viewer, CLASS_FIXED);
2716
2439
  viewer.setAttribute('role', 'dialog');
2717
2440
  viewer.setAttribute('aria-labelledby', this.title.id);
@@ -2720,15 +2443,12 @@
2720
2443
  setStyle(viewer, {
2721
2444
  zIndex: options.zIndex
2722
2445
  });
2723
-
2724
2446
  if (options.focus) {
2725
2447
  this.enforceFocus();
2726
2448
  }
2727
-
2728
2449
  this.initContainer();
2729
2450
  this.viewerData = assign({}, this.containerData);
2730
2451
  this.renderList();
2731
-
2732
2452
  if (this.viewed) {
2733
2453
  this.initImage(function () {
2734
2454
  _this9.renderImage(function () {
@@ -2741,38 +2461,30 @@
2741
2461
  });
2742
2462
  });
2743
2463
  }
2744
-
2745
2464
  return this;
2746
2465
  },
2747
2466
  // Exit modal mode (only available in inline mode)
2748
2467
  exit: function exit() {
2749
2468
  var _this10 = this;
2750
-
2751
2469
  var options = this.options,
2752
- viewer = this.viewer,
2753
- image = this.image,
2754
- list = this.list;
2755
-
2470
+ viewer = this.viewer,
2471
+ image = this.image,
2472
+ list = this.list;
2756
2473
  if (!this.isShown || this.played || !this.fulled || !options.inline) {
2757
2474
  return this;
2758
2475
  }
2759
-
2760
2476
  this.fulled = false;
2761
2477
  this.close();
2762
2478
  removeClass(this.button, CLASS_FULLSCREEN_EXIT);
2763
-
2764
2479
  if (options.transition) {
2765
2480
  removeClass(list, CLASS_TRANSITION);
2766
-
2767
2481
  if (this.viewed) {
2768
2482
  removeClass(image, CLASS_TRANSITION);
2769
2483
  }
2770
2484
  }
2771
-
2772
2485
  if (options.focus) {
2773
2486
  this.clearEnforceFocus();
2774
2487
  }
2775
-
2776
2488
  viewer.removeAttribute('role');
2777
2489
  viewer.removeAttribute('aria-labelledby');
2778
2490
  viewer.removeAttribute('aria-modal');
@@ -2783,7 +2495,6 @@
2783
2495
  this.viewerData = assign({}, this.parentData);
2784
2496
  this.renderViewer();
2785
2497
  this.renderList();
2786
-
2787
2498
  if (this.viewed) {
2788
2499
  this.initImage(function () {
2789
2500
  _this10.renderImage(function () {
@@ -2796,34 +2507,29 @@
2796
2507
  });
2797
2508
  });
2798
2509
  }
2799
-
2800
2510
  return this;
2801
2511
  },
2802
2512
  // Show the current ratio of the image with percentage
2803
2513
  tooltip: function tooltip() {
2804
2514
  var _this11 = this;
2805
-
2806
2515
  var options = this.options,
2807
- tooltipBox = this.tooltipBox,
2808
- imageData = this.imageData;
2809
-
2516
+ tooltipBox = this.tooltipBox,
2517
+ imageData = this.imageData;
2810
2518
  if (!this.viewed || this.played || !options.tooltip) {
2811
2519
  return this;
2812
2520
  }
2813
-
2814
2521
  tooltipBox.textContent = "".concat(Math.round(imageData.ratio * 100), "%");
2815
-
2816
2522
  if (!this.tooltipping) {
2817
2523
  if (options.transition) {
2818
2524
  if (this.fading) {
2819
2525
  dispatchEvent(tooltipBox, EVENT_TRANSITION_END);
2820
2526
  }
2821
-
2822
2527
  addClass(tooltipBox, CLASS_SHOW);
2823
2528
  addClass(tooltipBox, CLASS_FADE);
2824
2529
  addClass(tooltipBox, CLASS_TRANSITION);
2825
- tooltipBox.removeAttribute('aria-hidden'); // Force reflow to enable CSS3 transition
2530
+ tooltipBox.removeAttribute('aria-hidden');
2826
2531
 
2532
+ // Force reflow to enable CSS3 transition
2827
2533
  tooltipBox.initialOffsetWidth = tooltipBox.offsetWidth;
2828
2534
  addClass(tooltipBox, CLASS_IN);
2829
2535
  } else {
@@ -2833,7 +2539,6 @@
2833
2539
  } else {
2834
2540
  clearTimeout(this.tooltipping);
2835
2541
  }
2836
-
2837
2542
  this.tooltipping = setTimeout(function () {
2838
2543
  if (options.transition) {
2839
2544
  addListener(tooltipBox, EVENT_TRANSITION_END, function () {
@@ -2851,12 +2556,10 @@
2851
2556
  removeClass(tooltipBox, CLASS_SHOW);
2852
2557
  tooltipBox.setAttribute('aria-hidden', true);
2853
2558
  }
2854
-
2855
2559
  _this11.tooltipping = false;
2856
2560
  }, 1000);
2857
2561
  return this;
2858
2562
  },
2859
-
2860
2563
  /**
2861
2564
  * Toggle the image size between its current size and natural size
2862
2565
  * @param {Event} [_originalEvent=null] - The original event if any.
@@ -2864,13 +2567,11 @@
2864
2567
  */
2865
2568
  toggle: function toggle() {
2866
2569
  var _originalEvent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
2867
-
2868
2570
  if (this.imageData.ratio === 1) {
2869
- this.zoomTo(this.imageData.oldRatio, true, _originalEvent);
2571
+ this.zoomTo(this.imageData.oldRatio, true, null, _originalEvent);
2870
2572
  } else {
2871
- this.zoomTo(1, true, _originalEvent);
2573
+ this.zoomTo(1, true, null, _originalEvent);
2872
2574
  }
2873
-
2874
2575
  return this;
2875
2576
  },
2876
2577
  // Reset the image to its initial state
@@ -2879,21 +2580,19 @@
2879
2580
  this.imageData = assign({}, this.initialImageData);
2880
2581
  this.renderImage();
2881
2582
  }
2882
-
2883
2583
  return this;
2884
2584
  },
2885
2585
  // Update viewer when images changed
2886
2586
  update: function update() {
2887
2587
  var _this12 = this;
2888
-
2889
2588
  var element = this.element,
2890
- options = this.options,
2891
- isImg = this.isImg; // Destroy viewer if the target image was deleted
2589
+ options = this.options,
2590
+ isImg = this.isImg;
2892
2591
 
2592
+ // Destroy viewer if the target image was deleted
2893
2593
  if (isImg && !element.parentNode) {
2894
2594
  return this.destroy();
2895
2595
  }
2896
-
2897
2596
  var images = [];
2898
2597
  forEach(isImg ? [element] : element.querySelectorAll('img'), function (image) {
2899
2598
  if (isFunction(options.filter)) {
@@ -2904,22 +2603,20 @@
2904
2603
  images.push(image);
2905
2604
  }
2906
2605
  });
2907
-
2908
2606
  if (!images.length) {
2909
2607
  return this;
2910
2608
  }
2911
-
2912
2609
  this.images = images;
2913
2610
  this.length = images.length;
2914
-
2915
2611
  if (this.ready) {
2916
2612
  var changedIndexes = [];
2917
2613
  forEach(this.items, function (item, i) {
2918
2614
  var img = item.querySelector('img');
2919
2615
  var image = images[i];
2920
-
2921
2616
  if (image && img) {
2922
- if (image.src !== img.src // Title changed (#408)
2617
+ if (image.src !== img.src
2618
+
2619
+ // Title changed (#408)
2923
2620
  || image.alt !== img.alt) {
2924
2621
  changedIndexes.push(i);
2925
2622
  }
@@ -2931,18 +2628,17 @@
2931
2628
  width: 'auto'
2932
2629
  });
2933
2630
  this.initList();
2934
-
2935
2631
  if (this.isShown) {
2936
2632
  if (this.length) {
2937
2633
  if (this.viewed) {
2938
2634
  var changedIndex = changedIndexes.indexOf(this.index);
2939
-
2940
2635
  if (changedIndex >= 0) {
2941
2636
  this.viewed = false;
2942
2637
  this.view(Math.max(Math.min(this.index - changedIndex, this.length - 1), 0));
2943
2638
  } else {
2944
- var activeItem = this.items[this.index]; // Reactivate the current viewing item after reset the list.
2639
+ var activeItem = this.items[this.index];
2945
2640
 
2641
+ // Reactivate the current viewing item after reset the list.
2946
2642
  addClass(activeItem, CLASS_ACTIVE);
2947
2643
  activeItem.setAttribute('aria-selected', true);
2948
2644
  }
@@ -2959,30 +2655,24 @@
2959
2655
  } else {
2960
2656
  this.build();
2961
2657
  }
2962
-
2963
2658
  return this;
2964
2659
  },
2965
2660
  // Destroy the viewer
2966
2661
  destroy: function destroy() {
2967
2662
  var element = this.element,
2968
- options = this.options;
2969
-
2663
+ options = this.options;
2970
2664
  if (!element[NAMESPACE]) {
2971
2665
  return this;
2972
2666
  }
2973
-
2974
2667
  this.destroyed = true;
2975
-
2976
2668
  if (this.ready) {
2977
2669
  if (this.played) {
2978
2670
  this.stop();
2979
2671
  }
2980
-
2981
2672
  if (options.inline) {
2982
2673
  if (this.fulled) {
2983
2674
  this.exit();
2984
2675
  }
2985
-
2986
2676
  this.unbind();
2987
2677
  } else if (this.isShown) {
2988
2678
  if (this.viewing) {
@@ -2992,17 +2682,14 @@
2992
2682
  this.imageInitializing.abort();
2993
2683
  }
2994
2684
  }
2995
-
2996
2685
  if (this.hiding) {
2997
2686
  this.transitioning.abort();
2998
2687
  }
2999
-
3000
2688
  this.hidden();
3001
2689
  } else if (this.showing) {
3002
2690
  this.transitioning.abort();
3003
2691
  this.hidden();
3004
2692
  }
3005
-
3006
2693
  this.ready = false;
3007
2694
  this.viewer.parentNode.removeChild(this.viewer);
3008
2695
  } else if (options.inline) {
@@ -3012,11 +2699,9 @@
3012
2699
  this.initializing.abort();
3013
2700
  }
3014
2701
  }
3015
-
3016
2702
  if (!options.inline) {
3017
2703
  removeListener(element, EVENT_CLICK, this.onStart);
3018
2704
  }
3019
-
3020
2705
  element[NAMESPACE] = undefined;
3021
2706
  return this;
3022
2707
  }
@@ -3025,7 +2710,6 @@
3025
2710
  var others = {
3026
2711
  getImageURL: function getImageURL(image) {
3027
2712
  var url = this.options.url;
3028
-
3029
2713
  if (isString(url)) {
3030
2714
  url = image.getAttribute(url);
3031
2715
  } else if (isFunction(url)) {
@@ -3033,30 +2717,24 @@
3033
2717
  } else {
3034
2718
  url = '';
3035
2719
  }
3036
-
3037
2720
  return url;
3038
2721
  },
3039
2722
  enforceFocus: function enforceFocus() {
3040
2723
  var _this = this;
3041
-
3042
2724
  this.clearEnforceFocus();
3043
2725
  addListener(document, EVENT_FOCUSIN, this.onFocusin = function (event) {
3044
2726
  var viewer = _this.viewer;
3045
2727
  var target = event.target;
3046
-
3047
2728
  if (target === document || target === viewer || viewer.contains(target)) {
3048
2729
  return;
3049
2730
  }
3050
-
3051
2731
  while (target) {
3052
2732
  // Avoid conflicts with other modals (#474, #540)
3053
2733
  if (target.getAttribute('tabindex') !== null || target.getAttribute('aria-modal') === 'true') {
3054
2734
  return;
3055
2735
  }
3056
-
3057
2736
  target = target.parentElement;
3058
2737
  }
3059
-
3060
2738
  viewer.focus();
3061
2739
  });
3062
2740
  },
@@ -3069,51 +2747,49 @@
3069
2747
  open: function open() {
3070
2748
  var body = this.body;
3071
2749
  addClass(body, CLASS_OPEN);
3072
- body.style.paddingRight = "".concat(this.scrollbarWidth + (parseFloat(this.initialBodyComputedPaddingRight) || 0), "px");
2750
+ if (this.scrollbarWidth > 0) {
2751
+ body.style.paddingRight = "".concat(this.scrollbarWidth + (parseFloat(this.initialBodyComputedPaddingRight) || 0), "px");
2752
+ }
3073
2753
  },
3074
2754
  close: function close() {
3075
2755
  var body = this.body;
3076
2756
  removeClass(body, CLASS_OPEN);
3077
- body.style.paddingRight = this.initialBodyPaddingRight;
2757
+ if (this.scrollbarWidth > 0) {
2758
+ body.style.paddingRight = this.initialBodyPaddingRight;
2759
+ }
3078
2760
  },
3079
2761
  shown: function shown() {
3080
2762
  var element = this.element,
3081
- options = this.options,
3082
- viewer = this.viewer;
2763
+ options = this.options,
2764
+ viewer = this.viewer;
3083
2765
  this.fulled = true;
3084
2766
  this.isShown = true;
3085
2767
  this.render();
3086
2768
  this.bind();
3087
2769
  this.showing = false;
3088
-
3089
2770
  if (options.focus) {
3090
2771
  viewer.focus();
3091
2772
  this.enforceFocus();
3092
2773
  }
3093
-
3094
2774
  if (isFunction(options.shown)) {
3095
2775
  addListener(element, EVENT_SHOWN, options.shown, {
3096
2776
  once: true
3097
2777
  });
3098
2778
  }
3099
-
3100
2779
  if (dispatchEvent(element, EVENT_SHOWN) === false) {
3101
2780
  return;
3102
2781
  }
3103
-
3104
2782
  if (this.ready && this.isShown && !this.hiding) {
3105
2783
  this.view(this.index);
3106
2784
  }
3107
2785
  },
3108
2786
  hidden: function hidden() {
3109
2787
  var element = this.element,
3110
- options = this.options,
3111
- viewer = this.viewer;
3112
-
2788
+ options = this.options,
2789
+ viewer = this.viewer;
3113
2790
  if (options.fucus) {
3114
2791
  this.clearEnforceFocus();
3115
2792
  }
3116
-
3117
2793
  this.fulled = false;
3118
2794
  this.viewed = false;
3119
2795
  this.isShown = false;
@@ -3127,14 +2803,12 @@
3127
2803
  this.resetList();
3128
2804
  this.resetImage();
3129
2805
  this.hiding = false;
3130
-
3131
2806
  if (!this.destroyed) {
3132
2807
  if (isFunction(options.hidden)) {
3133
2808
  addListener(element, EVENT_HIDDEN, options.hidden, {
3134
2809
  once: true
3135
2810
  });
3136
2811
  }
3137
-
3138
2812
  dispatchEvent(element, EVENT_HIDDEN, null, {
3139
2813
  cancelable: false
3140
2814
  });
@@ -3142,10 +2816,10 @@
3142
2816
  },
3143
2817
  requestFullscreen: function requestFullscreen(options) {
3144
2818
  var document = this.element.ownerDocument;
3145
-
3146
2819
  if (this.fulled && !(document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement)) {
3147
- var documentElement = document.documentElement; // Element.requestFullscreen()
2820
+ var documentElement = document.documentElement;
3148
2821
 
2822
+ // Element.requestFullscreen()
3149
2823
  if (documentElement.requestFullscreen) {
3150
2824
  // Avoid TypeError when convert `options` to dictionary
3151
2825
  if (isPlainObject(options)) {
@@ -3164,7 +2838,6 @@
3164
2838
  },
3165
2839
  exitFullscreen: function exitFullscreen() {
3166
2840
  var document = this.element.ownerDocument;
3167
-
3168
2841
  if (this.fulled && (document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement)) {
3169
2842
  // Document.exitFullscreen()
3170
2843
  if (document.exitFullscreen) {
@@ -3180,48 +2853,43 @@
3180
2853
  },
3181
2854
  change: function change(event) {
3182
2855
  var options = this.options,
3183
- pointers = this.pointers;
3184
- var pointer = pointers[Object.keys(pointers)[0]]; // In the case of the `pointers` object is empty (#421)
2856
+ pointers = this.pointers;
2857
+ var pointer = pointers[Object.keys(pointers)[0]];
3185
2858
 
2859
+ // In the case of the `pointers` object is empty (#421)
3186
2860
  if (!pointer) {
3187
2861
  return;
3188
2862
  }
3189
-
3190
2863
  var offsetX = pointer.endX - pointer.startX;
3191
2864
  var offsetY = pointer.endY - pointer.startY;
3192
-
3193
2865
  switch (this.action) {
3194
2866
  // Move the current image
3195
2867
  case ACTION_MOVE:
3196
2868
  this.move(offsetX, offsetY, event);
3197
2869
  break;
3198
- // Zoom the current image
3199
2870
 
2871
+ // Zoom the current image
3200
2872
  case ACTION_ZOOM:
3201
- this.zoom(getMaxZoomRatio(pointers), false, event);
2873
+ this.zoom(getMaxZoomRatio(pointers), false, null, event);
3202
2874
  break;
3203
-
3204
2875
  case ACTION_SWITCH:
3205
2876
  {
3206
2877
  this.action = 'switched';
3207
2878
  var absoluteOffsetX = Math.abs(offsetX);
3208
-
3209
2879
  if (absoluteOffsetX > 1 && absoluteOffsetX > Math.abs(offsetY)) {
3210
2880
  // Empty `pointers` as `touchend` event will not be fired after swiped in iOS browsers.
3211
2881
  this.pointers = {};
3212
-
3213
2882
  if (offsetX > 1) {
3214
2883
  this.prev(options.loop);
3215
2884
  } else if (offsetX < -1) {
3216
2885
  this.next(options.loop);
3217
2886
  }
3218
2887
  }
3219
-
3220
2888
  break;
3221
2889
  }
3222
- } // Override
3223
-
2890
+ }
3224
2891
 
2892
+ // Override
3225
2893
  forEach(pointers, function (p) {
3226
2894
  p.startX = p.endX;
3227
2895
  p.startY = p.endY;
@@ -3229,20 +2897,18 @@
3229
2897
  },
3230
2898
  isSwitchable: function isSwitchable() {
3231
2899
  var imageData = this.imageData,
3232
- viewerData = this.viewerData;
2900
+ viewerData = this.viewerData;
3233
2901
  return this.length > 1 && imageData.x >= 0 && imageData.y >= 0 && imageData.width <= viewerData.width && imageData.height <= viewerData.height;
3234
2902
  }
3235
2903
  };
3236
2904
 
3237
2905
  var AnotherViewer = WINDOW.Viewer;
3238
-
3239
2906
  var getUniqueID = function (id) {
3240
2907
  return function () {
3241
2908
  id += 1;
3242
2909
  return id;
3243
2910
  };
3244
2911
  }(-1);
3245
-
3246
2912
  var Viewer = /*#__PURE__*/function () {
3247
2913
  /**
3248
2914
  * Create a new Viewer.
@@ -3251,13 +2917,10 @@
3251
2917
  */
3252
2918
  function Viewer(element) {
3253
2919
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3254
-
3255
2920
  _classCallCheck(this, Viewer);
3256
-
3257
2921
  if (!element || element.nodeType !== 1) {
3258
2922
  throw new Error('The first argument is required and must be an element.');
3259
2923
  }
3260
-
3261
2924
  this.element = element;
3262
2925
  this.options = assign({}, DEFAULTS, isPlainObject(options) && options);
3263
2926
  this.action = false;
@@ -3287,25 +2950,21 @@
3287
2950
  this.id = getUniqueID();
3288
2951
  this.init();
3289
2952
  }
3290
-
3291
2953
  _createClass(Viewer, [{
3292
2954
  key: "init",
3293
2955
  value: function init() {
3294
2956
  var _this = this;
3295
-
3296
2957
  var element = this.element,
3297
- options = this.options;
3298
-
2958
+ options = this.options;
3299
2959
  if (element[NAMESPACE]) {
3300
2960
  return;
3301
2961
  }
2962
+ element[NAMESPACE] = this;
3302
2963
 
3303
- element[NAMESPACE] = this; // The `focus` option requires the `keyboard` option set to `true`.
3304
-
2964
+ // The `focus` option requires the `keyboard` option set to `true`.
3305
2965
  if (options.focus && !options.keyboard) {
3306
2966
  options.focus = false;
3307
2967
  }
3308
-
3309
2968
  var isImg = element.localName === 'img';
3310
2969
  var images = [];
3311
2970
  forEach(isImg ? [element] : element.querySelectorAll('img'), function (image) {
@@ -3320,18 +2979,16 @@
3320
2979
  this.isImg = isImg;
3321
2980
  this.length = images.length;
3322
2981
  this.images = images;
3323
- this.initBody(); // Override `transition` option if it is not supported
2982
+ this.initBody();
3324
2983
 
2984
+ // Override `transition` option if it is not supported
3325
2985
  if (isUndefined(document.createElement(NAMESPACE).style.transition)) {
3326
2986
  options.transition = false;
3327
2987
  }
3328
-
3329
2988
  if (options.inline) {
3330
2989
  var count = 0;
3331
-
3332
2990
  var progress = function progress() {
3333
2991
  count += 1;
3334
-
3335
2992
  if (count === _this.length) {
3336
2993
  var timeout;
3337
2994
  _this.initializing = false;
@@ -3339,16 +2996,15 @@
3339
2996
  abort: function abort() {
3340
2997
  clearTimeout(timeout);
3341
2998
  }
3342
- }; // build asynchronously to keep `this.viewer` is accessible in `ready` event handler.
2999
+ };
3343
3000
 
3001
+ // build asynchronously to keep `this.viewer` is accessible in `ready` event handler.
3344
3002
  timeout = setTimeout(function () {
3345
3003
  _this.delaying = false;
3346
-
3347
3004
  _this.build();
3348
3005
  }, 0);
3349
3006
  }
3350
3007
  };
3351
-
3352
3008
  this.initializing = {
3353
3009
  abort: function abort() {
3354
3010
  forEach(images, function (image) {
@@ -3382,7 +3038,6 @@
3382
3038
  } else {
3383
3039
  addListener(element, EVENT_CLICK, this.onStart = function (_ref) {
3384
3040
  var target = _ref.target;
3385
-
3386
3041
  if (target.localName === 'img' && (!isFunction(options.filter) || options.filter.call(_this, target))) {
3387
3042
  _this.view(_this.images.indexOf(target));
3388
3043
  }
@@ -3395,9 +3050,8 @@
3395
3050
  if (this.ready) {
3396
3051
  return;
3397
3052
  }
3398
-
3399
3053
  var element = this.element,
3400
- options = this.options;
3054
+ options = this.options;
3401
3055
  var parent = element.parentNode;
3402
3056
  var template = document.createElement('div');
3403
3057
  template.innerHTML = TEMPLATE;
@@ -3423,82 +3077,65 @@
3423
3077
  addClass(title, !options.title ? CLASS_HIDE : getResponsiveClass(Array.isArray(options.title) ? options.title[0] : options.title));
3424
3078
  addClass(navbar, !options.navbar ? CLASS_HIDE : getResponsiveClass(options.navbar));
3425
3079
  toggleClass(button, CLASS_HIDE, !options.button);
3426
-
3427
3080
  if (options.keyboard) {
3428
3081
  button.setAttribute('tabindex', 0);
3429
3082
  }
3430
-
3431
3083
  if (options.backdrop) {
3432
3084
  addClass(viewer, "".concat(NAMESPACE, "-backdrop"));
3433
-
3434
3085
  if (!options.inline && options.backdrop !== 'static') {
3435
3086
  setData(canvas, DATA_ACTION, 'hide');
3436
3087
  }
3437
3088
  }
3438
-
3439
3089
  if (isString(options.className) && options.className) {
3440
3090
  // In case there are multiple class names
3441
3091
  options.className.split(REGEXP_SPACES).forEach(function (className) {
3442
3092
  addClass(viewer, className);
3443
3093
  });
3444
3094
  }
3445
-
3446
3095
  if (options.toolbar) {
3447
3096
  var list = document.createElement('ul');
3448
3097
  var custom = isPlainObject(options.toolbar);
3449
3098
  var zoomButtons = BUTTONS.slice(0, 3);
3450
3099
  var rotateButtons = BUTTONS.slice(7, 9);
3451
3100
  var scaleButtons = BUTTONS.slice(9);
3452
-
3453
3101
  if (!custom) {
3454
3102
  addClass(toolbar, getResponsiveClass(options.toolbar));
3455
3103
  }
3456
-
3457
3104
  forEach(custom ? options.toolbar : BUTTONS, function (value, index) {
3458
3105
  var deep = custom && isPlainObject(value);
3459
3106
  var name = custom ? hyphenate(index) : value;
3460
3107
  var show = deep && !isUndefined(value.show) ? value.show : value;
3461
-
3462
3108
  if (!show || !options.zoomable && zoomButtons.indexOf(name) !== -1 || !options.rotatable && rotateButtons.indexOf(name) !== -1 || !options.scalable && scaleButtons.indexOf(name) !== -1) {
3463
3109
  return;
3464
3110
  }
3465
-
3466
3111
  var size = deep && !isUndefined(value.size) ? value.size : value;
3467
3112
  var click = deep && !isUndefined(value.click) ? value.click : value;
3468
3113
  var item = document.createElement('li');
3469
-
3470
3114
  if (options.keyboard) {
3471
3115
  item.setAttribute('tabindex', 0);
3472
3116
  }
3473
-
3474
3117
  item.setAttribute('role', 'button');
3475
3118
  addClass(item, "".concat(NAMESPACE, "-").concat(name));
3476
-
3477
3119
  if (!isFunction(click)) {
3478
3120
  setData(item, DATA_ACTION, name);
3479
3121
  }
3480
-
3481
3122
  if (isNumber(show)) {
3482
3123
  addClass(item, getResponsiveClass(show));
3483
3124
  }
3484
-
3485
3125
  if (['small', 'large'].indexOf(size) !== -1) {
3486
3126
  addClass(item, "".concat(NAMESPACE, "-").concat(size));
3487
3127
  } else if (name === 'play') {
3488
3128
  addClass(item, "".concat(NAMESPACE, "-large"));
3489
3129
  }
3490
-
3491
3130
  if (isFunction(click)) {
3492
3131
  addListener(item, EVENT_CLICK, click);
3493
3132
  }
3494
-
3495
3133
  list.appendChild(item);
3496
3134
  });
3497
3135
  toolbar.appendChild(list);
3498
3136
  } else {
3499
3137
  addClass(toolbar, CLASS_HIDE);
3500
3138
  }
3501
-
3502
3139
  if (!options.rotatable) {
3503
3140
  var rotates = toolbar.querySelectorAll('li[class*="rotate"]');
3504
3141
  addClass(rotates, CLASS_INVISIBLE);
@@ -3506,19 +3143,16 @@
3506
3143
  toolbar.appendChild(rotate);
3507
3144
  });
3508
3145
  }
3509
-
3510
3146
  if (options.inline) {
3511
3147
  addClass(button, CLASS_FULLSCREEN);
3512
3148
  setStyle(viewer, {
3513
3149
  zIndex: options.zIndexInline
3514
3150
  });
3515
-
3516
3151
  if (window.getComputedStyle(parent).position === 'static') {
3517
3152
  setStyle(parent, {
3518
3153
  position: 'relative'
3519
3154
  });
3520
3155
  }
3521
-
3522
3156
  parent.insertBefore(viewer, element.nextSibling);
3523
3157
  } else {
3524
3158
  addClass(button, CLASS_CLOSE);
@@ -3529,67 +3163,57 @@
3529
3163
  zIndex: options.zIndex
3530
3164
  });
3531
3165
  var container = options.container;
3532
-
3533
3166
  if (isString(container)) {
3534
3167
  container = element.ownerDocument.querySelector(container);
3535
3168
  }
3536
-
3537
3169
  if (!container) {
3538
3170
  container = this.body;
3539
3171
  }
3540
-
3541
3172
  container.appendChild(viewer);
3542
3173
  }
3543
-
3544
3174
  if (options.inline) {
3545
3175
  this.render();
3546
3176
  this.bind();
3547
3177
  this.isShown = true;
3548
3178
  }
3549
-
3550
3179
  this.ready = true;
3551
-
3552
3180
  if (isFunction(options.ready)) {
3553
3181
  addListener(element, EVENT_READY, options.ready, {
3554
3182
  once: true
3555
3183
  });
3556
3184
  }
3557
-
3558
3185
  if (dispatchEvent(element, EVENT_READY) === false) {
3559
3186
  this.ready = false;
3560
3187
  return;
3561
3188
  }
3562
-
3563
3189
  if (this.ready && options.inline) {
3564
3190
  this.view(this.index);
3565
3191
  }
3566
3192
  }
3193
+
3567
3194
  /**
3568
3195
  * Get the no conflict viewer class.
3569
3196
  * @returns {Viewer} The viewer class.
3570
3197
  */
3571
-
3572
3198
  }], [{
3573
3199
  key: "noConflict",
3574
3200
  value: function noConflict() {
3575
3201
  window.Viewer = AnotherViewer;
3576
3202
  return Viewer;
3577
3203
  }
3204
+
3578
3205
  /**
3579
3206
  * Change the default options.
3580
3207
  * @param {Object} options - The new default options.
3581
3208
  */
3582
-
3583
3209
  }, {
3584
3210
  key: "setDefaults",
3585
3211
  value: function setDefaults(options) {
3586
3212
  assign(DEFAULTS, isPlainObject(options) && options);
3587
3213
  }
3588
3214
  }]);
3589
-
3590
3215
  return Viewer;
3591
3216
  }();
3592
-
3593
3217
  assign(Viewer.prototype, render, events, handlers, methods, others);
3594
3218
 
3595
3219
  return Viewer;