viewerjs 1.12.0 → 1.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,30 +1,30 @@
1
1
  # Viewer.js
2
2
 
3
- [![Downloads](https://img.shields.io/npm/dm/viewerjs.svg)](https://www.npmjs.com/package/viewerjs) [![Version](https://img.shields.io/npm/v/viewerjs.svg)](https://www.npmjs.com/package/viewerjs) [![Gzip Size](https://img.shields.io/bundlephobia/minzip/viewerjs.svg)](https://unpkg.com/viewerjs/dist/viewer.common.js)
3
+ [![Coverage Status](https://img.shields.io/codecov/c/github/fengyuanchen/viewerjs.svg)](https://codecov.io/gh/fengyuanchen/viewerjs) [![Downloads](https://img.shields.io/npm/dm/viewerjs.svg)](https://www.npmjs.com/package/viewerjs) [![Version](https://img.shields.io/npm/v/viewerjs.svg)](https://www.npmjs.com/package/viewerjs) [![Gzip Size](https://img.shields.io/bundlephobia/minzip/viewerjs.svg)](https://unpkg.com/viewerjs/dist/viewer.common.js)
4
4
 
5
5
  > JavaScript image viewer.
6
6
 
7
7
  - [Website](https://fengyuanchen.github.io/viewerjs)
8
8
  - [jquery-viewer](https://github.com/fengyuanchen/jquery-viewer) - A jQuery plugin wrapper for Viewer.js.
9
9
 
10
- ## Table of contents
10
+ ## Table of Contents
11
11
 
12
12
  - [Features](#features)
13
13
  - [Main Files](#main-files)
14
- - [Getting started](#getting-started)
15
- - [Keyboard support](#keyboard-support)
14
+ - [Getting Started](#getting-started)
15
+ - [Keyboard Support](#keyboard-support)
16
16
  - [Options](#options)
17
17
  - [Methods](#methods)
18
+ - [Static Methods](#static-methods)
18
19
  - [Events](#events)
19
- - [No conflict](#no-conflict)
20
- - [Browser support](#browser-support)
20
+ - [Browser Support](#browser-support)
21
21
  - [Contributing](#contributing)
22
22
  - [Versioning](#versioning)
23
23
  - [License](#license)
24
24
 
25
25
  ## Features
26
26
 
27
- - Supports 53 [options](#options)
27
+ - Supports 57 [options](#options)
28
28
  - Supports 23 [methods](#methods)
29
29
  - Supports 17 [events](#events)
30
30
  - Supports modal and inline modes
@@ -34,9 +34,10 @@
34
34
  - Supports rotation
35
35
  - Supports scale (flip)
36
36
  - Supports keyboard
37
+ - Supports image magnification
37
38
  - Cross-browser support
38
39
 
39
- ## Main files
40
+ ## Main Files
40
41
 
41
42
  ```text
42
43
  dist/
@@ -48,7 +49,7 @@ dist/
48
49
  └── viewer.esm.js (ES Module)
49
50
  ```
50
51
 
51
- ## Getting started
52
+ ## Getting Started
52
53
 
53
54
  ### Installation
54
55
 
@@ -75,11 +76,13 @@ new Viewer(element[, options])
75
76
 
76
77
  - **element**
77
78
  - Type: `HTMLElement`
78
- - The target image, or a container of images, for viewing.
79
+ - The target image, or a container of images, to view.
79
80
 
80
81
  - **options** (optional)
81
82
  - Type: `Object`
82
- - The options for viewing. See the available [options](#options).
83
+ - The configuration options. Check out the available [options](#options).
84
+
85
+ Alternatively, you may use `Viewer.create(element[, options])`.
83
86
 
84
87
  #### Example
85
88
 
@@ -118,7 +121,7 @@ const gallery = new Viewer(document.getElementById('images'));
118
121
  // Then show one image by clicking it, or call `gallery.show()`.
119
122
  ```
120
123
 
121
- ## Keyboard support
124
+ ## Keyboard Support
122
125
 
123
126
  > Only available in modal mode.
124
127
 
@@ -156,7 +159,7 @@ Show the button on the top-right of the viewer.
156
159
 
157
160
  ### navbar
158
161
 
159
- - Type: `Boolean` or `Number`
162
+ - Type: `Boolean` or `Number` or `String` or `Object`
160
163
  - Default: `true`
161
164
  - Options:
162
165
  - `0` or `false`: hide the navbar
@@ -164,9 +167,58 @@ Show the button on the top-right of the viewer.
164
167
  - `2`: show the navbar only when the screen width is greater than 768 pixels
165
168
  - `3`: show the navbar only when the screen width is greater than 992 pixels
166
169
  - `4`: show the navbar only when the screen width is greater than 1200 pixels
170
+ - `small`: show thumbnails at 24px tall.
171
+ - `medium`: show thumbnails at 32px tall.
172
+ - `large`: show thumbnails at 40px tall.
173
+ - `Object`: configure the navbar with the following properties:
174
+ - `show` (`Boolean` or `Number`): specify the visibility of the navbar.
175
+ - `size` (`String`): specify the thumbnail size: `small`, `medium`, or `large`.
176
+ - `visibleItemCount` (`Number`): specify the number of thumbnail items to render around the active item. The default is calculated from the container width and the width of one thumbnail item.
167
177
 
168
178
  Specify the visibility of the navbar.
169
179
 
180
+ When setting a size, thumbnails use a $9 / 16$ width-to-height ratio.
181
+
182
+ ```js
183
+ navbar: {
184
+ show: true,
185
+ size: 'large',
186
+ }
187
+ ```
188
+
189
+ ### navigation
190
+
191
+ - Type: `Boolean` or `Number` or `Object`
192
+ - Default: `false`
193
+
194
+ - Options:
195
+ - `0` or `false`: hide the navigation buttons.
196
+ - `1` or `true`: show the navigation buttons.
197
+ - `2`: show the navigation buttons only when the screen width is greater than 768 pixels.
198
+ - `3`: show the navigation buttons only when the screen width is greater than 992 pixels.
199
+ - `4`: show the navigation buttons only when the screen width is greater than 1200 pixels.
200
+ - `{ prev: Boolean | Number | Object, next: Boolean | Number | Object }`: show or hide each navigation button.
201
+ - `{ prev: { show: Boolean | Number, size: String }, next: { show: Boolean | Number, size: String } }`: customize each navigation button.
202
+ - Available sizes: `small` (32px), `medium` (40px, default), and `large` (48px).
203
+
204
+ Show the previous and next buttons on the left and right sides of the viewer.
205
+
206
+ For example:
207
+
208
+ ```js
209
+ new Viewer(image, {
210
+ navigation: {
211
+ prev: {
212
+ size: 'large',
213
+ },
214
+ next: {
215
+ show: 2,
216
+ size: 'small',
217
+ },
218
+ },
219
+ });
220
+ ```
221
+
170
222
  ### title
171
223
 
172
224
  - Type: `Boolean` or `Number` or `Function` or `Array`
@@ -313,6 +365,13 @@ Define the initial index of the image for viewing.
313
365
 
314
366
  Enable inline mode.
315
367
 
368
+ ### autoplay
369
+
370
+ - Type: `Boolean`
371
+ - Default: `true`
372
+
373
+ Enable to automatically cycle the images when playing.
374
+
316
375
  ### interval
317
376
 
318
377
  - Type: `Number`
@@ -352,6 +411,13 @@ Indicate if enabling loop viewing or not.
352
411
 
353
412
  > If the current image is the last one, then the next one to view is the first one, and vice versa.
354
413
 
414
+ ### preload
415
+
416
+ - Type: `Boolean`
417
+ - Default: `true`
418
+
419
+ Enable to preload the next or previous image before viewing it.
420
+
355
421
  ### minWidth
356
422
 
357
423
  - Type: `Number`
@@ -377,6 +443,29 @@ Define the minimum height of the viewer.
377
443
 
378
444
  Enable to move the image.
379
445
 
446
+ ### magnifier
447
+
448
+ - Type: `Boolean` or `Object`
449
+ - Default: `false`
450
+ - Options:
451
+ - `size` (`Number`): the size of the magnifier in pixels. Defaults to `100`.
452
+ - `zoomRatio` (`Number`): the magnification ratio. Defaults to `2`.
453
+ - `opacity` (`Number`): the opacity of the magnifier, from `0` to `1`. Defaults to `1`.
454
+
455
+ Show a magnifier over the image when hovering in fullscreen mode. The magnifier is disabled on touch screens.
456
+
457
+ For example:
458
+
459
+ ```js
460
+ new Viewer(image, {
461
+ magnifier: {
462
+ size: 120,
463
+ zoomRatio: 3,
464
+ opacity: 0.8,
465
+ },
466
+ });
467
+ ```
468
+
380
469
  ### rotatable
381
470
 
382
471
  - Type: `Boolean`
@@ -384,6 +473,20 @@ Enable to move the image.
384
473
 
385
474
  Enable to rotate the image.
386
475
 
476
+ ### rotateOnGesture
477
+
478
+ - Type: `Boolean`
479
+ - Default: `true`
480
+
481
+ Enable to rotate the current image with gesture events, such as a two-finger gesture on Mac Safari.
482
+
483
+ ### rotateOnTouch
484
+
485
+ - Type: `Boolean`
486
+ - Default: `true`
487
+
488
+ Enable to rotate the current image with a two-finger gesture on a touch screen.
489
+
387
490
  ### scalable
388
491
 
389
492
  - Type: `Boolean`
@@ -398,6 +501,13 @@ Enable to scale the image.
398
501
 
399
502
  Enable to zoom the image.
400
503
 
504
+ ### zoomOnGesture
505
+
506
+ - Type: `Boolean`
507
+ - Default: `true`
508
+
509
+ Enable to zoom the current image with gesture events, such as a pinch gesture on Mac Safari.
510
+
401
511
  ### zoomOnTouch
402
512
 
403
513
  - Type: `Boolean`
@@ -439,11 +549,23 @@ Show the tooltip with image ratio (percentage) when zooming in or zooming out.
439
549
 
440
550
  ### transition
441
551
 
442
- - Type: `Boolean`
552
+ - Type: `Boolean` or `Object`
443
553
  - Default: `true`
444
554
 
445
555
  Enable CSS3 transitions for some special elements.
446
556
 
557
+ When passing an object, set a supported action to `false` to disable only its transition. The supported actions are `show`, `hide`, `view`, `move`, `zoom`, `rotate`, `scale`, `play`, and `tooltip`.
558
+
559
+ ```js
560
+ new Viewer(image, {
561
+ transition: {
562
+ hide: false,
563
+ view: false,
564
+ zoom: false,
565
+ },
566
+ });
567
+ ```
568
+
447
569
  ### zIndex
448
570
 
449
571
  - Type: `Number`
@@ -467,18 +589,38 @@ Define the ratio when zooming the image by wheeling the mouse.
467
589
 
468
590
  ### minZoomRatio
469
591
 
470
- - Type: `Number`
592
+ - Type: `Number` or `Function`
471
593
  - Default: `0.01`
472
594
 
473
595
  Define the min ratio of the image when zooming out.
474
596
 
597
+ If it is a function, it receives the current image and image data, and should return the minimum ratio:
598
+
599
+ ```js
600
+ new Viewer(image, {
601
+ minZoomRatio(image, imageData) {
602
+ return imageData.naturalWidth > 2000 ? 0.1 : 0.01;
603
+ },
604
+ });
605
+ ```
606
+
475
607
  ### maxZoomRatio
476
608
 
477
- - Type: `Number`
609
+ - Type: `Number` or `Function`
478
610
  - Default: `100`
479
611
 
480
612
  Define the max ratio of the image when zooming in.
481
613
 
614
+ If it is a function, it receives the current image and image data, and should return the maximum ratio:
615
+
616
+ ```js
617
+ new Viewer(image, {
618
+ maxZoomRatio(image, imageData) {
619
+ return imageData.naturalWidth > 2000 ? 2 : 10;
620
+ },
621
+ });
622
+ ```
623
+
482
624
  ### url
483
625
 
484
626
  - Type: `String` or `Function`
@@ -903,18 +1045,61 @@ Toggle the image size between its current size and natural size.
903
1045
 
904
1046
  Reset the image to its initial state.
905
1047
 
906
- ### update()
1048
+ ### update([options])
907
1049
 
908
- Update the viewer instance when the source images changed (added, removed, or sorted).
1050
+ Update the viewer instance when the source images changed (added, removed, or sorted), or update the options while the viewer is open.
909
1051
 
910
1052
  > If you load images dynamically (with XMLHTTPRequest), you can use this method to add the new images to the viewer instance.
911
1053
 
1054
+ ```js
1055
+ viewer.update({
1056
+ slideOnTouch: false,
1057
+ });
1058
+ ```
1059
+
912
1060
  ### destroy()
913
1061
 
914
1062
  Destroy the viewer and remove the instance.
915
1063
 
916
1064
  [⬆ back to top](#table-of-contents)
917
1065
 
1066
+ ## Static Methods
1067
+
1068
+ ### create(element[, options])
1069
+
1070
+ Create a new `Viewer` instance without using the `new` operator.
1071
+
1072
+ ```js
1073
+ const viewer = Viewer.create(image, {
1074
+ inline: true,
1075
+ });
1076
+ ```
1077
+
1078
+ ### setDefaults(options)
1079
+
1080
+ Change the global default options for subsequently created `Viewer` instances. Instance options override these defaults.
1081
+
1082
+ ```js
1083
+ Viewer.setDefaults({
1084
+ inline: true,
1085
+ });
1086
+ ```
1087
+
1088
+ ### noConflict
1089
+
1090
+ If you have to use another viewer with the same namespace, call the `Viewer.noConflict` static method to revert to it.
1091
+
1092
+ ```html
1093
+ <script src="other-viewer.js"></script>
1094
+ <script src="viewer.js"></script>
1095
+ <script>
1096
+ Viewer.noConflict();
1097
+ // Code that uses other `Viewer` can follow here.
1098
+ </script>
1099
+ ```
1100
+
1101
+ [⬆ back to top](#table-of-contents)
1102
+
918
1103
  ## Events
919
1104
 
920
1105
  All events can access the viewer instance with `this.viewer` in its handler.
@@ -1130,20 +1315,7 @@ This event fires when the viewer starts to stop.
1130
1315
 
1131
1316
  [⬆ back to top](#table-of-contents)
1132
1317
 
1133
- ## No conflict
1134
-
1135
- If you have to use another viewer with the same namespace, call the `Viewer.noConflict` static method to revert to it.
1136
-
1137
- ```html
1138
- <script src="other-viewer.js"></script>
1139
- <script src="viewer.js"></script>
1140
- <script>
1141
- Viewer.noConflict();
1142
- // Code that uses other `Viewer` can follow here.
1143
- </script>
1144
- ```
1145
-
1146
- ## Browser support
1318
+ ## Browser Support
1147
1319
 
1148
1320
  - Chrome (latest)
1149
1321
  - Firefox (latest)