mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-25 16:11: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
@@ -20,6 +20,7 @@ import {
|
||||
inverseClass,
|
||||
createElement,
|
||||
includeFromEvent,
|
||||
getComposedPath,
|
||||
} from '../utils';
|
||||
|
||||
export default class Control extends Component {
|
||||
@@ -265,7 +266,7 @@ export default class Control extends Component {
|
||||
}
|
||||
|
||||
const event = proxy($list, 'click', async (event) => {
|
||||
const path = event.composedPath() || [];
|
||||
const path = getComposedPath(event);
|
||||
const item = option.selector.find(
|
||||
(item) => item.$control_item === path.find(($item) => item.$control_item === $item),
|
||||
);
|
||||
|
||||
@@ -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