Skip to content

Commit 6283892

Browse files
committed
build: release 1.7.0
1 parent 5b0a6d3 commit 6283892

16 files changed

+3770
-2515
lines changed

CHANGELOG.md

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

3-
## next
3+
## 1.7.0 (Sep 26, 2020)
44

55
- Add 2 new events: `play` and `stop` (#411).
66
- Let the `viewed`, `zoomed` and `hidden` events can not be canceled.
77
- Improve the TypeScript declarations in the `types/index.d.ts` file.
88

9-
## 1.6.2 (Sep 30, 2020)
9+
## 1.6.2 (Aug 30, 2020)
1010

1111
- Fix wrong usage about `this` in ES6+ (#395).
1212
- Improve the wheel zoom behavior (#396).

dist/viewer.common.js

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*!
2-
* Viewer.js v1.6.2
2+
* Viewer.js v1.7.0
33
* https://fengyuanchen.github.io/viewerjs
44
*
55
* Copyright 2015-present Chen Fengyuan
66
* Released under the MIT license
77
*
8-
* Date: 2020-08-30T02:33:40.250Z
8+
* Date: 2020-09-26T06:58:07.157Z
99
*/
1010

1111
'use strict';
@@ -316,7 +316,9 @@ var DEFAULTS = {
316316
view: null,
317317
viewed: null,
318318
zoom: null,
319-
zoomed: null
319+
zoomed: null,
320+
play: null,
321+
stop: null
320322
};
321323

322324
var TEMPLATE = '<div class="viewer-container" touch-action="none">' + '<div class="viewer-canvas"></div>' + '<div class="viewer-footer">' + '<div class="viewer-title"></div>' + '<div class="viewer-toolbar"></div>' + '<div class="viewer-navbar">' + '<ul class="viewer-list"></ul>' + '</div>' + '</div>' + '<div class="viewer-tooltip"></div>' + '<div role="button" class="viewer-button" data-viewer-action="mix"></div>' + '<div class="viewer-player"></div>' + '</div>';
@@ -371,7 +373,9 @@ var EVENT_VIEW = 'view';
371373
var EVENT_VIEWED = 'viewed';
372374
var EVENT_WHEEL = 'wheel';
373375
var EVENT_ZOOM = 'zoom';
374-
var EVENT_ZOOMED = 'zoomed'; // Data keys
376+
var EVENT_ZOOMED = 'zoomed';
377+
var EVENT_PLAY = 'play';
378+
var EVENT_STOP = 'stop'; // Data keys
375379

376380
var DATA_ACTION = "".concat(NAMESPACE, "Action"); // RegExps
377381

@@ -780,18 +784,19 @@ function addListener(element, type, listener) {
780784
* @param {Element} element - The event target.
781785
* @param {string} type - The event type(s).
782786
* @param {Object} data - The additional event data.
787+
* @param {Object} options - The additional event options.
783788
* @returns {boolean} Indicate if the event is default prevented or not.
784789
*/
785790

786-
function dispatchEvent(element, type, data) {
791+
function dispatchEvent(element, type, data, options) {
787792
var event; // Event and CustomEvent on IE9-11 are global objects, not constructors
788793

789794
if (isFunction(Event) && isFunction(CustomEvent)) {
790-
event = new CustomEvent(type, {
791-
detail: data,
795+
event = new CustomEvent(type, _objectSpread2({
792796
bubbles: true,
793-
cancelable: true
794-
});
797+
cancelable: true,
798+
detail: data
799+
}, options));
795800
} else {
796801
event = document.createEvent('CustomEvent');
797802
event.initCustomEvent(type, true, true, data);
@@ -1430,6 +1435,8 @@ var handlers = {
14301435
originalImage: _this.images[index],
14311436
index: index,
14321437
image: image
1438+
}, {
1439+
cancelable: false
14331440
});
14341441
});
14351442
});
@@ -2217,6 +2224,8 @@ var methods = {
22172224
ratio: ratio,
22182225
oldRatio: oldRatio,
22192226
originalEvent: _originalEvent
2227+
}, {
2228+
cancelable: false
22202229
});
22212230
});
22222231

@@ -2322,8 +2331,20 @@ var methods = {
23222331
return this;
23232332
}
23242333

2325-
var options = this.options,
2326-
player = this.player;
2334+
var element = this.element,
2335+
options = this.options;
2336+
2337+
if (isFunction(options.play)) {
2338+
addListener(element, EVENT_PLAY, options.play, {
2339+
once: true
2340+
});
2341+
}
2342+
2343+
if (dispatchEvent(element, EVENT_PLAY) === false) {
2344+
return this;
2345+
}
2346+
2347+
var player = this.player;
23272348
var onLoad = this.loadImage.bind(this);
23282349
var list = [];
23292350
var total = 0;
@@ -2384,6 +2405,19 @@ var methods = {
23842405
return this;
23852406
}
23862407

