From 74cddcad738ba0a733cb7eac4318d0959159b8e7 Mon Sep 17 00:00:00 2001 From: Gary Katsevman Date: Thu, 3 Nov 2016 18:41:27 -0400 Subject: [PATCH] fix: currentDimension can return 0 for fluid player on IE (#3738) This is because IE returns 0 for both getComputedStyle and currentStyle. However, offsetHeight and offsetWidth do contain the correct values we want. So, if before returning in currentDimension the return value is still zero, check the offset values. --- src/js/component.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/js/component.js b/src/js/component.js index d9367fb486..db9b295c0c 100644 --- a/src/js/component.js +++ b/src/js/component.js @@ -1148,16 +1148,20 @@ class Component { const computedStyle = window.getComputedStyle(this.el_); computedWidthOrHeight = computedStyle.getPropertyValue(widthOrHeight) || computedStyle[widthOrHeight]; - } else if (this.el_.currentStyle) { - // ie 8 doesn't support computed style, shim it - // return clientWidth or clientHeight instead for better accuracy + } + + // remove 'px' from variable and parse as integer + computedWidthOrHeight = parseFloat(computedWidthOrHeight); + + // if the computed value is still 0, it's possible that the browser is lying + // and we want to check the offset values. + // This code also runs on IE8 and wherever getComputedStyle doesn't exist. + if (computedWidthOrHeight === 0) { const rule = `offset${toTitleCase(widthOrHeight)}`; computedWidthOrHeight = this.el_[rule]; } - // remove 'px' from variable and parse as integer - computedWidthOrHeight = parseFloat(computedWidthOrHeight); return computedWidthOrHeight; }