* 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 * @
(el, relativeToContainingBlock, relativeToNonStaticParent, undoScale, container)
| 253 | * @return {Object} The boundingClientRect of el, with specified adjustments |
| 254 | */ |
| 255 | function getRect(el, relativeToContainingBlock, relativeToNonStaticParent, undoScale, container) { |
| 256 | if (!el.getBoundingClientRect && el !== window) return; |
| 257 | var elRect, top, left, bottom, right, height, width; |
| 258 | if (el !== window && el.parentNode && el !== getWindowScrollingElement()) { |
| 259 | elRect = el.getBoundingClientRect(); |
| 260 | top = elRect.top; |
| 261 | left = elRect.left; |
| 262 | bottom = elRect.bottom; |
| 263 | right = elRect.right; |
| 264 | height = elRect.height; |
| 265 | width = elRect.width; |
| 266 | } else { |
| 267 | top = 0; |
| 268 | left = 0; |
| 269 | bottom = window.innerHeight; |
| 270 | right = window.innerWidth; |
| 271 | height = window.innerHeight; |
| 272 | width = window.innerWidth; |
| 273 | } |
| 274 | if ((relativeToContainingBlock || relativeToNonStaticParent) && el !== window) { |
| 275 | // Adjust for translate() |
| 276 | container = container || el.parentNode; |
| 277 | |
| 278 | // solves #1123 (see: https://stackoverflow.com/a/37953806/6088312) |
| 279 | // Not needed on <= IE11 |
| 280 | if (!IE11OrLess) { |
| 281 | do { |
| 282 | if (container && container.getBoundingClientRect && (css(container, 'transform') !== 'none' || relativeToNonStaticParent && css(container, 'position') !== 'static')) { |
| 283 | var containerRect = container.getBoundingClientRect(); |
| 284 | |
| 285 | // Set relative to edges of padding box of container |
| 286 | top -= containerRect.top + parseInt(css(container, 'border-top-width')); |
| 287 | left -= containerRect.left + parseInt(css(container, 'border-left-width')); |
| 288 | bottom = top + elRect.height; |
| 289 | right = left + elRect.width; |
| 290 | break; |
| 291 | } |
| 292 | /* jshint boss:true */ |
| 293 | } while (container = container.parentNode); |
| 294 | } |
| 295 | } |
| 296 | if (undoScale && el !== window) { |
| 297 | // Adjust for scale() |
| 298 | var elMatrix = matrix(container || el), |
| 299 | scaleX = elMatrix && elMatrix.a, |
| 300 | scaleY = elMatrix && elMatrix.d; |
| 301 | if (elMatrix) { |
| 302 | top /= scaleY; |
| 303 | left /= scaleX; |
| 304 | width /= scaleX; |
| 305 | height /= scaleY; |
| 306 | bottom = top + height; |
| 307 | right = left + width; |
| 308 | } |
| 309 | } |
| 310 | return { |
| 311 | top: top, |
| 312 | left: left, |
no test coverage detected
searching dependent graphs…