Skip to content

Instantly share code, notes, and snippets.

@benmj
Created September 30, 2013 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benmj/6770675 to your computer and use it in GitHub Desktop.
Save benmj/6770675 to your computer and use it in GitHub Desktop.
from third party javascript
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