Last active
August 29, 2015 14:14
-
-
Save tommcdo/47d4caacc565b3d5f2bf to your computer and use it in GitHub Desktop.
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
if (!window.getComputedStyle) { | |
window.getComputedStyle = (function() { | |
var // partially grabbed from jQuery and Dean's hack | |
notpixel = /^(?:[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|))(?!px)[a-z%]+$/, | |
position = /^(top|right|bottom|left)$/, | |
re = /\-([a-z])/g, | |
place = function (match, $1) { | |
return $1.toUpperCase(); | |
} | |
; | |
function ComputedStyle(_) { | |
this._ = _; | |
} | |
ComputedStyle.prototype.getPropertyValue = function (name) { | |
var | |
el = this._, | |
style = el.style, | |
currentStyle = el.currentStyle, | |
runtimeStyle = el.runtimeStyle, | |
result, | |
left, | |
rtLeft | |
; | |
name = (name === 'float' ? 'style-float' : name).replace(re, place); | |
result = currentStyle ? currentStyle[name] : style[name]; | |
if (notpixel.test(result) && !position.test(name)) { | |
left = style.left; | |
rtLeft = runtimeStyle && runtimeStyle.left; | |
if (rtLeft) { | |
runtimeStyle.left = currentStyle.left; | |
} | |
style.left = name === 'fontSize' ? '1em' : result; | |
result = style.pixelLeft + 'px'; | |
style.left = left; | |
if (rtLeft) { | |
runtimeStyle.left = rtLeft; | |
} | |
} | |
return result == null ? | |
result : ((result + '') || 'auto'); | |
}; | |
// unsupported | |
function PseudoComputedStyle() {} | |
PseudoComputedStyle.prototype.getPropertyValue = function () { | |
return null; | |
}; | |
return function (el, pseudo) { | |
return pseudo ? | |
new PseudoComputedStyle(el) : | |
new ComputedStyle(el); | |
}; | |
})(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment