From a017044e377512e6b2230ade9bc2bc547182bea1 Mon Sep 17 00:00:00 2001 From: Josh Larson Date: Mon, 21 May 2018 09:57:56 -0500 Subject: [PATCH] fix: Use getComputedStyle but fall back to boundingClientRect (#623) --- src/player-wrapper.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/player-wrapper.js b/src/player-wrapper.js index b329592a..4fd5e57e 100644 --- a/src/player-wrapper.js +++ b/src/player-wrapper.js @@ -374,9 +374,13 @@ PlayerWrapper.prototype.play = function() { * @return {number} The player's width. */ PlayerWrapper.prototype.getPlayerWidth = function() { - const boundingRect = this.vjsPlayer.el().getBoundingClientRect() || {}; + let width = (getComputedStyle(this.vjsPlayer.el()) || {}).width; - return parseInt(boundingRect.width, 10) || this.vjsPlayer.width(); + if (!width || parseInt(width, 10) === 0) { + width = (this.vjsPlayer.el().getBoundingClientRect() || {}).width; + } + + return parseInt(width, 10) || this.vjsPlayer.width(); }; @@ -386,9 +390,13 @@ PlayerWrapper.prototype.getPlayerWidth = function() { * @return {number} The player's height. */ PlayerWrapper.prototype.getPlayerHeight = function() { - const boundingRect = this.vjsPlayer.el().getBoundingClientRect() || {}; + let height = (getComputedStyle(this.vjsPlayer.el()) || {}).height; + + if (!height || parseInt(height, 10) === 0) { + height = (this.vjsPlayer.el().getBoundingClientRect() || {}).height; + } - return parseInt(boundingRect.height, 10) || this.vjsPlayer.height(); + return parseInt(height, 10) || this.vjsPlayer.height(); };