Created
September 30, 2013 21:37
-
-
Save benmj/6770675 to your computer and use it in GitHub Desktop.
from third party javascript
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 getStyle (node, property, camel) { | |
var value; | |
if (window.getComputedStyle) { | |
value = document.defaultView.getComputedStyle(node, null) | |
.getPropertyValue(property); | |
} else if (node.currentStyle) { | |
// IE fallback | |
value = node.currentStyle[property] ? | |
node.currentStyle[property] : | |
node.currentStyle[camel]; | |
} | |
if (value === '' || | |
value === 'transparent' || | |
value === 'rgba(0, 0, 0, 0)') { | |
return getStyle(node.parentNode, property, camel); | |
} else { | |
return value || ''; | |
} | |
} | |
function getBasicStyles(container) { | |
var anchor = document.createElement('a'); | |
container.appendChild(anchor); | |
function get(prop, camel) { | |
return getStyle(container, prop, camel); | |
} | |
var styles = { | |
anchorColor : getStyle(anchor, 'color'), | |
fontColor : get('color'), | |
direction : get('direction'), | |
fontFamily : get('font-family', 'fontFamily').replace(/['"]/g, '') | |
}; | |
anchor.parentNode.removeChild(anchor); | |
return styles; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment