|
@@ -240,15 +240,53 @@ export function objToArray(obj) {
|
|
|
return isEmpty(obj) ? [] : [obj];
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * 新的兼容获取 event.path 方法
|
|
|
+ * https://stackoverflow.com/questions/39245488/event-path-is-undefined-running-in-firefox
|
|
|
+ * @param evt
|
|
|
+ * @returns {Window[]|*|*[]}
|
|
|
+ */
|
|
|
+export function eventPath(evt) {
|
|
|
+ let path = (evt.composedPath && evt.composedPath()) || evt.path;
|
|
|
+ let target = evt.target;
|
|
|
+
|
|
|
+ if (path != null) {
|
|
|
+ // Safari doesn't include Window, but it should.
|
|
|
+ return (path.indexOf(window) < 0) ? path.concat(window) : path;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (target === window) {
|
|
|
+ return [window];
|
|
|
+ }
|
|
|
+
|
|
|
+ function getParents(node, memo) {
|
|
|
+ memo = memo || [];
|
|
|
+ let parentNode = node.parentNode;
|
|
|
+
|
|
|
+ if (!parentNode) {
|
|
|
+ return memo;
|
|
|
+ } else {
|
|
|
+ return getParents(parentNode, memo.concat(parentNode));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return [target].concat(getParents(target), window);
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 用于修复 el-popover el-select 等弹出层事件
|
|
|
+ * @param e
|
|
|
+ * @returns {*}
|
|
|
+ */
|
|
|
export function calcShadowRootEvent(e) {
|
|
|
if (!e) return;
|
|
|
let event = e.target;
|
|
|
if (e.target.shadowRoot && e.target.shadowRoot.toString() === '[object ShadowRoot]') {
|
|
|
- let eventPath = e.composedPath();
|
|
|
- if (!eventPath.length) {
|
|
|
- eventPath = e.path;
|
|
|
+ let eventPaths = eventPath(e);
|
|
|
+ if (eventPaths.length > 1) {
|
|
|
+ event = eventPaths[1];
|
|
|
}
|
|
|
- event = eventPath[0];
|
|
|
+ event = eventPaths[0];
|
|
|
}
|
|
|
return event;
|
|
|
}
|