Skip to content

Commit 66c87ef

Browse files
committed
build: release 1.6.0
1 parent 039c40a commit 66c87ef

File tree

13 files changed

+5027
-5903
lines changed

13 files changed

+5027
-5903
lines changed

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Changelog
22

3-
## next
3+
## 1.6.0 (Jun 6, 2020)
44

55
- Add a new options: `inheritedAttributes`.
66
- Ignore images without the `src` attribute (#326).
@@ -10,9 +10,9 @@
1010

1111
## 1.5.0 (Nov 23, 2019)
1212

13-
- Force reflow element in a new way to avoid side effect (#343).
14-
- Add a new option: `slideOnTouch` (#340).
1513
- Detect if the queried image is existing when update image list (#333).
14+
- Add a new option: `slideOnTouch` (#340).
15+
- Force reflow element in a new way to avoid side effect (#343).
1616

1717
## 1.4.0 (Oct 26, 2019)
1818

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
## Features
2626

27-
- Supports 42 [options](#options)
27+
- Supports 43 [options](#options)
2828
- Supports 23 [methods](#methods)
2929
- Supports 9 [events](#events)
3030
- Supports modal and inline modes
@@ -253,7 +253,7 @@ The container to put the viewer in modal mode.
253253
- Type: `Function`
254254
- Default: `null`
255255

256-
Filter the images for viewing (should return `true` if the image is viewable).
256+
Filter the images for viewing (should return `true` if the image is viewable, return `false` to ignore the image).
257257

258258
For example:
259259

@@ -265,6 +265,8 @@ new Viewer(image, {
265265
});
266266
```
267267

268+
> Note that images without the `src` attribute set will be ignored by default.
269+
268270
### fullscreen
269271

270272
- Type: `Boolean`

dist/viewer.common.js

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
/*!
2-
* Viewer.js v1.5.0
2+
* Viewer.js v1.6.0
33
* https://fengyuanchen.github.io/viewerjs
44
*
55
* Copyright 2015-present Chen Fengyuan
66
* Released under the MIT license
77
*
8-
* Date: 2019-11-23T05:10:26.193Z
8+
* Date: 2020-06-06T11:26:26.858Z
99
*/
1010

1111
'use strict';
1212

1313
function _typeof(obj) {
14+
"@babel/helpers - typeof";
15+
1416
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
1517
_typeof = function (obj) {
1618
return typeof obj;
@@ -151,6 +153,12 @@ var DEFAULTS = {
151153
*/
152154
fullscreen: true,
153155

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+
154162
/**
155163
* Define the initial index of image for viewing.
156164
* @type {number}
@@ -315,7 +323,7 @@ var TEMPLATE = '<div class="viewer-container" touch-action="none">' + '<div clas
315323

316324
var IS_BROWSER = typeof window !== 'undefined' && typeof window.document !== 'undefined';
317325
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;
319327
var HAS_POINTER_EVENT = IS_BROWSER ? 'PointerEvent' in WINDOW : false;
320328
var NAMESPACE = 'viewer'; // Actions
321329

@@ -862,11 +870,12 @@ var IS_SAFARI = WINDOW.navigator && /(Macintosh|iPhone|iPod|iPad).*AppleWebKit/i
862870
/**
863871
* Get an image's natural sizes.
864872
* @param {string} image - The target image.
873+
* @param {Object} options - The viewer options.
865874
* @param {Function} callback - The callback function.
866875
* @returns {HTMLImageElement} The new image.
867876
*/
868877

869-
function getImageNaturalSizes(image, callback) {
878+
function getImageNaturalSizes(image, options, callback) {
870879
var newImage = document.createElement('img'); // Modern browsers (except Safari)
871880

872881
if (image.naturalWidth && !IS_SAFARI) {
@@ -884,6 +893,13 @@ function getImageNaturalSizes(image, callback) {
884893
}
885894
};
886895

896+
forEach(options.inheritedAttributes, function (name) {
897+
var value = image.getAttribute(name);
898+
899+
if (value !== null) {
900+
newImage.setAttribute(name, value);
901+
}
902+
});
887903
newImage.src = image.src; // iOS Safari will convert the image automatically
888904
// with its orientation once append it into DOM
889905

@@ -995,6 +1011,14 @@ var render = {
9951011
this.initList();
9961012
this.renderViewer();
9971013
},
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+
},
9981022
initContainer: function initContainer() {
9991023
this.containerData = {
10001024
width: window.innerWidth,
@@ -1048,6 +1072,13 @@ var render = {
10481072
if (src || url) {
10491073
var item = document.createElement('li');
10501074
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+
});
10511082
img.src = src || url;
10521083
img.alt = alt;
10531084
img.setAttribute('data-index', index);
@@ -1123,7 +1154,7 @@ var render = {
11231154
sizingImage.onload = null;
11241155
}
11251156
};
1126-
sizingImage = getImageNaturalSizes(image, function (naturalWidth, naturalHeight) {
1157+
sizingImage = getImageNaturalSizes(image, options, function (naturalWidth, naturalHeight) {
11271158
var aspectRatio = naturalWidth / naturalHeight;
11281159
var width = viewerWidth;
11291160
var height = viewerHeight;
@@ -1414,7 +1445,7 @@ var handlers = {
14141445
var parentWidth = parent.offsetWidth || 30;
14151446
var parentHeight = parent.offsetHeight || 50;
14161447
var filled = !!getData(image, 'filled');
1417-
getImageNaturalSizes(image, function (naturalWidth, naturalHeight) {
1448+
getImageNaturalSizes(image, this.options, function (naturalWidth, naturalHeight) {
14181449
var aspectRatio = naturalWidth / naturalHeight;
14191450
var width = parentWidth;
14201451
var height = parentHeight;
@@ -1640,6 +1671,12 @@ var handlers = {
16401671
return;
16411672
}
16421673

1674+
if (this.fulled) {
1675+
this.close();
1676+
this.initBody();
1677+
this.open();
1678+
}
1679+
16431680
this.initContainer();
16441681
this.initViewer();
16451682
this.renderViewer();
@@ -1801,7 +1838,7 @@ var methods = {
18011838

18021839
var viewer = this.viewer;
18031840

1804-
if (options.transition && !immediate) {
1841+
if (options.transition && hasClass(this.image, CLASS_TRANSITION) && !immediate) {
18051842
var hidden = this.hidden.bind(this);
18061843

18071844
var hide = function hide() {
@@ -1824,7 +1861,7 @@ var methods = {
18241861
}
18251862
}; // Note that the `CLASS_TRANSITION` class will be removed on pointer down (#255)
18261863

1827-
if (this.viewed && hasClass(this.image, CLASS_TRANSITION)) {
1864+
if (this.viewed) {
18281865
addListener(this.image, EVENT_TRANSITION_END, hide, {
18291866
once: true
18301867
});
@@ -1873,6 +1910,13 @@ var methods = {
18731910
var url = getData(img, 'originalUrl');
18741911
var alt = img.getAttribute('alt');
18751912
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+
});
18761920
image.src = url;
18771921
image.alt = alt;
18781922

@@ -2286,6 +2330,7 @@ var methods = {
22862330
var image = document.createElement('img');
22872331
image.src = getData(img, 'originalUrl');
22882332
image.alt = img.getAttribute('alt');
2333+
image.referrerPolicy = img.referrerPolicy;
22892334
total += 1;
22902335
addClass(image, CLASS_FADE);
22912336
toggleClass(image, CLASS_TRANSITION, options.transition);
@@ -2646,7 +2691,7 @@ var others = {
26462691
open: function open() {
26472692
var body = this.body;
26482693
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");
26502695
},
26512696
close: function close() {
26522697
var body = this.body;
@@ -2785,9 +2830,7 @@ var others = {
27852830

27862831
var AnotherViewer = WINDOW.Viewer;
27872832

2788-
var Viewer =
2789-
/*#__PURE__*/
2790-
function () {
2833+
var Viewer = /*#__PURE__*/function () {
27912834
/**
27922835
* Create a new Viewer.
27932836
* @param {Element} element - The target element for viewing.
@@ -2848,18 +2891,14 @@ function () {
28482891
if (options.filter.call(_this, image)) {
28492892
images.push(image);
28502893
}
2851-
} else {
2894+
} else if (image.src) {
28522895
images.push(image);
28532896
}
28542897
});
28552898
this.isImg = isImg;
28562899
this.length = images.length;
28572900
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
28632902

28642903
if (isUndefined(document.createElement(NAMESPACE).style.transition)) {
28652904
options.transition = false;

dist/viewer.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*!
2-
* Viewer.js v1.5.0
2+
* Viewer.js v1.6.0
33
* https://fengyuanchen.github.io/viewerjs
44
*
55
* Copyright 2015-present Chen Fengyuan
66
* Released under the MIT license
77
*
8-
* Date: 2019-11-23T05:10:21.757Z
8+
* Date: 2020-06-06T11:26:24.345Z
99
*/
1010

1111
.viewer-zoom-in::before,

0 commit comments

Comments
 (0)