1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-03 09:49:20 +02:00

Fix settings menu escape key

This commit is contained in:
Chocobozzz 2025-07-08 11:07:18 +02:00
parent c958f6271f
commit 91002ac042
No known key found for this signature in database
GPG key ID: 583A612D890159BE
5 changed files with 34 additions and 30 deletions

View file

@ -11,8 +11,7 @@ class P2PInfoButton extends Button {
}) as HTMLDivElement }) as HTMLDivElement
div.appendChild(subDivP2P) div.appendChild(subDivP2P)
const downloadIcon = videojs.dom.createEl('span', { const downloadIcon = videojs.dom.createEl('span', { className: 'icon icon-download' }, {
className: 'icon icon-download',
role: 'img', role: 'img',
ariaLabel: this.player().localize('Download speed:') ariaLabel: this.player().localize('Download speed:')
}) })
@ -25,10 +24,9 @@ class P2PInfoButton extends Button {
downloadSpeedText.appendChild(downloadSpeedUnit) downloadSpeedText.appendChild(downloadSpeedUnit)
subDivP2P.appendChild(downloadSpeedText) subDivP2P.appendChild(downloadSpeedText)
const uploadIcon = videojs.dom.createEl('span', { const uploadIcon = videojs.dom.createEl('span', { className: 'icon icon-upload' }, {
role: 'img', role: 'img',
ariaLabel: this.player().localize('Upload speed:'), ariaLabel: this.player().localize('Upload speed:')
className: 'icon icon-upload'
}) })
subDivP2P.appendChild(uploadIcon) subDivP2P.appendChild(uploadIcon)

View file

@ -254,6 +254,7 @@ class PeerTubePlugin extends Plugin {
if (isMobile()) this.player.addClass('vjs-is-mobile') if (isMobile()) this.player.addClass('vjs-is-mobile')
this.initSmoothProgressBar() this.initSmoothProgressBar()
this.patchMenuEscapeKey()
this.player.ready(() => { this.player.ready(() => {
this.listenControlBarMouse() this.listenControlBarMouse()
@ -654,6 +655,22 @@ class PeerTubePlugin extends Plugin {
} }
} }
private patchMenuEscapeKey () {
const Menu = videojs.getComponent('Menu') as any
const fn = Menu.prototype.handleKeyDown
Menu.prototype.handleKeyDown = function handleKeyDown (event: KeyboardEvent) {
if (event.key === 'Escape') {
event.preventDefault()
event.stopPropagation()
this.trigger('escaped-key')
return
}
fn.call(this, event)
}
}
private getCaptionsButton () { private getCaptionsButton () {
const settingsButton = this.player.controlBar.getDescendant([ 'settingsButton' ]) as SettingsButton const settingsButton = this.player.controlBar.getDescendant([ 'settingsButton' ]) as SettingsButton

View file

@ -8,20 +8,6 @@ const Component = videojs.getComponent('Component')
class MenuFocusFixed extends Menu { class MenuFocusFixed extends Menu {
declare private focusedChild_: number declare private focusedChild_: number
handleKeyDown (event: KeyboardEvent) {
if (event.key === 'Escape') {
event.preventDefault()
event.stopPropagation()
this.trigger('escaped-key')
return
}
// FIXME: super misses handleKeyDown
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
return super.handleKeyDown(event)
}
stepForward () { stepForward () {
let stepChild = 0 let stepChild = 0

View file

@ -145,7 +145,6 @@ class SettingsButton extends Button {
showDialog () { showDialog () {
this.player().peertube().onMenuOpened() this.player().peertube().onMenuOpened()
;(this.menu.el() as HTMLElement).style.opacity = '1' ;(this.menu.el() as HTMLElement).style.opacity = '1'
this.dialog.show() this.dialog.show()
@ -252,6 +251,11 @@ class SettingsButton extends Button {
// Whether to add or remove selected class on the settings sub menu element // Whether to add or remove selected class on the settings sub menu element
settingsMenuItem.on('click', openSubMenu) settingsMenuItem.on('click', openSubMenu)
settingsMenuItem.on('escaped-key', () => {
this.hideDialog()
this.focus()
})
} }
resetChildren () { resetChildren () {

View file

@ -139,7 +139,6 @@ class SettingsMenuItem extends MenuItem {
/** /**
* Create the component's DOM element * Create the component's DOM element
*
*/ */
createEl () { createEl () {
const el = videojs.dom.createEl('li', { const el = videojs.dom.createEl('li', {
@ -176,9 +175,8 @@ class SettingsMenuItem extends MenuItem {
// Remove open class to ensure only the open submenu gets this class // Remove open class to ensure only the open submenu gets this class
videojs.dom.removeClass(this.el(), 'open') videojs.dom.removeClass(this.el(), 'open')
super.handleClick(event); super.handleClick(event)
;(this.mainMenu.el() as HTMLElement).style.opacity = '0'
(this.mainMenu.el() as HTMLElement).style.opacity = '0'
// Whether to add or remove vjs-hidden class on the settingsSubMenuEl element // Whether to add or remove vjs-hidden class on the settingsSubMenuEl element
if (videojs.dom.hasClass(this.settingsSubMenuEl_, 'vjs-hidden')) { if (videojs.dom.hasClass(this.settingsSubMenuEl_, 'vjs-hidden')) {
videojs.dom.removeClass(this.settingsSubMenuEl_, 'vjs-hidden') videojs.dom.removeClass(this.settingsSubMenuEl_, 'vjs-hidden')
@ -206,9 +204,8 @@ class SettingsMenuItem extends MenuItem {
const button = this.subMenu.menu.addChild('MenuItem', {}, 0) const button = this.subMenu.menu.addChild('MenuItem', {}, 0)
button.setAttribute('aria-label', this.player().localize('Go back')) button.setAttribute('aria-label', this.player().localize('Go back'))
button.addClass('vjs-back-button'); button.addClass('vjs-back-button')
;(button.el() as HTMLElement).innerHTML = this.player().localize(this.subMenu.controlText())
(button.el() as HTMLElement).innerHTML = this.player().localize(this.subMenu.controlText())
} }
onTransitionEnd (event: any) { onTransitionEnd (event: any) {
@ -284,7 +281,6 @@ class SettingsMenuItem extends MenuItem {
const subMenuItemExtended = subMenuItem as MenuItemExtended const subMenuItemExtended = subMenuItem as MenuItemExtended
if (subMenuItemExtended.isSelected_) { if (subMenuItemExtended.isSelected_) {
// Prefer to use the function // Prefer to use the function
if (typeof subMenuItemExtended.getLabel === 'function') { if (typeof subMenuItemExtended.getLabel === 'function') {
this.settingsSubMenuValueEl_.innerHTML = subMenuItemExtended.getLabel() this.settingsSubMenuValueEl_.innerHTML = subMenuItemExtended.getLabel()
@ -354,6 +350,10 @@ class SettingsMenuItem extends MenuItem {
private rebuildAfterMenuChange () { private rebuildAfterMenuChange () {
debugLogger('Rebuilding menu ' + this.subMenu.name() + ' after change') debugLogger('Rebuilding menu ' + this.subMenu.name() + ' after change')
this.subMenu.menu.on('escaped-key', () => {
this.trigger('escaped-key')
})
this.settingsSubMenuEl_.innerHTML = '' this.settingsSubMenuEl_.innerHTML = ''
this.settingsSubMenuEl_.appendChild(this.subMenu.menu.el()) this.settingsSubMenuEl_.appendChild(this.subMenu.menu.el())
this.update() this.update()
@ -361,10 +361,9 @@ class SettingsMenuItem extends MenuItem {
this.setSize() this.setSize()
this.bindClickEvents() this.bindClickEvents()
} }
} }
(SettingsMenuItem as any).prototype.contentElType = 'button' ;(SettingsMenuItem as any).prototype.contentElType = 'button'
videojs.registerComponent('SettingsMenuItem', SettingsMenuItem) videojs.registerComponent('SettingsMenuItem', SettingsMenuItem)
export { SettingsMenuItem } export { SettingsMenuItem }