diff --git a/mithril.js b/mithril.js index bb6edd23..e279e368 100644 --- a/mithril.js +++ b/mithril.js @@ -319,8 +319,8 @@ var renderService = function($window) { var attrs = vnode.attrs var is = attrs && attrs.is var element = ns ? - is ? $doc.createElementNS(ns, tag, is) : $doc.createElementNS(ns, tag) : - is ? $doc.createElement(tag, is) : $doc.createElement(tag) + is ? $doc.createElementNS(ns, tag, {is: is}) : $doc.createElementNS(ns, tag) : + is ? $doc.createElement(tag, {is: is}) : $doc.createElement(tag) vnode.dom = element if (attrs != null) { setAttrs(vnode, attrs, ns) @@ -680,11 +680,11 @@ var renderService = function($window) { } //style function updateStyle(element, old, style) { - if (old === style) element.cssText = "", old = null - if (style == null) element.cssText = "" - else if (typeof style === "string") element.cssText = style + if (old === style) element.style.cssText = "", old = null + if (style == null) element.style.cssText = "" + else if (typeof style === "string") element.style.cssText = style else { - if (typeof old === "string") element.cssText = "" + if (typeof old === "string") element.style.cssText = "" for (var key in style) { element.style[key] = style[key] } diff --git a/mithril.min.js b/mithril.min.js index 6e99b40e..30736343 100644 --- a/mithril.min.js +++ b/mithril.min.js @@ -9,22 +9,22 @@ a)},combine:G,reject:function(a){var b=y();b.error(a);return b},HALT:D};u.normal if("string"===typeof a&&void 0===K[a]){for(var b,d,e=[],k={};b=ka.exec(a);){var q=b[1],l=b[2];""===q&&""!==l?d=l:"#"===q?k.id=l:"."===q?e.push(l):"["===b[3][0]&&((q=b[6])&&(q=q.replace(/\\(["'])/g,"$1").replace(/\\\\/g,"\\")),k[b[4]]=q||!0)}0=r&&B>=A;){var t=c[r],w=f[A];if(t===w)r++,A++;else if(null!=t&&null!=w&&t.key===w.key)r++,A++,q(a,t,w,e, -m(c,r,h),z,k),z&&t.tag===w.tag&&g(a,l(t),h);else if(t=c[v],t===w)v--,A++;else if(null!=t&&null!=w&&t.key===w.key)q(a,t,w,e,m(c,v+1,h),z,k),A=r&&B>=A;){t=c[v];w=f[B];if(t===w)v--;else if(null!=t&&null!=w&&t.key===w.key)q(a,t,w,e,m(c,v+1,h),z,k),z&&t.tag===w.tag&&g(a,l(t),h),null!=t.dom&&(h=t.dom),v--;else{if(!u){u=c;var t=v,n={},x;for(x=0;x=r&&B>=A;){var t=c[r],w=f[A];if(t===w)r++,A++;else if(null!=t&&null!=w&&t.key=== +w.key)r++,A++,q(a,t,w,e,m(c,r,h),z,k),z&&t.tag===w.tag&&g(a,l(t),h);else if(t=c[v],t===w)v--,A++;else if(null!=t&&null!=w&&t.key===w.key)q(a,t,w,e,m(c,v+1,h),z,k),A=r&&B>=A;){t=c[v];w=f[B];if(t===w)v--;else if(null!=t&&null!=w&&t.key===w.key)q(a,t,w,e,m(c,v+1,h),z,k),z&&t.tag===w.tag&&g(a,l(t),h),null!=t.dom&&(h=t.dom),v--;else{if(!u){u=c;var t=v,n={},x;for(x=0;xa.indexOf("?")?"?":"&";a+=h+d}return a}function e(a){try{return""!== a?JSON.parse(a):null}catch(b){throw Error(a);}}function k(a){return a.responseText}function q(a,b){if("function"===typeof a)if(b instanceof Array)for(var d=0;d -1) { + var rawKey = rule.slice(0, colonIndex).trim() + var key = rawKey.replace(/-\D/g, function(match) {return match[1].toUpperCase()}) + var value = rule.slice(colonIndex + 1).trim() + if (key !== "cssText") { + style[key] = value + buf.push(rawKey + ": " + value + ";") + } + } + } + cssText = buf.join(" ") + } + } + }) var events = {} var element = { nodeType: 1, @@ -140,21 +198,6 @@ module.exports = function() { // https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style#Setting_style throw new Error("setting element.style is not portable") }, - set cssText(value) { - if (typeof value === "string") { - for (var key in style) style[key] = "" - var rules = value.split(";") - for (var i = 0; i < rules.length; i++) { - var rule = rules[i] - var colonIndex = rule.indexOf(":") - if (colonIndex > -1) { - var key = rule.slice(0, colonIndex).trim().replace(/-\D/g, function(match) {return match[1].toUpperCase()}) - var value = rule.slice(colonIndex + 1).trim() - style[key] = value - } - } - } - }, get className() { return this.attributes["class"] ? this.attributes["class"].nodeValue : "" }, diff --git a/test-utils/tests/test-domMock.js b/test-utils/tests/test-domMock.js index 2b589673..b08df230 100644 --- a/test-utils/tests/test-domMock.js +++ b/test-utils/tests/test-domMock.js @@ -474,20 +474,56 @@ o.spec("domMock", function() { o(typeof div.style).equals("object") }) - o("setting cssText string works", function() { + o("setting style.cssText string works", function() { var div = $document.createElement("div") - div.cssText = "background-color: red; border-bottom: 1px solid red;" + div.style.cssText = "background-color: red; border-bottom: 1px solid red;" o(div.style.backgroundColor).equals("red") o(div.style.borderBottom).equals("1px solid red") }) - o("removing via setting cssText string works", function() { + o("removing via setting style.cssText string works", function() { var div = $document.createElement("div") - div.cssText = "background: red;" - div.cssText = "" + div.style.cssText = "background: red;" + div.style.cssText = "" o(div.style.background).equals("") }) + o("the final semicolon is optional when setting style.cssText", function() { + var div = $document.createElement("div") + div.style.cssText = "background: red" + + o(div.style.background).equals("red") + o(div.style.cssText).equals("background: red;") + }) + o("'cssText' as a property name is ignored when setting style.cssText", function(){ + var div = $document.createElement("div") + div.style.cssText = "cssText: red;" + + o(div.style.cssText).equals("") + }) + o("setting style.cssText that has a semi-colon in a strings", function(){ + var div = $document.createElement("div") + div.style.cssText = "background: url(';'); font-family: \";\"" + + o(div.style.background).equals("url(';')") + o(div.style.fontFamily).equals("\";\"") + o(div.style.cssText).equals("background: url(';'); font-family: \";\";") + }) + o("comments in style.cssText are stripped", function(){ + var div = $document.createElement("div") + div.style.cssText = "/**/background/*:*/: /*>;)*/red/**/;/**/" + + o(div.style.background).equals("red") + o(div.style.cssText).equals("background: red;") + + }) + o("comments in strings in style.cssText are preserved", function(){ + var div = $document.createElement("div") + div.style.cssText = "background: url('/*foo*/')" + + o(div.style.background).equals("url('/*foo*/')") + + }) o("setting style throws", function () { var err = false try {