mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-23 22:01:20 -08:00
Refactor event path handling to use getComposedPath utility
- Replaced direct usage of event.composedPath() with a new utility function getComposedPath in Control component. - Updated includeFromEvent function to utilize getComposedPath for better compatibility. - Implemented getComposedPath function to ensure consistent event path retrieval across different browsers.
This commit is contained in:
1 parent
412b8e7fa7
commit
05ce97c6fd
12 files changed
+41
-14
No files matched your search
@@ -76,7 +76,7 @@ export function isInViewport(el, offset = 0) {
|
||||
}
|
||||
|
||||
export function includeFromEvent(event, target) {
|
||||
return event.composedPath && event.composedPath().indexOf(target) > -1;
|
||||
return getComposedPath(event).indexOf(target) > -1;
|
||||
}
|
||||
|
||||
export function replaceElement(newChild, oldChild) {
|
||||
@@ -161,3 +161,17 @@ export function loadImg(url, scale) {
|
||||
img.src = url;
|
||||
});
|
||||
}
|
||||
|
||||
export function getComposedPath(event) {
|
||||
if (event.composedPath) return event.composedPath();
|
||||
const path = [];
|
||||
let node = event.target;
|
||||
while (node) {
|
||||
path.push(node);
|
||||
node = node.parentNode;
|
||||
}
|
||||
if (path.indexOf(window) === -1 && window !== undefined) {
|
||||
path.push(window);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
Reference in new issue
Block a user