refactor(animations): single animation engine code pass
This commit is contained in:

committed by
Jason Aden

parent
16c8167886
commit
8a6eb1ac78
@ -114,3 +114,44 @@ export function parseTimelineCommand(command: string): [string, string] {
|
||||
const action = command.substr(separatorPos + 1);
|
||||
return [id, action];
|
||||
}
|
||||
|
||||
let _contains: (elm1: any, elm2: any) => boolean = (elm1: any, elm2: any) => false;
|
||||
let _matches: (element: any, selector: string) => boolean = (element: any, selector: string) =>
|
||||
false;
|
||||
let _query: (element: any, selector: string, multi: boolean) => any[] =
|
||||
(element: any, selector: string, multi: boolean) => {
|
||||
return [];
|
||||
};
|
||||
|
||||
if (typeof Element != 'undefined') {
|
||||
// this is well supported in all browsers
|
||||
_contains = (elm1: any, elm2: any) => { return elm1.contains(elm2) as boolean; };
|
||||
|
||||
if (Element.prototype.matches) {
|
||||
_matches = (element: any, selector: string) => element.matches(selector);
|
||||
} else {
|
||||
const proto = Element.prototype as any;
|
||||
const fn = proto.matchesSelector || proto.mozMatchesSelector || proto.msMatchesSelector ||
|
||||
proto.oMatchesSelector || proto.webkitMatchesSelector;
|
||||
if (fn) {
|
||||
_matches = (element: any, selector: string) => fn.apply(element, [selector]);
|
||||
}
|
||||
}
|
||||
|
||||
_query = (element: any, selector: string, multi: boolean): any[] => {
|
||||
let results: any[] = [];
|
||||
if (multi) {
|
||||
results.push(...element.querySelectorAll(selector));
|
||||
} else {
|
||||
const elm = element.querySelector(selector);
|
||||
if (elm) {
|
||||
results.push(elm);
|
||||
}
|
||||
}
|
||||
return results;
|
||||
};
|
||||
}
|
||||
|
||||
export const matchesElement = _matches;
|
||||
export const containsElement = _contains;
|
||||
export const invokeQuery = _query;
|
||||
|
Reference in New Issue
Block a user