1 | function polyfill(window) {
|
2 | var ElementPrototype = window.Element.prototype;
|
3 |
|
4 | if (typeof ElementPrototype.matches !== 'function') {
|
5 | ElementPrototype.matches = ElementPrototype.msMatchesSelector || ElementPrototype.mozMatchesSelector || ElementPrototype.webkitMatchesSelector || function matches(selector) {
|
6 | var element = this;
|
7 | var elements = (element.document || element.ownerDocument).querySelectorAll(selector);
|
8 | var index = 0;
|
9 |
|
10 | while (elements[index] && elements[index] !== element) {
|
11 | ++index;
|
12 | }
|
13 |
|
14 | return Boolean(elements[index]);
|
15 | };
|
16 | }
|
17 |
|
18 | if (typeof ElementPrototype.closest !== 'function') {
|
19 | ElementPrototype.closest = function closest(selector) {
|
20 | var element = this;
|
21 |
|
22 | while (element && element.nodeType === 1) {
|
23 | if (element.matches(selector)) {
|
24 | return element;
|
25 | }
|
26 |
|
27 | element = element.parentNode;
|
28 | }
|
29 |
|
30 | return null;
|
31 | };
|
32 | }
|
33 | }
|
34 |
|
35 | export default polyfill;
|
36 |
|