1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 18:17:20 +00:00

Unhyphenate CSS property names when rendering to the DOM

Annoyingly, Chrome will happily accept `background-color` and
`backgroundColor` interchangeably, so I hadn't noticed that this was
broken...
This commit is contained in:
Jeremy Ruston 2012-06-11 10:41:13 +01:00
parent 85d7bb6d8b
commit d0a9bfd0f0
3 changed files with 15 additions and 1 deletions

View File

@ -16,6 +16,7 @@ exports.startup = function() {
var modules,n,m,f,commander;
// This should be somewhere else
if($tw.browser) {
$tw.browser.unHyphenateCss = document.body.style["background-color"] === undefined;
$tw.browser.prefix = document.body.style.webkitTransform !== undefined ? "webkit" :
document.body.style.MozTransform !== undefined ? "Moz" :
document.body.style.OTransform !== undefined ? "O" : null;

View File

@ -96,7 +96,7 @@ Element.prototype.renderInDom = function(parentDomNode,insertBefore) {
element.className = v.join(" ");
} else if (typeof v === "object") { // ...or objects other than style?
for(var p in v) {
element.style[p] = v[p];
element.style[$tw.utils.unHyphenateCss(p)] = v[p];
}
} else {
element.setAttribute(a,v);

View File

@ -299,6 +299,19 @@ exports.applyStyleSheet = function(id,css) {
}
};
/*
Convert a hyphenated CSS property name into a camel case one
*/
exports.unHyphenateCss = function(propName) {
if($tw.browser.unHyphenateCss) {
return propName.replace(/-([a-z])/gi, function(match0,match1) {
return match1.toUpperCase();
});
} else {
return propName;
}
};
/*
Parse a version number string of the form "1.2.3", "1.2.3.a4", or "1.2.3.b4" into:
{major: <number>, minor: <number>, revision: <number>, alpha: <number>, beta: <number>}