1 | /**
|
2 | * source by `dom-closest`
|
3 | * https://github.com/necolas/dom-closest.git
|
4 | */
|
5 | import matches from './dom-matches';
|
6 | /**
|
7 | * @param element {Element}
|
8 | * @param selector {String}
|
9 | * @param context {Element=}
|
10 | * @return {Element}
|
11 | */
|
12 |
|
13 | export default function (element, selector, context) {
|
14 | context = context || document; // guard against orphans
|
15 |
|
16 | element = {
|
17 | parentNode: element
|
18 | };
|
19 |
|
20 | while ((element = element.parentNode) && element !== context) {
|
21 | if (matches(element, selector)) {
|
22 | return element;
|
23 | }
|
24 | }
|
25 | } |
\ | No newline at end of file |