UNPKG

@angular-mdc/web

Version:
68 lines (66 loc) 2 kB
/** * @license * Copyright (c) Dominic Carretto * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://github.com/trimox/angular-mdc-web/blob/master/LICENSE */ /** * @fileoverview added by tsickle * Generated from: dom/ponyfill.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** @type {?} */ const hasNativeClosest = typeof Element !== 'undefined' && !!Element.prototype.closest; /** * IE 11 compatible closest implementation that is able to start from non-Element Nodes. * @param {?} element * @param {?} selector * @return {?} */ function closest(element, selector) { if (!(element instanceof Node)) { return null; } /** @type {?} */ let curr = element; while (curr != null && !(curr instanceof Element)) { curr = curr.parentNode; } return curr && (/** @type {?} */ ((hasNativeClosest ? curr.closest(selector) : polyfillClosest(curr, selector)))); } /** * Polyfill for browsers without Element.closest. * @param {?} element * @param {?} selector * @return {?} */ function polyfillClosest(element, selector) { /** @type {?} */ let curr = element; while (curr != null && !(curr instanceof Element && matches(curr, selector))) { curr = curr.parentNode; } return (/** @type {?} */ ((curr || null))); } /** * IE 11 compatible matches implementation. * @param {?} element * @param {?} selector * @return {?} */ function matches(element, selector) { return element.matches ? element.matches(selector) : ((/** @type {?} */ (element)))['msMatchesSelector'](selector); } export { closest, matches }; //# sourceMappingURL=dom.js.map