Created
February 10, 2012 16:42
-
-
Save johnkpaul/1790727 to your computer and use it in GitHub Desktop.
Shim for getComputedStyle in old IEs
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
(function(window, undefined){ | |
window.getComputedStylePropertyValue = function(el,cssProperty){ | |
if(!window.getComputedStyle){ | |
if(document.defaultView && document.defaultView.getComputedStyle){ | |
return document.defaultView.getComputedStyle.getPropertyValue(cssProperty); | |
} | |
else{ | |
var camelCasedCssProperty = getCamelCasedCssProperty(cssProperty); | |
if(el.currentStyle){ | |
return el.currentStyle(camelCasedCssProperty); | |
} | |
else{ | |
return el.style[camelCasedCssProperty]; | |
} | |
} | |
} | |
else{ | |
return window.getComputedStyle(el).getPropertyValue(cssProperty); | |
} | |
} | |
function getCamelCasedCssProperty(cssProperty){ | |
return cssProperty.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase() }); | |
} | |
})(this) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Neat, but your polyfill does not return a computed style but the declared CSS one instead. I'll work for a better version ;)