1
1
/*!
2
- * Viewer.js v1.5 .0
2
+ * Viewer.js v1.6 .0
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: 2019-11-23T05:10 :26.193Z
8
+ * Date: 2020-06-06T11:26 :26.858Z
9
9
*/
10
10
11
11
'use strict' ;
12
12
13
13
function _typeof ( obj ) {
14
+ "@babel/helpers - typeof" ;
15
+
14
16
if ( typeof Symbol === "function" && typeof Symbol . iterator === "symbol" ) {
15
17
_typeof = function ( obj ) {
16
18
return typeof obj ;
@@ -151,6 +153,12 @@ var DEFAULTS = {
151
153
*/
152
154
fullscreen : true ,
153
155
156
+ /**
157
+ * Define the extra attributes to inherit from the original image.
158
+ * @type {Array }
159
+ */
160
+ inheritedAttributes : [ 'crossOrigin' , 'decoding' , 'isMap' , 'loading' , 'referrerPolicy' , 'sizes' , 'srcset' , 'useMap' ] ,
161
+
154
162
/**
155
163
* Define the initial index of image for viewing.
156
164
* @type {number }
@@ -315,7 +323,7 @@ var TEMPLATE = '<div class="viewer-container" touch-action="none">' + '<div clas
315
323
316
324
var IS_BROWSER = typeof window !== 'undefined' && typeof window . document !== 'undefined' ;
317
325
var WINDOW = IS_BROWSER ? window : { } ;
318
- var IS_TOUCH_DEVICE = IS_BROWSER ? 'ontouchstart' in WINDOW . document . documentElement : false ;
326
+ var IS_TOUCH_DEVICE = IS_BROWSER && WINDOW . document . documentElement ? 'ontouchstart' in WINDOW . document . documentElement : false ;
319
327
var HAS_POINTER_EVENT = IS_BROWSER ? 'PointerEvent' in WINDOW : false ;
320
328
var NAMESPACE = 'viewer' ; // Actions
321
329
@@ -862,11 +870,12 @@ var IS_SAFARI = WINDOW.navigator && /(Macintosh|iPhone|iPod|iPad).*AppleWebKit/i
862
870
/**
863
871
* Get an image's natural sizes.
864
872
* @param {string } image - The target image.
873
+ * @param {Object } options - The viewer options.
865
874
* @param {Function } callback - The callback function.
866
875
* @returns {HTMLImageElement } The new image.
867
876
*/
868
877
869
- function getImageNaturalSizes ( image , callback ) {
878
+ function getImageNaturalSizes ( image , options , callback ) {
870
879
var newImage = document . createElement ( 'img' ) ; // Modern browsers (except Safari)
871
880
872
881
if ( image . naturalWidth && ! IS_SAFARI ) {
@@ -884,6 +893,13 @@ function getImageNaturalSizes(image, callback) {
884
893
}
885
894
} ;
886
895
896
+ forEach ( options . inheritedAttributes , function ( name ) {
897
+ var value = image . getAttribute ( name ) ;
898
+
899
+ if ( value !== null ) {
900
+ newImage . setAttribute ( name , value ) ;
901
+ }
902
+ } ) ;
887
903
newImage . src = image . src ; // iOS Safari will convert the image automatically
888
904
// with its orientation once append it into DOM
889
905
@@ -995,6 +1011,14 @@ var render = {
995
1011
this . initList ( ) ;
996
1012
this . renderViewer ( ) ;
997
1013
} ,
1014
+ initBody : function initBody ( ) {
1015
+ var ownerDocument = this . element . ownerDocument ;
1016
+ var body = ownerDocument . body || ownerDocument . documentElement ;
1017
+ this . body = body ;
1018
+ this . scrollbarWidth = window . innerWidth - ownerDocument . documentElement . clientWidth ;
1019
+ this . initialBodyPaddingRight = body . style . paddingRight ;
1020
+ this . initialBodyComputedPaddingRight = window . getComputedStyle ( body ) . paddingRight ;
1021
+ } ,
998
1022
initContainer : function initContainer ( ) {
999
1023
this . containerData = {
1000
1024
width : window . innerWidth ,
@@ -1048,6 +1072,13 @@ var render = {
1048
1072
if ( src || url ) {
1049
1073
var item = document . createElement ( 'li' ) ;
1050
1074
var img = document . createElement ( 'img' ) ;
1075
+ forEach ( options . inheritedAttributes , function ( name ) {
1076
+ var value = image . getAttribute ( name ) ;
1077
+
1078
+ if ( value !== null ) {
1079
+ img . setAttribute ( name , value ) ;
1080
+ }
1081
+ } ) ;
1051
1082
img . src = src || url ;
1052
1083
img . alt = alt ;
1053
1084
img . setAttribute ( 'data-index' , index ) ;
@@ -1123,7 +1154,7 @@ var render = {
1123
1154
sizingImage . onload = null ;
1124
1155
}
1125
1156
} ;
1126
- sizingImage = getImageNaturalSizes ( image , function ( naturalWidth , naturalHeight ) {
1157
+ sizingImage = getImageNaturalSizes ( image , options , function ( naturalWidth , naturalHeight ) {
1127
1158
var aspectRatio = naturalWidth / naturalHeight ;
1128
1159
var width = viewerWidth ;
1129
1160
var height = viewerHeight ;
@@ -1414,7 +1445,7 @@ var handlers = {
1414
1445
var parentWidth = parent . offsetWidth || 30 ;
1415
1446
var parentHeight = parent . offsetHeight || 50 ;
1416
1447
var filled = ! ! getData ( image , 'filled' ) ;
1417
- getImageNaturalSizes ( image , function ( naturalWidth , naturalHeight ) {
1448
+ getImageNaturalSizes ( image , this . options , function ( naturalWidth , naturalHeight ) {
1418
1449
var aspectRatio = naturalWidth / naturalHeight ;
1419
1450
var width = parentWidth ;
1420
1451
var height = parentHeight ;
@@ -1640,6 +1671,12 @@ var handlers = {
1640
1671
return ;
1641
1672
}
1642
1673
1674
+ if ( this . fulled ) {
1675
+ this . close ( ) ;
1676
+ this . initBody ( ) ;
1677
+ this . open ( ) ;
1678
+ }
1679
+
1643
1680
this . initContainer ( ) ;
1644
1681
this . initViewer ( ) ;
1645
1682
this . renderViewer ( ) ;
@@ -1801,7 +1838,7 @@ var methods = {
1801
1838
1802
1839
var viewer = this . viewer ;
1803
1840
1804
- if ( options . transition && ! immediate ) {
1841
+ if ( options . transition && hasClass ( this . image , CLASS_TRANSITION ) && ! immediate ) {
1805
1842
var hidden = this . hidden . bind ( this ) ;
1806
1843
1807
1844
var hide = function hide ( ) {
@@ -1824,7 +1861,7 @@ var methods = {
1824
1861
}
1825
1862
} ; // Note that the `CLASS_TRANSITION` class will be removed on pointer down (#255)
1826
1863
1827
- if ( this . viewed && hasClass ( this . image , CLASS_TRANSITION ) ) {
1864
+ if ( this . viewed ) {
1828
1865
addListener ( this . image , EVENT_TRANSITION_END , hide , {
1829
1866
once : true
1830
1867
} ) ;
@@ -1873,6 +1910,13 @@ var methods = {
1873
1910
var url = getData ( img , 'originalUrl' ) ;
1874
1911
var alt = img . getAttribute ( 'alt' ) ;
1875
1912
var image = document . createElement ( 'img' ) ;
1913
+ forEach ( options . inheritedAttributes , function ( name ) {
1914
+ var value = img . getAttribute ( name ) ;
1915
+
1916
+ if ( value !== null ) {
1917
+ image . setAttribute ( name , value ) ;
1918
+ }
1919
+ } ) ;
1876
1920
image . src = url ;
1877
1921
image . alt = alt ;
1878
1922
@@ -2286,6 +2330,7 @@ var methods = {
2286
2330
var image = document . createElement ( 'img' ) ;
2287
2331
image . src = getData ( img , 'originalUrl' ) ;
2288
2332
image . alt = img . getAttribute ( 'alt' ) ;
2333
+ image . referrerPolicy = img . referrerPolicy ;
2289
2334
total += 1 ;
2290
2335
addClass ( image , CLASS_FADE ) ;
2291
2336
toggleClass ( image , CLASS_TRANSITION , options . transition ) ;
@@ -2646,7 +2691,7 @@ var others = {
2646
2691
open : function open ( ) {
2647
2692
var body = this . body ;
2648
2693
addClass ( body , CLASS_OPEN ) ;
2649
- body . style . paddingRight = "" . concat ( this . scrollbarWidth + ( parseFloat ( this . initialBodyPaddingRight ) || 0 ) , "px" ) ;
2694
+ body . style . paddingRight = "" . concat ( this . scrollbarWidth + ( parseFloat ( this . initialBodyComputedPaddingRight ) || 0 ) , "px" ) ;
2650
2695
} ,
2651
2696
close : function close ( ) {
2652
2697
var body = this . body ;
@@ -2785,9 +2830,7 @@ var others = {
2785
2830
2786
2831
var AnotherViewer = WINDOW . Viewer ;
2787
2832
2788
- var Viewer =
2789
- /*#__PURE__*/
2790
- function ( ) {
2833
+ var Viewer = /*#__PURE__*/ function ( ) {
2791
2834
/**
2792
2835
* Create a new Viewer.
2793
2836
* @param {Element } element - The target element for viewing.
@@ -2848,18 +2891,14 @@ function () {
2848
2891
if ( options . filter . call ( _this , image ) ) {
2849
2892
images . push ( image ) ;
2850
2893
}
2851
- } else {
2894
+ } else if ( image . src ) {
2852
2895
images . push ( image ) ;
2853
2896
}
2854
2897
} ) ;
2855
2898
this . isImg = isImg ;
2856
2899
this . length = images . length ;
2857
2900
this . images = images ;
2858
- var ownerDocument = element . ownerDocument ;
2859
- var body = ownerDocument . body || ownerDocument . documentElement ;
2860
- this . body = body ;
2861
- this . scrollbarWidth = window . innerWidth - ownerDocument . documentElement . clientWidth ;
2862
- this . initialBodyPaddingRight = window . getComputedStyle ( body ) . paddingRight ; // Override `transition` option if it is not supported
2901
+ this . initBody ( ) ; // Override `transition` option if it is not supported
2863
2902
2864
2903
if ( isUndefined ( document . createElement ( NAMESPACE ) . style . transition ) ) {
2865
2904
options . transition = false ;
0 commit comments