Skip to content
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
27 changes: 20 additions & 7 deletions Source/Element/Element.Style.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ var returnsBordersInWrongOrder = el.style.border != border;
el = null;
//</ltIE9>

var hasGetComputedStyle = !!window.getComputedStyle,
brokenGetComputedStyle; // Opera rounds sub-pixel values

if (hasGetComputedStyle){
var el = document.createElement('div');
el.style.display = 'none';
el.style.paddingLeft = '1.5px';
document.html.appendChild(el);
Copy link
Member Author

Choose a reason for hiding this comment

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

appending this here as the body might not exist yet at this point of the code execution (if js was included in head) and Opera returns empty values for window.getComputedStyle on a detached node.

brokenGetComputedStyle = window.getComputedStyle(el, null).paddingLeft != el.style.paddingLeft;
document.html.removeChild(el);
el = null;
}

Element.Properties.styles = {set: function(styles){
this.setStyles(styles);
}};
Expand Down Expand Up @@ -87,7 +100,7 @@ var floatName = (html.style.cssFloat == null) ? 'styleFloat' : 'cssFloat',
Element.implement({

getComputedStyle: function(property){
if (this.currentStyle) return this.currentStyle[property.camelCase()];
if ((!hasGetComputedStyle || brokenGetComputedStyle) && this.currentStyle) return this.currentStyle[property.camelCase()];
var defaultView = Element.getDocument(this).defaultView,
computed = defaultView ? defaultView.getComputedStyle(this, null) : null;
return (computed) ? computed.getPropertyValue((property == floatName) ? 'float' : property.hyphenate()) : '';
Expand Down Expand Up @@ -141,7 +154,7 @@ Element.implement({
var color = result.match(/rgba?\([\d\s,]+\)/);
if (color) result = result.replace(color[0], color[0].rgbToHex());
}
if (Browser.opera || Browser.ie){
if (!hasGetComputedStyle || brokenGetComputedStyle){
if ((/^(height|width)$/).test(property) && !(/px$/.test(result))){
var values = (property == 'width') ? ['left', 'right'] : ['top', 'bottom'], size = 0;
values.each(function(value){
Expand All @@ -152,12 +165,12 @@ Element.implement({
if ((/^border(.+)Width|margin|padding/).test(property) && isNaN(parseFloat(result))){
return '0px';
}
//<ltIE9>
if (returnsBordersInWrongOrder && /^border(Top|Right|Bottom|Left)?$/.test(property) && /^#/.test(result)){
return result.replace(/^(.+)\s(.+)\s(.+)$/, '$2 $3 $1');
}
//</ltIE9>
}
//<ltIE9>
if (returnsBordersInWrongOrder && /^border(Top|Right|Bottom|Left)?$/.test(property) && /^#/.test(result)){
return result.replace(/^(.+)\s(.+)\s(.+)$/, '$2 $3 $1');
}
//</ltIE9>
return result;
},

Expand Down