Last active
August 29, 2015 14:03
-
-
Save itsoli/3292dbecfe35fb5478f7 to your computer and use it in GitHub Desktop.
This file contains 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 css3prop = (function () { | |
'use strict'; | |
function dashedToCamelCase(string) { | |
return string.replace(/(\-[a-z])/g, function($1) { | |
return $1.charAt(1).toUpperCase(); | |
}); | |
} | |
function camelCaseToDashed(string) { | |
return string.replace(/([A-Z])/g, function($1) { | |
return '-' + $1.toLowerCase(); | |
}); | |
} | |
var css3prop = {}; | |
var map = {}; | |
css3prop.js = function (property) { | |
if (!property) { | |
return undefined; | |
} | |
if (property in map) { | |
return map[property]; | |
} | |
var result = undefined; | |
var style = document.documentElement.style; | |
if (property in style) { | |
result = property; | |
} else { | |
var vendors = ['ms', 'Moz', 'Webkit', 'O']; | |
var suffix = property.charAt(0).toUpperCase() + property.slice(1); | |
for (var i = 0; i < vendors.length; ++i) { | |
var prop = vendors[i] + suffix; | |
if (prop in style) { | |
result = prop; | |
break; | |
} | |
} | |
} | |
map[property] = result; | |
return result; | |
}; | |
css3prop.css = function (property) { | |
var result = css3prop.js(dashedToCamelCase(property)); | |
if (result) { | |
result = camelCaseToDashed(result); | |
return (result.substring(0, 3) === 'ms-') ? '-' + result : result; | |
} | |
return undefined; | |
}; | |
return css3prop; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment