mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-23 13:51:20 -08:00
- Changed event handling from `art.proxy` to `art.on` for visibility change and pointer events in the ads and danmuku plugins to improve consistency and maintainability. - Bumped version of the danmuku plugin from 5.1.8 to 5.1.9. - Added pointer events to the global event initialization in the core to ensure proper event handling across the application.
53 lines
1.2 KiB
JavaScript
53 lines
1.2 KiB
JavaScript
export default function globalInit(art, events) {
|
|
const documentEvents = [
|
|
'click',
|
|
'mouseup',
|
|
'keydown',
|
|
'touchend',
|
|
'touchmove',
|
|
'mousemove',
|
|
'pointerup',
|
|
'contextmenu',
|
|
'pointermove',
|
|
'visibilitychange',
|
|
'webkitfullscreenchange',
|
|
]
|
|
|
|
const windowEvents = [
|
|
'resize',
|
|
'scroll',
|
|
'orientationchange',
|
|
]
|
|
|
|
const destroyEvents = []
|
|
|
|
function bindGlobalEvents(source = {}) {
|
|
for (let index = 0; index < destroyEvents.length; index++) {
|
|
events.remove(destroyEvents[index])
|
|
}
|
|
|
|
destroyEvents.length = 0
|
|
|
|
const { $player } = art.template
|
|
|
|
documentEvents.forEach((name) => {
|
|
const doc = source.document || $player.ownerDocument || document
|
|
const destroy = events.proxy(doc, name, (event) => {
|
|
art.emit(`document:${name}`, event)
|
|
})
|
|
destroyEvents.push(destroy)
|
|
})
|
|
|
|
windowEvents.forEach((name) => {
|
|
const win = source.window || $player.ownerDocument?.defaultView || window
|
|
const destroy = events.proxy(win, name, (event) => {
|
|
art.emit(`window:${name}`, event)
|
|
})
|
|
destroyEvents.push(destroy)
|
|
})
|
|
}
|
|
|
|
bindGlobalEvents()
|
|
events.bindGlobalEvents = bindGlobalEvents
|
|
}
|