Skip to content

Instantly share code, notes, and snippets.

@SanderSpies
Last active August 29, 2015 14:05
Show Gist options
  • Save SanderSpies/9ce7eec0e1c3394c7003 to your computer and use it in GitHub Desktop.
Save SanderSpies/9ce7eec0e1c3394c7003 to your computer and use it in GitHub Desktop.
CSS reset for react-style
var allInitial;
var testElement = document.createElement('div');
// Firefox
if ('all' in testElement.style) {
allInitial = {
all: 'initial'
};
}
else {
testElement.style.display = 'initial';
if (testElement.style.display === 'initial') {
// Chrome
var cssPropertyNames = Object.keys(testElement.style);
for (var i = 0, l = cssPropertyNames.length; i < l; i++) {
var cssPropertyName = cssPropertyNames[i];
allInitial[cssPropertyName] = 'initial';
}
}
}
testElement = null;
function allInitialFunc(el) {
if (allInitial) {
return allInitial;
}
// IE
// unfortunately we need to this every time
var newEl = document.createElement(el.localName);
var initialStyle = newEl.style;
for (var i = 0, l = cssPropertyNames.length; i < l; i++) {
var cssPropertyName = cssPropertyNames[i];
allInitial[cssPropertyName] = initialStyle[cssPropertyName];
}
return allInitial;
}
module.exports = allInitialFunc;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment