white-ui-kit
Version:
Модуль компонентов UI Имя модуля: `white-ui-kit`
29 lines (24 loc) • 791 B
text/typescript
// Хелпер событий
export class EventHelper {
/**
* Получить путь из Node по событию
* @param event - событие
*/
public static path(event: MouseEvent | any): Node[] {
const target = event.target || event.srcElement || event.currentTarget;
const composedPath = event.composedPath && event.composedPath();
const path = composedPath || event.path;
if (path) {
// Safari fix
return (path.indexOf(window) === -1)
? path.concat(window)
: path;
}
const getParents = (node: Node, memo: Node[] = []): Node[] => (
node.parentNode
? getParents(node.parentNode, memo.concat(node.parentNode))
: memo
);
return [target].concat(getParents(target), window);
}
}