Skip to content

Commit

Permalink
Merge pull request #373 from EYHN/master
Browse files Browse the repository at this point in the history
Right click 2 times to open the browser's native context menu.
  • Loading branch information
DIYgod authored Sep 9, 2018
2 parents 0f3bd57 + 419fcb9 commit 01ab283
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/js/contextmenu.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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();

Expand Down Expand Up @@ -47,13 +53,15 @@ class ContextMenu {

this.player.template.mask.classList.add('dplayer-mask-show');

this.shown = true;
this.player.events.trigger('contextmenu_show');
}

hide () {
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');
}
}
Expand Down

0 comments on commit 01ab283

Please sign in to comment.