-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
contextmenu module and hotkey module
- Loading branch information
Showing
6 changed files
with
114 additions
and
95 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
class ContextMenu { | ||
constructor (player) { | ||
this.player = player; | ||
|
||
this.player.container.addEventListener('contextmenu', (e) => { | ||
const event = e || window.event; | ||
event.preventDefault(); | ||
|
||
const clientRect = this.player.container.getBoundingClientRect(); | ||
this.show(event.clientX - clientRect.left, event.clientY - clientRect.top); | ||
|
||
this.player.template.mask.addEventListener('click', () => { | ||
this.hide(); | ||
}); | ||
}); | ||
} | ||
|
||
show (x, y) { | ||
this.player.template.menu.classList.add('dplayer-menu-show'); | ||
|
||
const clientRect = this.player.container.getBoundingClientRect(); | ||
if (x + this.player.template.menu.offsetWidth >= clientRect.width) { | ||
this.player.template.menu.style.right = clientRect.width - x + 'px'; | ||
this.player.template.menu.style.left = 'initial'; | ||
} | ||
else { | ||
this.player.template.menu.style.left = x + 'px'; | ||
this.player.template.menu.style.right = 'initial'; | ||
} | ||
if (y + this.player.template.menu.offsetHeight >= clientRect.height) { | ||
this.player.template.menu.style.bottom = clientRect.height - y + 'px'; | ||
this.player.template.menu.style.top = 'initial'; | ||
} | ||
else { | ||
this.player.template.menu.style.top = y + 'px'; | ||
this.player.template.menu.style.bottom = 'initial'; | ||
} | ||
|
||
this.player.template.mask.classList.add('dplayer-mask-show'); | ||
|
||
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.player.events.trigger('contextmenu_hide'); | ||
} | ||
} | ||
|
||
module.exports = ContextMenu; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
class HotKey { | ||
constructor (player) { | ||
if (player.options.hotkey) { | ||
document.addEventListener('keydown', (e) => { | ||
if (player.focus) { | ||
const tag = document.activeElement.tagName.toUpperCase(); | ||
const editable = document.activeElement.getAttribute('contenteditable'); | ||
if (tag !== 'INPUT' && tag !== 'TEXTAREA' && editable !== '' && editable !== 'true') { | ||
const event = e || window.event; | ||
let percentage; | ||
switch (event.keyCode) { | ||
case 32: | ||
event.preventDefault(); | ||
player.toggle(); | ||
break; | ||
case 37: | ||
event.preventDefault(); | ||
player.seek(player.video.currentTime - 5); | ||
player.controller.setAutoHide(); | ||
break; | ||
case 39: | ||
event.preventDefault(); | ||
player.seek(player.video.currentTime + 5); | ||
player.controller.setAutoHide(); | ||
break; | ||
case 38: | ||
event.preventDefault(); | ||
percentage = player.volume() + 0.1; | ||
player.volume(percentage); | ||
break; | ||
case 40: | ||
event.preventDefault(); | ||
percentage = player.volume() - 0.1; | ||
player.volume(percentage); | ||
break; | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
|
||
document.addEventListener('keydown', (e) => { | ||
const event = e || window.event; | ||
switch (event.keyCode) { | ||
case 27: | ||
if (player.fullScreen.isFullScreen('web')) { | ||
player.fullScreen.cancel('web'); | ||
} | ||
break; | ||
} | ||
}); | ||
} | ||
} | ||
|
||
module.exports = HotKey; |