Skip to content

Apply CSS shorthand expansion to IE<9 only #1953

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/browser/ui/dom/CSSPropertyOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,15 @@ var processStyleName = memoizeStringOnly(function(styleName) {
return hyphenateStyleName(styleName);
});

var hasShorthandPropertyBug = false;
var styleFloatAccessor = 'cssFloat';
if (ExecutionEnvironment.canUseDOM) {
try {
// IE8 throws "Invalid argument." if resetting shorthand style properties.
document.createElement('div').style.font = '';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does this throw? All the info online I can find indicate that it silently does the wrong thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

>>document.createElement('div').style.font = '';
  "Invalid argument." (error)
>>document.createElement('div').style.fontSize = '';
  ""

} catch (e) {
hasShorthandPropertyBug = true;
}
// IE8 only supports accessing cssFloat (standard) as styleFloat
if (document.documentElement.style.cssFloat === undefined) {
styleFloatAccessor = 'styleFloat';
Expand Down Expand Up @@ -118,7 +125,7 @@ var CSSPropertyOperations = {
}
if (styleValue) {
style[styleName] = styleValue;
} else {
} else if (hasShorthandPropertyBug) {
var expansion = CSSProperty.shorthandPropertyExpansions[styleName];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe just do expansion = hasShorthandPropertyBug && ...; to avoid the duplication in style[styleName] = '';? Otherwise looks good to me.

if (expansion) {
// Shorthand property that IE8 won't like unsetting, so unset each
Expand All @@ -129,6 +136,8 @@ var CSSPropertyOperations = {
} else {
style[styleName] = '';
}
} else {
style[styleName] = '';
}
}
}
Expand Down