UNPKG

@helpscout/hsds-react

Version:

React component library for Help Scout's Design System

38 lines (29 loc) 1.17 kB
"use strict"; exports.__esModule = true; exports.matches = matches; exports.closest = closest; exports.default = void 0; /* istanbul ignore file */ // Source // https://github.com/ForbesLindesay/closest var proto = typeof Element !== 'undefined' ? Element.prototype : {}; var vendor = proto['matches'] || proto['matchesSelector'] || proto['webkitMatchesSelector'] || proto['mozMatchesSelector'] || proto['msMatchesSelector'] || proto['oMatchesSelector']; function matches(el, selector) { if (!el || el.nodeType !== 1) return false; if (vendor) return vendor.call(el, selector); if (!el.parentNode) return false; var nodes = el.parentNode.querySelectorAll(selector); for (var i = 0; i < nodes.length; i++) { if (nodes[i] == el) return true; } return false; } // TODO: remove, move to Beacon (src/components/PreviousMessages/PreviousMessages.LoadMore.js) function closest(element, selector, checkYoSelf) { var parent = checkYoSelf ? element : element.parentNode; while (parent && parent !== document) { if (matches(parent, selector)) return parent; parent = parent.parentNode; } } var _default = closest; exports.default = _default;