Skip to content

Commit

Permalink
Merge pull request #114 from dnshi/code-simplified
Browse files Browse the repository at this point in the history
Simplify video.js
  • Loading branch information
DIYgod authored Aug 4, 2017
2 parents 4b9b1fb + 5a5fe7a commit 163d6ae
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/video.js
Original file line number Diff line number Diff line change
@@ -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 = [];
Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -134,4 +127,4 @@ class Video {
}
}

module.exports = Video;
module.exports = Video;

0 comments on commit 163d6ae

Please sign in to comment.