mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-09-24 02:48:18 +00:00
utils: Avoid Node#contains for IE 11 support
Bug: T260061 Change-Id: Ifd1e9067ab16a65349a460e935bb95f5895432db
This commit is contained in:
parent
5c41597eb5
commit
34fb7c6497
|
@ -19,6 +19,22 @@ function childIndexOf( child ) {
|
|||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a Node contains (is an ancestor of) another Node (or is the same node)
|
||||
*
|
||||
* @param {Node} ancestor
|
||||
* @param {Node} descendant
|
||||
* @return {boolean}
|
||||
*/
|
||||
function contains( ancestor, descendant ) {
|
||||
// Support: IE 11
|
||||
// Node#contains is only supported on HTMLElement nodes. Otherwise we could just use
|
||||
// `ancestor.contains( descendant )`.
|
||||
return ancestor === descendant ||
|
||||
// eslint-disable-next-line no-bitwise
|
||||
ancestor.compareDocumentPosition( descendant ) & Node.DOCUMENT_POSITION_CONTAINED_BY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find closest ancestor element using one of the given tag names.
|
||||
*
|
||||
|
@ -140,12 +156,12 @@ function getCoveredSiblings( item ) {
|
|||
end = siblings.length - 1;
|
||||
|
||||
// Find first of the siblings that contains the item
|
||||
while ( !siblings[ start ].contains( range.startContainer ) ) {
|
||||
while ( !contains( siblings[ start ], range.startContainer ) ) {
|
||||
start++;
|
||||
}
|
||||
|
||||
// Find last of the siblings that contains the item
|
||||
while ( !siblings[ end ].contains( range.endContainer ) ) {
|
||||
while ( !contains( siblings[ end ], range.endContainer ) ) {
|
||||
end--;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue