* Returns the "bounding client rect" of given element * @param {HTMLElement} el The element whose boundingClientRect is wanted * @param {[Boolean]} relativeToContainingBlock Whether the rect should be relative to the containing block of (including) the container * @param
(el, relativeToContainingBlock, relativeToNonStaticParent, undoScale, container)
| 167 | * @return {Object} The boundingClientRect of el, with specified adjustments |
| 168 | */ |
| 169 | function getRect(el, relativeToContainingBlock, relativeToNonStaticParent, undoScale, container) { |
| 170 | if (!el.getBoundingClientRect && el !== window) return; |
| 171 | |
| 172 | let elRect, |
| 173 | top, |
| 174 | left, |
| 175 | bottom, |
| 176 | right, |
| 177 | height, |
| 178 | width; |
| 179 | |
| 180 | if (el !== window && el.parentNode && el !== getWindowScrollingElement()) { |
| 181 | elRect = el.getBoundingClientRect(); |
| 182 | top = elRect.top; |
| 183 | left = elRect.left; |
| 184 | bottom = elRect.bottom; |
| 185 | right = elRect.right; |
| 186 | height = elRect.height; |
| 187 | width = elRect.width; |
| 188 | } else { |
| 189 | top = 0; |
| 190 | left = 0; |
| 191 | bottom = window.innerHeight; |
| 192 | right = window.innerWidth; |
| 193 | height = window.innerHeight; |
| 194 | width = window.innerWidth; |
| 195 | } |
| 196 | |
| 197 | if ((relativeToContainingBlock || relativeToNonStaticParent) && el !== window) { |
| 198 | // Adjust for translate() |
| 199 | container = container || el.parentNode; |
| 200 | |
| 201 | // solves #1123 (see: https://stackoverflow.com/a/37953806/6088312) |
| 202 | // Not needed on <= IE11 |
| 203 | if (!IE11OrLess) { |
| 204 | do { |
| 205 | if ( |
| 206 | container && |
| 207 | container.getBoundingClientRect && |
| 208 | ( |
| 209 | css(container, 'transform') !== 'none' || |
| 210 | relativeToNonStaticParent && |
| 211 | css(container, 'position') !== 'static' |
| 212 | ) |
| 213 | ) { |
| 214 | let containerRect = container.getBoundingClientRect(); |
| 215 | |
| 216 | // Set relative to edges of padding box of container |
| 217 | top -= containerRect.top + parseInt(css(container, 'border-top-width')); |
| 218 | left -= containerRect.left + parseInt(css(container, 'border-left-width')); |
| 219 | bottom = top + elRect.height; |
| 220 | right = left + elRect.width; |
| 221 | |
| 222 | break; |
| 223 | } |
| 224 | /* jshint boss:true */ |
| 225 | } while (container = container.parentNode); |
| 226 | } |
no test coverage detected
searching dependent graphs…