Created
June 20, 2010 02:25
-
-
Save miya2000/445495 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
| var getValidCssPropertyName = (function() { | |
| function camelize(str) { | |
| return str.replace(/-([a-z])/g, function($0,$1) { return $1.toUpperCase() }); | |
| } | |
| function decamelize(str) { | |
| return str.replace( /[A-Z]/g, function($0) { return "-" + $0.toLowerCase() }); | |
| } | |
| var tmpStyle = null; | |
| function getValidCssPropertyName(cssStr, forJS) { | |
| if (!cssStr) return ''; | |
| if (cssStr == 'float') { | |
| if (!forJS) return 'float'; | |
| else return 'cssFloat'/*@cc_on && 'styleFloat' @*/; | |
| } | |
| var style = tmpStyle; | |
| if (style == null) { | |
| style = tmpStyle = document.createElement('div').style; | |
| setTimeout(function() { tmpStyle = null; }, 0); | |
| } | |
| var jsname = camelize(cssStr); | |
| if (jsname in style) return forJS ? jsname : decamelize(cssStr); | |
| jsname = jsname.charAt(0).toUpperCase() + jsname.slice(1); | |
| if (( 'O' + jsname) in style) return forJS ? ('O' + jsname) : ('-o-' + decamelize(cssStr)); | |
| if (( 'Moz' + jsname) in style) return forJS ? ('Moz' + jsname) : ('-moz-' + decamelize(cssStr)); | |
| if (('Webkit' + jsname) in style) return forJS ? ('Webkit' + jsname) : ('-webkit-' + decamelize(cssStr)); | |
| return ''; | |
| } | |
| return getValidCssPropertyName; | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment