* Finds the offset parent common to the two provided nodes * @method * @memberof Popper.Utils * @argument {Element} element1 * @argument {Element} element2 * @returns {Element} common offset parent
(element1, element2)
| 3231 | |
| 3232 | |
| 3233 | function findCommonOffsetParent(element1, element2) { |
| 3234 | // This check is needed to avoid errors in case one of the elements isn't defined for any reason |
| 3235 | if (!element1 || !element1.nodeType || !element2 || !element2.nodeType) { |
| 3236 | return document.documentElement; |
| 3237 | } // Here we make sure to give as "start" the element that comes first in the DOM |
| 3238 | |
| 3239 | |
| 3240 | var order = element1.compareDocumentPosition(element2) & Node.DOCUMENT_POSITION_FOLLOWING; |
| 3241 | var start = order ? element1 : element2; |
| 3242 | var end = order ? element2 : element1; // Get common ancestor container |
| 3243 | |
| 3244 | var range = document.createRange(); |
| 3245 | range.setStart(start, 0); |
| 3246 | range.setEnd(end, 0); |
| 3247 | var commonAncestorContainer = range.commonAncestorContainer; // Both nodes are inside #document |
| 3248 | |
| 3249 | if (element1 !== commonAncestorContainer && element2 !== commonAncestorContainer || start.contains(end)) { |
| 3250 | if (isOffsetContainer(commonAncestorContainer)) { |
| 3251 | return commonAncestorContainer; |
| 3252 | } |
| 3253 | |
| 3254 | return getOffsetParent(commonAncestorContainer); |
| 3255 | } // one of the nodes is inside shadowDOM, find which one |
| 3256 | |
| 3257 | |
| 3258 | var element1root = getRoot(element1); |
| 3259 | |
| 3260 | if (element1root.host) { |
| 3261 | return findCommonOffsetParent(element1root.host, element2); |
| 3262 | } else { |
| 3263 | return findCommonOffsetParent(element1, getRoot(element2).host); |
| 3264 | } |
| 3265 | } |
| 3266 | /** |
| 3267 | * Gets the scroll value of the given element in the given side (top and left) |
| 3268 | * @method |
no test coverage detected
searching dependent graphs…