Created
December 1, 2011 23:18
-
-
Save eligrey/1420621 to your computer and use it in GitHub Desktop.
Workaround for WebKit bug 73152
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
// Workaround for WebKit bug 73152 (https://bugs.webkit.org/show_bug.cgi?id=73152) | |
var serialize_css_prop = function(style, prop) { | |
"use strict"; | |
var | |
css = [] | |
, vals = style.getPropertyCSSValue(prop) | |
, val | |
, val_css | |
, i | |
, len | |
; | |
if (!vals) { | |
return; | |
} | |
if (vals.cssValueType !== vals.CSS_VALUE_LIST) { | |
vals = [vals]; | |
} | |
i = 0; | |
len = vals.length; | |
for (; i < len; i++) { | |
val = vals[i]; | |
val_css = val.cssText; | |
if (val.primitiveType === val.CSS_STRING && !/^\s*["']/.test(val_css)) { | |
// Since the bug doesn't apply to strings with quotes, I can | |
// safely surround the string with single quotes without escaping. | |
val_css = "'" + val_css + "'"; | |
} | |
css.push(val_css); | |
} | |
return prop + ":" + css.join(" ") + ";"; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment