mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-17 05:10:50 +00:00
23 lines
449 B
JavaScript
23 lines
449 B
JavaScript
|
'use strict';
|
||
|
|
||
|
/**
|
||
|
* Find closest ancestor element using one of the given tag names.
|
||
|
*
|
||
|
* @param {Node} el
|
||
|
* @param {string[]} tagNames
|
||
|
* @return {HTMLElement|null}
|
||
|
*/
|
||
|
function closestElement( el, tagNames ) {
|
||
|
do {
|
||
|
if ( el.nodeType === Node.ELEMENT_NODE && tagNames.indexOf( el.tagName.toLowerCase() ) !== -1 ) {
|
||
|
return el;
|
||
|
}
|
||
|
el = el.parentNode;
|
||
|
} while ( el );
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
module.exports = {
|
||
|
closestElement: closestElement
|
||
|
};
|