浏览代码

Merge pull request #373 from EYHN/master

Right click 2 times to open the browser's native context menu.
DIYgod 7 年之前
父节点
当前提交
01ab283368
共有 1 个文件被更改,包括 8 次插入0 次删除
  1. 8 0
      src/js/contextmenu.js

+ 8 - 0
src/js/contextmenu.js

@@ -1,6 +1,7 @@
 class ContextMenu {
     constructor (player) {
         this.player = player;
+        this.shown = false;
 
         Array.prototype.slice.call(this.player.template.menuItem).forEach((item, index) => {
             if (this.player.options.contextmenu[index].click) {
@@ -12,6 +13,11 @@ class ContextMenu {
         });
 
         this.player.container.addEventListener('contextmenu', (e) => {
+            if (this.shown) {
+                this.hide();
+                return;
+            }
+            
             const event = e || window.event;
             event.preventDefault();
 
@@ -47,6 +53,7 @@ class ContextMenu {
 
         this.player.template.mask.classList.add('dplayer-mask-show');
 
+        this.shown = true;
         this.player.events.trigger('contextmenu_show');
     }
 
@@ -54,6 +61,7 @@ class ContextMenu {
         this.player.template.mask.classList.remove('dplayer-mask-show');
         this.player.template.menu.classList.remove('dplayer-menu-show');
 
+        this.shown = false;
         this.player.events.trigger('contextmenu_hide');
     }
 }