Skip to content

Instantly share code, notes, and snippets.

@auser
Last active August 29, 2015 13:56
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 auser/9335121 to your computer and use it in GitHub Desktop.
Save auser/9335121 to your computer and use it in GitHub Desktop.
var styleObject = function() {
this.classes = null;
var allClasses = document.styleSheets;
for (var i = 0; i < allClasses.length; i++) {
var cls = allClasses[i];
if (cls.title === "nvd3") {
this.classes = cls.rules;
break;
}
};
}
styleObject.prototype.applyToElements = function(parent) {
for (var i = 0; i < parent.children.length; i++) {
var child = parent.children[i];
this.applyToElements(child);
};
this.applyToElement(parent);
}
styleObject.prototype.applyToElement = function(element) {
function dumpComputedStyles(elem) {
var allStyles = [];
var cs = window.getComputedStyle(elem,null);
var len = cs.length;
for (var i=0;i<len;i++) {
var style = cs[i];
allStyles.push(style+" : "+cs.getPropertyValue(style));
}
// Finally, copy the element styles
if (element.style) {
allStyles.push(element.style.cssText);
}
return allStyles;
}
var allStyles = dumpComputedStyles(element)
element.setAttribute('style', allStyles.join(';'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment