mediawiki-extensions-Discus.../modules/utils.js

23 lines
449 B
JavaScript
Raw Normal View History

'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
};