Improved the reliability of CPBrowserCSSProperty by checking for the browser prefix *before* hyphenating the camel-cased string.

This has the added benefit of ignoring unknown/unsupported prefixes, providing the property itself is camel-cased.

For example:

"LinearBackground" -> "linear-background"
"Linear-Background" -> "linear-background"
"linear-background" -> "linear-background"
"fooLinearBackground" -> "linear-background"

and

"WebkitLinearBackground" -> "-webkit-linear-background"
"MozLinearBackground" -> "-moz-linear-background"
etc..
This commit is contained in:
Miles Tinsley committed 2013-01-06 17:20:37 +00:00
1 parent 002c49b32f
commit 964f3fe06d
1 file changed
+20 -14
+20 -14
View File
@@ -348,26 +348,32 @@ function CPBrowserCSSProperty(aProperty)
if (!browserProperty)
return nil;
var parts = browserProperty.match(/[A-Z][a-z]+/g),
formattedBrowserProperty = browserProperty,
prefixes = {
'Webkit': '-webkit',
'Moz': '-moz',
'O': '-o',
'ms': '-ms'
var prefixes = {
'Webkit': '-webkit-',
'Moz': '-moz-',
'O': '-o-',
'ms': '-ms-'
};
// If there were any capitalized words in the browserProperty, insert a "-" between each one
if (parts && parts.length > 0)
formattedBrowserProperty = parts.join("-");
for (var prefix in prefixes)
{
if (formattedBrowserProperty.substring(0, prefix.length) == prefix)
if (browserProperty.substring(0, prefix.length) == prefix)
{
return prefixes[prefix] + formattedBrowserProperty.substring(prefix.length).toLowerCase();
var browserPropertyWithoutPrefix = browserProperty.substring(prefix.length),
parts = browserPropertyWithoutPrefix.match(/[A-Z][a-z]+/g);
// If there were any capitalized words in the browserProperty, insert a "-" between each one
if (parts && parts.length > 0)
browserPropertyWithoutPrefix = parts.join("-");
return prefixes[prefix] + browserPropertyWithoutPrefix.toLowerCase();
}
}
return formattedBrowserProperty.toLowerCase();
var parts = browserProperty.match(/[A-Z][a-z]+/g);
if (parts && parts.length > 0)
browserProperty = parts.join("-");
return browserProperty.toLowerCase();
}