Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a safe getComputedStyle to videojs. #3664

Merged
merged 2 commits into from
Nov 3, 2016

Conversation

gkatsev
Copy link
Member

@gkatsev gkatsev commented Oct 3, 2016

Description

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.

Specific Changes proposed

  • add a getComputedStyle util
  • expose videojs.getComputedStyle
  • use the util in mouse time display and seek bar

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.
@gkatsev gkatsev force-pushed the safe-get-computed-style branch from 40f0248 to c62de28 Compare October 3, 2016 21:08
* @param prop the property name you want
*/
export default function getComputedStyle(el, prop) {
if (typeof getComputedStyle === 'function') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like we may want to check for el or prop being null here and return empty sting if that happens.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, shouldn't this be window.getComputedStyle?

I think this'll detect the module-level function instead of the global one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it'll be safer to do window..

I guess checking that el and prop are available is good. I'll refrain from doing other type checking, though.

* @param el the element you want the computed style of
* @param prop the property name you want
*/
videojs.getComputedStyle = computedStyle;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to call it getComputedStyle? Should it be getComputedStyle throughout the code rather than computedStyle?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be computedStyle so we don't confuse it with the global function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do that.

Copy link
Contributor

@brandonocasey brandonocasey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM


return cs ? cs[prop] : '';
}

return el.currentStyle[prop];
return el.currentStyle[prop] || '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch here

@misteroneill misteroneill added confirmed minor This PR can be added to a minor release. It should not be added to a patch release. labels Oct 4, 2016
@gkatsev gkatsev added this to the 5.13 milestone Oct 4, 2016
@gkatsev gkatsev merged commit 9702618 into videojs:master Nov 3, 2016
@gkatsev gkatsev deleted the safe-get-computed-style branch November 3, 2016 19:59
gkatsev pushed a commit that referenced this pull request Jul 29, 2019
This will prevent a null exception when a video.js is implemented in a 'display:none' iframe on Firefox (<62).

This is a fix in continuation of the PR #3664 regarding a bug in Firefox https://bugzilla.mozilla.org/show_bug.cgi?id=548397
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed minor This PR can be added to a minor release. It should not be added to a patch release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants