Skip to content

Commit

Permalink
fix: Use getComputedStyle but fall back to boundingClientRect (#623)
Browse files Browse the repository at this point in the history
  • Loading branch information
jplhomer authored and shawnbuso committed May 21, 2018
1 parent 2e8dd8f commit a017044
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/player-wrapper.js
Expand Up @@ -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();
};


Expand All @@ -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();
};


Expand Down

0 comments on commit a017044

Please sign in to comment.