Skip to content

Instantly share code, notes, and snippets.

@eligrey
Created December 1, 2011 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eligrey/1420621 to your computer and use it in GitHub Desktop.
Save eligrey/1420621 to your computer and use it in GitHub Desktop.
Workaround for WebKit bug 73152
// 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