Permalink
Browse files

use native getComputedStyle on IE9 and IE10 instead of non-standard c…

…urrentStyle
  • Loading branch information...
1 parent 4d6b2af commit 4f4f076db4b5ad7473bcfed26e98c469bc7d6b18 @gonchuki committed Aug 29, 2012
Showing with 20 additions and 7 deletions.
  1. +20 −7 Source/Element/Element.Style.js
@@ -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);
+ brokenGetComputedStyle = window.getComputedStyle(el, null).paddingLeft != el.style.paddingLeft;
+ document.html.removeChild(el);
+ el = null;
+}
+
Element.Properties.styles = {set: function(styles){
this.setStyles(styles);
}};
@@ -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()) : '';
@@ -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){
@@ -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;
},

0 comments on commit 4f4f076

Please sign in to comment.