From 419fcb9c10779108fe5b3762a09dc007fd784b6c Mon Sep 17 00:00:00 2001 From: eyhn Date: Sun, 9 Sep 2018 14:10:20 +0800 Subject: [PATCH] the browser's native context menu close #369 --- src/js/contextmenu.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/js/contextmenu.js b/src/js/contextmenu.js index 82bb67864..08a2f943f 100644 --- a/src/js/contextmenu.js +++ b/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'); } }