浏览代码

trigger info panel

DIYgod 7 年之前
父节点
当前提交
77a2ba88b4
共有 7 个文件被更改,包括 48 次插入2 次删除
  1. 2 1
      src/css/index.scss
  2. 10 0
      src/css/info-panel.scss
  3. 1 0
      src/js/contextmenu.js
  4. 29 0
      src/js/info-panel.js
  5. 1 1
      src/js/options.js
  6. 3 0
      src/js/player.js
  7. 2 0
      src/js/template.js

+ 2 - 1
src/css/index.scss

@@ -8,4 +8,5 @@
 @import './menu';
 @import './menu';
 @import './notice';
 @import './notice';
 @import './subtitle';
 @import './subtitle';
-@import './video';
+@import './video';
+@import './info-panel';

+ 10 - 0
src/css/info-panel.scss

@@ -0,0 +1,10 @@
+.dplayer-info-panel {
+    position: absolute;
+    top: 10px;
+    left: 10px;
+    width: 400px;
+
+    &-hide {
+        display: none;
+    }
+}

+ 1 - 0
src/js/contextmenu.js

@@ -6,6 +6,7 @@ class ContextMenu {
             if (this.player.options.contextmenu[index].click) {
             if (this.player.options.contextmenu[index].click) {
                 item.addEventListener('click', () => {
                 item.addEventListener('click', () => {
                     this.player.options.contextmenu[index].click(this.player);
                     this.player.options.contextmenu[index].click(this.player);
+                    this.hide();
                 });
                 });
             }
             }
             return item;
             return item;

+ 29 - 0
src/js/info-panel.js

@@ -0,0 +1,29 @@
+class InfoPanel {
+    constructor (player) {
+        this.container = player.template.infoPanel;
+        this.video = player.video;
+    }
+
+    show () {
+        this.container.classList.remove('dplayer-info-panel-hide');
+    }
+
+    hide () {
+        this.container.classList.add('dplayer-info-panel-hide');
+    }
+
+    triggle () {
+        if (this.container.classList.contains('dplayer-info-panel-hide')) {
+            this.show();
+        }
+        else {
+            this.hide();
+        }
+    }
+
+    update () {
+
+    }
+}
+
+export default InfoPanel;

+ 1 - 1
src/js/options.js

@@ -124,7 +124,7 @@ export default (options) => {
         {
         {
             text: 'Video info',
             text: 'Video info',
             click: (player) => {
             click: (player) => {
-                player.infoPanel.show();
+                player.infoPanel.triggle();
             }
             }
         },
         },
         {
         {

+ 3 - 0
src/js/player.js

@@ -18,6 +18,7 @@ import Setting from './setting';
 import Comment from './comment';
 import Comment from './comment';
 import HotKey from './hotkey';
 import HotKey from './hotkey';
 import ContextMenu from './contextmenu';
 import ContextMenu from './contextmenu';
+import InfoPanel from './info-panel';
 
 
 let index = 0;
 let index = 0;
 const instances = [];
 const instances = [];
@@ -131,6 +132,8 @@ class DPlayer {
 
 
         this.initVideo(this.video, this.quality && this.quality.type || this.options.video.type);
         this.initVideo(this.video, this.quality && this.quality.type || this.options.video.type);
 
 
+        this.infoPanel = new InfoPanel(this);
+
         if (!this.danmaku && this.options.autoplay) {
         if (!this.danmaku && this.options.autoplay) {
             this.play();
             this.play();
         }
         }

+ 2 - 0
src/js/template.js

@@ -66,6 +66,7 @@ class Template {
         this.barPreview = this.container.querySelector('.dplayer-bar-preview');
         this.barPreview = this.container.querySelector('.dplayer-bar-preview');
         this.barWrap = this.container.querySelector('.dplayer-bar-wrap');
         this.barWrap = this.container.querySelector('.dplayer-bar-wrap');
         this.notice = this.container.querySelector('.dplayer-notice');
         this.notice = this.container.querySelector('.dplayer-notice');
+        this.infoPanel = this.container.querySelector('.dplayer-info-panel');
     }
     }
 
 
     tpl (options, index, tran, icons) {
     tpl (options, index, tran, icons) {
@@ -299,6 +300,7 @@ class Template {
                 </div>
                 </div>
             </div>
             </div>
         </div>
         </div>
+        <div class="dplayer-info-panel dplayer-info-panel-hide"></div>
         ${this.tplContextmenuList(options.contextmenu, tran)}
         ${this.tplContextmenuList(options.contextmenu, tran)}
         <div class="dplayer-notice"></div>`;
         <div class="dplayer-notice"></div>`;
     }
     }