-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add a safe computedStyle to videojs. (#3664)
This is used internally in the seek bar and mouse time display. In firefox, in an iframe that is hidden with "display: none", getComputedStyle() returns "null" which can break things. See https://bugzilla.mozilla.org/show_bug.cgi?id=548397 for more details.
- Loading branch information
Showing
4 changed files
with
49 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import window from 'global/window'; | ||
|
||
/** | ||
* A safe getComputedStyle with an IE8 fallback. | ||
* | ||
* This is because in Firefox, if the player is loaded in an iframe with `display:none`, | ||
* then `getComputedStyle` returns `null`, so, we do a null-check to make sure | ||
* that the player doesn't break in these cases. | ||
* See https://bugzilla.mozilla.org/show_bug.cgi?id=548397 for more details. | ||
* | ||
* @function computedStyle | ||
* @param el the element you want the computed style of | ||
* @param prop the property name you want | ||
*/ | ||
export default function computedStyle(el, prop) { | ||
if (!el || !prop) { | ||
return ''; | ||
} | ||
|
||
if (typeof window.getComputedStyle === 'function') { | ||
const cs = window.getComputedStyle(el); | ||
|
||
return cs ? cs[prop] : ''; | ||
} | ||
|
||
return el.currentStyle[prop] || ''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters