Last active
October 5, 2016 07:52
-
-
Save thybzi/86897b0f8402da3dbce4fe1649d3e04a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 createStyle(data, useImportant, w) { | |
var styleElement, styleContent, selector, property, value; | |
w = w || window; | |
styleContent = ''; | |
for (selector in data) { | |
if (!data.hasOwnProperty(selector)) continue; | |
styleContent += '\n' + selector + ' {\n'; | |
for (property in data[selector]) { | |
if (!data[selector].hasOwnProperty(property)) continue; | |
value = data[selector][property]; | |
styleContent += ' ' + property + ': ' + value; | |
if (useImportant) { | |
styleContent += ' !important'; | |
} | |
styleContent += ';\n' | |
} | |
styleContent += ' }\n'; | |
} | |
styleElement = w.document.createElement('style'); | |
styleElement.textContent = styleContent; | |
w.document.querySelector('head').appendChild(styleElement); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment