mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-21 15:06:45 +02:00
don't reimplement native closest
(#696)
This commit is contained in:
parent
50fae125ed
commit
a2485392a5
|
@ -1053,6 +1053,7 @@ Choices is compiled using [Babel](https://babeljs.io/) to enable support for [ES
|
|||
- Array.prototype.indexOf
|
||||
- Object.assign
|
||||
- Element.prototype.classList
|
||||
- Element.prototype.closest
|
||||
- window.requestAnimationFrame
|
||||
- CustomEvent
|
||||
|
||||
|
|
|
@ -39,19 +39,11 @@ export const wrap = (element, wrapper = document.createElement('div')) => {
|
|||
return wrapper.appendChild(element);
|
||||
};
|
||||
|
||||
export const findAncestorByAttrName = (el, attr) => {
|
||||
let target = el;
|
||||
|
||||
while (target) {
|
||||
if (target.hasAttribute(attr)) {
|
||||
return target;
|
||||
}
|
||||
|
||||
target = target.parentElement;
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
/**
|
||||
* @param {HTMLElement} el
|
||||
* @param {string} attr
|
||||
*/
|
||||
export const findAncestorByAttrName = (el, attr) => el.closest(`[${attr}]`);
|
||||
|
||||
export const getAdjacentEl = (startEl, className, direction = 1) => {
|
||||
if (!startEl || !className) {
|
||||
|
|
Loading…
Reference in a new issue