Merge pull request #114 from dnshi/code-simplified

Simplify video.js
This commit is contained in:
DIYgod 2017-08-04 15:47:39 +08:00 committed by GitHub
commit 163d6aea39
1 changed files with 7 additions and 14 deletions

View File

@ -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;
module.exports = Video;