2408+
var element = this.element,
2409+
options = this.options;
2410+
2411+
if (isFunction(options.stop)) {
2412+
addListener(element, EVENT_STOP, options.stop, {
2413+
once: true
2414+
});
2415+
}
2416+
2417+
if (dispatchEvent(element, EVENT_STOP) === false) {
2418+
return this;
2419+
}
2420+
23872421
var player = this.player;
23882422
this.played = false;
23892423
clearTimeout(this.playing);
@@ -2595,17 +2629,18 @@ var methods = {
25952629
this.length = images.length;
25962630

25972631
if (this.ready) {
2598-
var indexes = [];
2632+
var changedIndexes = [];
25992633
forEach(this.items, function (item, i) {
26002634
var img = item.querySelector('img');
26012635
var image = images[i];
26022636

26032637
if (image && img) {
2604-
if (image.src !== img.src) {
2605-
indexes.push(i);
2638+
if (image.src !== img.src // Title changed (#408)
2639+
|| image.alt !== img.alt) {
2640+
changedIndexes.push(i);
26062641
}
26072642
} else {
2608-
indexes.push(i);
2643+
changedIndexes.push(i);
26092644
}
26102645
});
26112646
setStyle(this.list, {
@@ -2616,12 +2651,13 @@ var methods = {
26162651
if (this.isShown) {
26172652
if (this.length) {
26182653
if (this.viewed) {
2619-
var index = indexes.indexOf(this.index);
2654+
var changedIndex = changedIndexes.indexOf(this.index);
26202655

2621-
if (index >= 0) {
2656+
if (changedIndex >= 0) {
26222657
this.viewed = false;
2623-
this.view(Math.max(this.index - (index + 1), 0));
2658+
this.view(Math.max(Math.min(this.index - changedIndex, this.length - 1), 0));
26242659
} else {
2660+
// Reactivate the current viewing item after reset the list.
26252661
addClass(this.items[this.index], CLASS_ACTIVE);
26262662
}
26272663
}
@@ -2767,7 +2803,9 @@ var others = {
27672803
});
27682804
}
27692805

2770-
dispatchEvent(element, EVENT_HIDDEN);
2806+
dispatchEvent(element, EVENT_HIDDEN, null, {
2807+
cancelable: false
2808+
});
27712809
}
27722810
},
27732811
requestFullscreen: function requestFullscreen() {

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.6.2
2+
* Viewer.js v1.7.0
33
* https://fengyuanchen.github.io/viewerjs
44
*
55
* Copyright 2015-present Chen Fengyuan
66
* Released under the MIT license
77
*
8-
* Date: 2020-08-30T02:26:54.370Z
8+
* Date: 2020-09-26T06:58:02.142Z
99
*/
1010

1111
.viewer-zoom-in::before,

dist/viewer.esm.js

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*!
2-
* Viewer.js v1.6.2
2+
* Viewer.js v1.7.0
33
* https://fengyuanchen.github.io/viewerjs
44
*
55
* Copyright 2015-present Chen Fengyuan
66
* Released under the MIT license
77
*
8-
* Date: 2020-08-30T02:33:40.250Z
8+
* Date: 2020-09-26T06:58:07.157Z
99
*/
1010

1111
function _typeof(obj) {
@@ -314,7 +314,9 @@ var DEFAULTS = {
314314
view: null,
315315
viewed: null,
316316
zoom: null,
317-
zoomed: null
317+
zoomed: null,
318+
play: null,
319+
stop: null
318320
};
319321

320322
var TEMPLATE = '<div class="viewer-container" touch-action="none">' + '<div class="viewer-canvas"></div>' + '<div class="viewer-footer">' + '<div class="viewer-title"></div>' + '<div class="viewer-toolbar"></div>' + '<div class="viewer-navbar">' + '<ul class="viewer-list"></ul>' + '</div>' + '</div>' + '<div class="viewer-tooltip"></div>' + '<div role="button" class="viewer-button" data-viewer-action="mix"></div>' + '<div class="viewer-player"></div>' + '</div>';
@@ -369,7 +371,9 @@ var EVENT_VIEW = 'view';
369371
var EVENT_VIEWED = 'viewed';
370372
var EVENT_WHEEL = 'wheel';
371373
var EVENT_ZOOM = 'zoom';
372-
var EVENT_ZOOMED = 'zoomed'; // Data keys
374+
var EVENT_ZOOMED = 'zoomed';
375+
var EVENT_PLAY = 'play';
376+
var EVENT_STOP = 'stop'; // Data keys
373377

374378
var DATA_ACTION = "".concat(NAMESPACE, "Action"); // RegExps
375379

@@ -778,18 +782,19 @@ function addListener(element, type, listener) {
778782
* @param {Element} element - The event target.
779783
* @param {string} type - The event type(s).
780784
* @param {Object} data - The additional event data.
785+
* @param {Object} options - The additional event options.
781786
* @returns {boolean} Indicate if the event is default prevented or not.
782787
*/
783788

784-
function dispatchEvent(element, type, data) {
789+
function dispatchEvent(element, type, data, options) {
785790
var event; // Event and CustomEvent on IE9-11 are global objects, not constructors
786791

787792
if (isFunction(Event) && isFunction(CustomEvent)) {
788-
event = new CustomEvent(type, {
789-
detail: data,
793+
event = new CustomEvent(type, _objectSpread2({
790794
bubbles: true,
791-
cancelable: true
792-
});
795+
cancelable: true,
796+
detail: data
797+
}, options));
793798
} else {
794799
event = document.createEvent('CustomEvent');
795800
event.initCustomEvent(type, true, true, data);
@@ -1428,6 +1433,8 @@ var handlers = {
14281433
originalImage: _this.images[index],
14291434
index: index,
14301435
image: image
1436+
}, {
1437+
cancelable: false
14311438
});
14321439
});
14331440
});
@@ -2215,6 +2222,8 @@ var methods = {
22152222
ratio: ratio,
22162223
oldRatio: oldRatio,
22172224
originalEvent: _originalEvent
2225+
}, {
2226+
cancelable: false
22182227
});
22192228
});
22202229

@@ -2320,8 +2329,20 @@ var methods = {
23202329
return this;
23212330
}
23222331

2323-
var options = this.options,
2324-
player = this.player;
2332+
var element = this.element,
2333+
options = this.options;
2334+
2335+
if (isFunction(options.play)) {
2336+
addListener(element, EVENT_PLAY, options.play, {
2337+
once: true
2338+
});
2339+
}
2340+
2341+
if (dispatchEvent(element, EVENT_PLAY) === false) {
2342+
return this;
2343+
}
2344+
2345+
var player = this.player;
23252346
var onLoad = this.loadImage.bind(this);
23262347
var list = [];
23272348
var total = 0;
@@ -2382,6 +2403,19 @@ var methods = {
23822403
return this;
23832404
}
23842405

2406+
var element = this.element,
2407+
options = this.options;
2408+
2409+
if (isFunction(options.stop)) {
2410+
addListener(element, EVENT_STOP, options.stop, {
2411+
once: true
2412+
});
2413+
}
2414+
2415+
if (dispatchEvent(element, EVENT_STOP) === false) {
2416+
return this;
2417+
}
2418+
23852419
var player = this.player;
23862420
this.played = false;
23872421
clearTimeout(this.playing);
@@ -2593,17 +2627,18 @@ var methods = {
25932627
this.length = images.length;
25942628

25952629
if (this.ready) {
2596-
var indexes = [];
2630+
var changedIndexes = [];
25972631
forEach(this.items, function (item, i) {
25982632
var img = item.querySelector('img');
25992633
var image = images[i];
26002634

26012635
if (image && img) {
2602-
if (image.src !== img.src) {
2603-
indexes.push(i);
2636+
if (image.src !== img.src // Title changed (#408)
2637+
|| image.alt !== img.alt) {
2638+
changedIndexes.push(i);
26042639
}
26052640
} else {
2606-
indexes.push(i);
2641+
changedIndexes.push(i);
26072642
}
26082643
});
26092644
setStyle(this.list, {
@@ -2614,12 +2649,13 @@ var methods = {
26142649
if (this.isShown) {
26152650
if (this.length) {
26162651
if (this.viewed) {
2617-
var index = indexes.indexOf(this.index);
2652+
var changedIndex = changedIndexes.indexOf(this.index);
26182653

2619-
if (index >= 0) {
2654+
if (changedIndex >= 0) {
26202655
this.viewed = false;
2621-
this.view(Math.max(this.index - (index + 1), 0));
2656+
this.view(Math.max(Math.min(this.index - changedIndex, this.length - 1), 0));
26222657
} else {
2658+
// Reactivate the current viewing item after reset the list.
26232659
addClass(this.items[this.index], CLASS_ACTIVE);
26242660
}
26252661
}
@@ -2765,7 +2801,9 @@ var others = {
27652801
});
27662802
}
27672803

2768-
dispatchEvent(element, EVENT_HIDDEN);
2804+
dispatchEvent(element, EVENT_HIDDEN, null, {
2805+
cancelable: false
2806+
});
27692807
}
27702808
},
27712809
requestFullscreen: function requestFullscreen() {

0 commit comments

Comments
 (0)