You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
864 B
33 lines
864 B
var DOCUMENT_NODE_TYPE = 9; |
|
|
|
/** |
|
* A polyfill for Element.matches() |
|
*/ |
|
if (typeof Element !== 'undefined' && !Element.prototype.matches) { |
|
var proto = Element.prototype; |
|
|
|
proto.matches = proto.matchesSelector || |
|
proto.mozMatchesSelector || |
|
proto.msMatchesSelector || |
|
proto.oMatchesSelector || |
|
proto.webkitMatchesSelector; |
|
} |
|
|
|
/** |
|
* Finds the closest parent that matches a selector. |
|
* |
|
* @param {Element} element |
|
* @param {String} selector |
|
* @return {Function} |
|
*/ |
|
function closest (element, selector) { |
|
while (element && element.nodeType !== DOCUMENT_NODE_TYPE) { |
|
if (typeof element.matches === 'function' && |
|
element.matches(selector)) { |
|
return element; |
|
} |
|
element = element.parentNode; |
|
} |
|
} |
|
|
|
module.exports = closest;
|
|
|