mediawiki-extensions-Discus.../modules/utils.js
Bartosz Dziewoński e9b583d1c3 parser: Improve merging multiple comments on one line
Now also works if the "follow-up" comment is wrapped in e.g. `<small>`.

Change-Id: Ic37cb6afdb42021f109a1818f5c4299d907ed094
2020-03-14 13:34:42 +00:00

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