forked from dequelabs/axe-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelement-matches.js
More file actions
42 lines (36 loc) · 870 Bytes
/
element-matches.js
File metadata and controls
42 lines (36 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* Polyfill for Element#matches
* @param {HTMLElement} node The element to test
* @param {String} selector The selector to test element against
* @return {Boolean}
*/
const matchesSelector = (() => {
let method;
function getMethod(node) {
const candidates = [
'matches',
'matchesSelector',
'mozMatchesSelector',
'webkitMatchesSelector',
'msMatchesSelector'
];
const length = candidates.length;
let index, candidate;
for (index = 0; index < length; index++) {
candidate = candidates[index];
if (node[candidate]) {
return candidate;
}
}
}
return (node, selector) => {
if (!method || !node[method]) {
method = getMethod(node);
}
if (node[method]) {
return node[method](selector);
}
return false;
};
})();
export default matchesSelector;