mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-17 05:10:50 +00:00
e9b583d1c3
Now also works if the "follow-up" comment is wrapped in e.g. `<small>`. Change-Id: Ic37cb6afdb42021f109a1818f5c4299d907ed094
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
|
|
};
|