mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-25 08:01:20 -08:00
feat: Refactor global event handling in ArtPlayer
- Introduced a new globalInit function to manage document and window events. - Replaced direct event proxies with a unified bindGlobalEvents method. - Updated event handling in various modules to utilize the new global event system. - Removed the deprecated documentInit module. - Bumped version to 5.2.6 in package.json.
This commit is contained in:
1 parent
abd64e11f2
commit
8af6f7c322
18 files changed
+142
-62
No files matched your search
@@ -0,0 +1,49 @@
|
||||
export default function globalInit(art, events) {
|
||||
const documentEvents = [
|
||||
'click',
|
||||
'mouseup',
|
||||
'keydown',
|
||||
'touchend',
|
||||
'touchmove',
|
||||
'mousemove',
|
||||
'contextmenu',
|
||||
'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
|
||||
}
|
||||
Reference in new issue
Block a user