DIYgod 6 éve
szülő
commit
d30fa4e176
5 módosított fájl, 35 hozzáadás és 32 törlés
  1. 2 1
      .eslintrc
  2. 2 2
      src/js/controller.js
  3. 4 4
      src/js/info-panel.js
  4. 13 15
      src/js/player.js
  5. 14 10
      src/js/timer.js

+ 2 - 1
.eslintrc

@@ -49,7 +49,8 @@
         "no-useless-computed-key": 1,
         "no-useless-rename": 1,
         "rest-spread-spacing": 1,
-        "no-trailing-spaces": 1
+        "no-trailing-spaces": 1,
+        "quotes": [1, "single"]
     },
     "globals": {
         "require": false,

+ 2 - 2
src/js/controller.js

@@ -89,11 +89,11 @@ class Controller {
             percentage = Math.min(percentage, 1);
             this.player.bar.set('played', percentage, 'width');
             this.player.seek(this.player.bar.get('played') * this.player.video.duration);
-            this.player.time.enable('progress');
+            this.player.timer.enable('progress');
         };
 
         this.player.template.playedBarWrap.addEventListener(utils.nameMap.dragStart, () => {
-            this.player.time.disable('progress');
+            this.player.timer.disable('progress');
             document.addEventListener(utils.nameMap.dragMove, thumbMove);
             document.addEventListener(utils.nameMap.dragEnd, thumbUp);
         });

+ 4 - 4
src/js/info-panel.js

@@ -15,14 +15,14 @@ class InfoPanel {
     show () {
         this.beginTime = Date.now();
         this.update();
-        this.player.time.enable('info');
-        this.player.time.enable('fps');
+        this.player.timer.enable('info');
+        this.player.timer.enable('fps');
         this.container.classList.remove('dplayer-info-panel-hide');
     }
 
     hide () {
-        this.player.time.disable('info');
-        this.player.time.disable('fps');
+        this.player.timer.disable('info');
+        this.player.timer.disable('fps');
         this.container.classList.add('dplayer-info-panel-hide');
     }
 

+ 13 - 15
src/js/player.js

@@ -11,7 +11,7 @@ import FullScreen from './fullscreen';
 import User from './user';
 import Subtitle from './subtitle';
 import Bar from './bar';
-import Time from './time';
+import Timer from './timer';
 import Bezel from './bezel';
 import Controller from './controller';
 import Setting from './setting';
@@ -123,7 +123,7 @@ class DPlayer {
 
         this.paused = true;
 
-        this.time = new Time(this);
+        this.timer = new Timer(this);
 
         this.hotkey = new HotKey(this);
 
@@ -163,6 +163,7 @@ class DPlayer {
         }
 
         this.bar.set('played', time / this.video.duration, 'width');
+        this.template.ptime.innerHTML = utils.secondToTime(time);
     }
 
     /**
@@ -181,8 +182,8 @@ class DPlayer {
             this.pause();
         }).then(() => {
         });
-        this.time.enable('loading');
-        this.time.enable('progress');
+        this.timer.enable('loading');
+        this.timer.enable('progress');
         this.container.classList.remove('dplayer-paused');
         this.container.classList.add('dplayer-playing');
         if (this.danmaku) {
@@ -208,11 +209,11 @@ class DPlayer {
             this.bezel.switch(Icons.pause);
         }
 
-        this.ended = false;
         this.template.playButton.innerHTML = Icons.play;
         this.video.pause();
-        this.time.disable('loading');
-        this.time.disable('progress');
+        this.player.container.classList.remove('dplayer-loading');  // TODO
+        this.timer.disable('loading');
+        this.timer.disable('progress');
         this.container.classList.remove('dplayer-playing');
         this.container.classList.add('dplayer-paused');
         if (this.danmaku) {
@@ -436,11 +437,9 @@ class DPlayer {
         });
 
         // video end
-        this.ended = false;
         this.on('ended', () => {
             this.bar.set('played', 1, 'width');
             if (!this.setting.loop) {
-                this.ended = true;
                 this.pause();
             }
             else {
@@ -558,16 +557,15 @@ class DPlayer {
         instances.splice(instances.indexOf(this), 1);
         this.pause();
         this.controller.destroy();
-        this.time.destroy();
+        this.timer.destroy();
         this.video.src = '';
         this.container.innerHTML = '';
         this.events.trigger('destroy');
+    }
 
-        for (const key in this) {
-            if (this.hasOwnProperty(key) && key !== 'paused') {
-                delete this[key];
-            }
-        }
+    static get version () {
+        /* global DPLAYER_VERSION */
+        return DPLAYER_VERSION;
     }
 }
 

+ 14 - 10
src/js/time.js → src/js/timer.js

@@ -1,6 +1,6 @@
 import utils from './utils';
 
-class Time {
+class Timer {
     constructor (player) {
         this.player = player;
 
@@ -21,12 +21,12 @@ class Time {
     }
 
     init () {
-        for (let i = 0; i < this.types.length; i++) {
-            const type = this.types[i];
-            if (type !== 'fps') {
-                this[`init${type}Checker`]();
+        this.types.map((item) => {
+            if (item !== 'fps') {
+                this[`init${item}Checker`]();
             }
-        }
+            return item;
+        });
     }
 
     initloadingChecker () {
@@ -60,7 +60,7 @@ class Time {
                 this.player.bar.set('played', this.player.video.currentTime / this.player.video.duration, 'width');
                 const currentTime = utils.secondToTime(this.player.video.currentTime);
                 if (this.player.template.ptime.innerHTML !== currentTime) {
-                    this.player.template.ptime.innerHTML = utils.secondToTime(this.player.video.currentTime);
+                    this.player.template.ptime.innerHTML = currentTime;
                 }
             }
         }, 100);
@@ -111,9 +111,13 @@ class Time {
         this[`enable${type}Checker`] = false;
     }
 
-    destroy (type) {
-        this[`${type}Checker`] && clearInterval(this[`${type}Checker`]);
+    destroy () {
+        this.types.map((item) => {
+            this[`enable${item}Checker`] = false;
+            this[`${item}Checker`] && clearInterval(this[`${item}Checker`]);
+            return item;
+        });
     }
 }
 
-export default Time;
+export default Timer;