Last active
August 29, 2015 14:05
-
-
Save SanderSpies/9ce7eec0e1c3394c7003 to your computer and use it in GitHub Desktop.
CSS reset for react-style
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
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