From 5a5fe7a6fe1c4f6128bd6b579799e8a7aef6ba9a Mon Sep 17 00:00:00 2001 From: Dean Shi Date: Fri, 4 Aug 2017 00:42:16 -0700 Subject: [PATCH] Update video.js --- src/video.js | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/video.js b/src/video.js index d6b3231..decc7c3 100644 --- a/src/video.js +++ b/src/video.js @@ -1,11 +1,11 @@ class Video { - constructor (videos, duration) { + constructor (videos, duration = 0) { this.videos = videos; this.multi = this.videos.length > 1; this.index = 0; this.current = this.videos[this.index]; - this.duration = duration || 0; + this.duration = duration; this.durationArr = []; this.eventAll = []; this.eventCurrent = []; @@ -44,18 +44,11 @@ class Video { // bind event on (type, event, callback) { if (typeof callback === 'function') { - if (type === 'all') { - if (!this.eventAll[event]) { - this.eventAll[event] = []; - } - this.eventAll[event].push(callback); - } - else { - if (!this.eventCurrent[event]) { - this.eventCurrent[event] = []; - } - this.eventCurrent[event].push(callback); + const events = type === 'all' ? this.eventAll : this.eventCurrent; + if (!events[event]) { + events[event] = []; } + events[event].push(callback); if (['seeking'].indexOf(event) === -1) { for (let i = 0; i < this.videos.length; i++) { @@ -134,4 +127,4 @@ class Video { } } -module.exports = Video; \ No newline at end of file +module.exports = Video;