diff --git a/archive/v0.1.11/mithril-tests.js b/archive/v0.1.11/mithril-tests.js index 8b40890c..bac8917b 100644 --- a/archive/v0.1.11/mithril-tests.js +++ b/archive/v0.1.11/mithril-tests.js @@ -32,7 +32,7 @@ Mithril = m = new function app(window) { } return cell } - function build(parentElement, parentTag, data, cached, shouldReattach, index, namespace) { + function build(parentElement, parentTag, data, cached, shouldReattach, index, editable, namespace) { if (data === null || data === undefined) { if (cached) clear(cached.nodes) return @@ -49,7 +49,7 @@ Mithril = m = new function app(window) { if (dataType == "[object Array]") { var nodes = [], intact = cached.length === data.length, subArrayCount = 0 for (var i = 0, cacheCount = 0; i < data.length; i++) { - var item = build(parentElement, null, data[i], cached[cacheCount], shouldReattach, index + subArrayCount || subArrayCount, namespace) + var item = build(parentElement, null, data[i], cached[cacheCount], shouldReattach, index + subArrayCount || subArrayCount, editable, namespace) if (item === undefined) continue if (!item.nodes.intact) intact = false subArrayCount += item instanceof Array ? item.length : 1 @@ -74,7 +74,7 @@ Mithril = m = new function app(window) { cached = { tag: data.tag, attrs: setAttributes(node, data.tag, data.attrs, {}, namespace), - children: build(node, data.tag, data.children, cached.children, true, 0, namespace), + children: build(node, data.tag, data.children, cached.children, true, 0, data.attrs.contenteditable ? node : editable, namespace), nodes: [node] } parentElement.insertBefore(node, parentElement.childNodes[index] || null) @@ -82,7 +82,7 @@ Mithril = m = new function app(window) { else { node = cached.nodes[0] setAttributes(node, data.tag, data.attrs, cached.attrs, namespace) - cached.children = build(node, data.tag, data.children, cached.children, false, 0, namespace) + cached.children = build(node, data.tag, data.children, cached.children, false, 0, data.attrs.contenteditable ? node : editable, namespace) cached.nodes.intact = true if (shouldReattach === true) parentElement.insertBefore(node, parentElement.childNodes[index] || null) } @@ -102,20 +102,25 @@ Mithril = m = new function app(window) { cached.nodes = [node] } else if (cached.valueOf() !== data.valueOf() || shouldReattach === true) { - if (data.$trusted) { - var current = cached.nodes[0], nodes = [current] - if (current) { - while (current = current.nextSibling) nodes.push(current) - clear(nodes) - node = injectHTML(parentElement, index, data) + if (!editable || editable !== window.document.activeElement) { + if (data.$trusted) { + var current = cached.nodes[0], nodes = [current] + if (current) { + while (current = current.nextSibling) nodes.push(current) + clear(nodes) + node = injectHTML(parentElement, index, data) + } + else parentElement.innerHTML = data + } + else { + node = cached.nodes[0] + if (parentTag === "textarea") parentElement.value = data + else if (editable) editable.innerHTML = data + else { + parentElement.insertBefore(node, parentElement.childNodes[index] || null) + node.nodeValue = data + } } - else parentElement.innerHTML = data - } - else { - node = cached.nodes[0] - if (parentTag === "textarea") parentElement.value = data - else parentElement.insertBefore(node, parentElement.childNodes[index] || null) - node.nodeValue = data } cached = new data.constructor(data) cached.nodes = [node] @@ -137,6 +142,7 @@ Mithril = m = new function app(window) { } else if (attrName === "style") { for (var rule in dataAttr) { + console.log(node) if (cachedAttr === undefined || cachedAttr[rule] !== dataAttr[rule]) node.style[rule] = dataAttr[rule] } } @@ -202,7 +208,7 @@ Mithril = m = new function app(window) { var index = nodeCache.indexOf(root) var id = index < 0 ? nodeCache.push(root) - 1 : index var node = root == window.document || root == window.document.documentElement ? documentNode : root - cellCache[id] = build(node, null, cell, cellCache[id], false, 0) + cellCache[id] = build(node, null, cell, cellCache[id], false, 0, null, undefined) } m.trust = function(value) { diff --git a/archive/v0.1.11/mithril.js b/archive/v0.1.11/mithril.js index f07d8197..a66726c4 100644 --- a/archive/v0.1.11/mithril.js +++ b/archive/v0.1.11/mithril.js @@ -32,7 +32,7 @@ Mithril = m = new function app(window) { } return cell } - function build(parentElement, parentTag, data, cached, shouldReattach, index, namespace) { + function build(parentElement, parentTag, data, cached, shouldReattach, index, editable, namespace) { if (data === null || data === undefined) { if (cached) clear(cached.nodes) return @@ -49,7 +49,7 @@ Mithril = m = new function app(window) { if (dataType == "[object Array]") { var nodes = [], intact = cached.length === data.length, subArrayCount = 0 for (var i = 0, cacheCount = 0; i < data.length; i++) { - var item = build(parentElement, null, data[i], cached[cacheCount], shouldReattach, index + subArrayCount || subArrayCount, namespace) + var item = build(parentElement, null, data[i], cached[cacheCount], shouldReattach, index + subArrayCount || subArrayCount, editable, namespace) if (item === undefined) continue if (!item.nodes.intact) intact = false subArrayCount += item instanceof Array ? item.length : 1 @@ -74,7 +74,7 @@ Mithril = m = new function app(window) { cached = { tag: data.tag, attrs: setAttributes(node, data.tag, data.attrs, {}, namespace), - children: build(node, data.tag, data.children, cached.children, true, 0, namespace), + children: build(node, data.tag, data.children, cached.children, true, 0, data.attrs.contenteditable ? node : editable, namespace), nodes: [node] } parentElement.insertBefore(node, parentElement.childNodes[index] || null) @@ -82,7 +82,7 @@ Mithril = m = new function app(window) { else { node = cached.nodes[0] setAttributes(node, data.tag, data.attrs, cached.attrs, namespace) - cached.children = build(node, data.tag, data.children, cached.children, false, 0, namespace) + cached.children = build(node, data.tag, data.children, cached.children, false, 0, data.attrs.contenteditable ? node : editable, namespace) cached.nodes.intact = true if (shouldReattach === true) parentElement.insertBefore(node, parentElement.childNodes[index] || null) } @@ -102,20 +102,25 @@ Mithril = m = new function app(window) { cached.nodes = [node] } else if (cached.valueOf() !== data.valueOf() || shouldReattach === true) { - if (data.$trusted) { - var current = cached.nodes[0], nodes = [current] - if (current) { - while (current = current.nextSibling) nodes.push(current) - clear(nodes) - node = injectHTML(parentElement, index, data) + if (!editable || editable !== window.document.activeElement) { + if (data.$trusted) { + var current = cached.nodes[0], nodes = [current] + if (current) { + while (current = current.nextSibling) nodes.push(current) + clear(nodes) + node = injectHTML(parentElement, index, data) + } + else parentElement.innerHTML = data + } + else { + node = cached.nodes[0] + if (parentTag === "textarea") parentElement.value = data + else if (editable) editable.innerHTML = data + else { + parentElement.insertBefore(node, parentElement.childNodes[index] || null) + node.nodeValue = data + } } - else parentElement.innerHTML = data - } - else { - node = cached.nodes[0] - if (parentTag === "textarea") parentElement.value = data - else parentElement.insertBefore(node, parentElement.childNodes[index] || null) - node.nodeValue = data } cached = new data.constructor(data) cached.nodes = [node] @@ -137,6 +142,7 @@ Mithril = m = new function app(window) { } else if (attrName === "style") { for (var rule in dataAttr) { + console.log(node) if (cachedAttr === undefined || cachedAttr[rule] !== dataAttr[rule]) node.style[rule] = dataAttr[rule] } } @@ -202,7 +208,7 @@ Mithril = m = new function app(window) { var index = nodeCache.indexOf(root) var id = index < 0 ? nodeCache.push(root) - 1 : index var node = root == window.document || root == window.document.documentElement ? documentNode : root - cellCache[id] = build(node, null, cell, cellCache[id], false, 0) + cellCache[id] = build(node, null, cell, cellCache[id], false, 0, null, undefined) } m.trust = function(value) { diff --git a/archive/v0.1.11/mithril.min.js b/archive/v0.1.11/mithril.min.js index d5b8b899..bba919ab 100644 --- a/archive/v0.1.11/mithril.min.js +++ b/archive/v0.1.11/mithril.min.js @@ -4,5 +4,5 @@ http://github.com/lhorie/mithril.js (c) Leo Horie License: MIT */ -Mithril=m=new function(a){function b(){var a=arguments,b="[object Object]"==u.call(a[1]),c=b?a[1]:{},d="class"in c?"class":"className",e=t[a[0]];if(void 0===e){t[a[0]]=e={tag:"div",attrs:{}};for(var f,h=[];f=v.exec(a[0]);)if(""==f[1])e.tag=f[2];else if("#"==f[1])e.attrs.id=f[2];else if("."==f[1])h.push(f[2]);else if("["==f[3][0]){var i=w.exec(f[3]);e.attrs[i[1]]=i[3]||!0}h.length>0&&(e.attrs[d]=h.join(" "))}e=g(e),e.attrs=g(e.attrs),e.children=b?a[2]:a[1];for(var j in c)e.attrs[j]=j==d?(e.attrs[j]||"")+" "+c[j]:c[j];return e}function c(b,g,h,i,j,k,l){if(null===h||void 0===h)return void(i&&e(i.nodes));if("retain"!==h.subtree){var m=u.call(i),n=u.call(h);if(m!=n&&(null!==i&&void 0!==i&&e(i.nodes),i=new h.constructor,i.nodes=[]),"[object Array]"==n){for(var o=[],p=i.length===h.length,q=0,r=0,s=0;r-1?new h.constructor(h):h,i.nodes=[v];else if(i.valueOf()!==h.valueOf()||j===!0){if(h.$trusted){var x=i.nodes[0],o=[x];if(x){for(;x=x.nextSibling;)o.push(x);e(o),v=f(b,k,h)}else b.innerHTML=h}else v=i.nodes[0],"textarea"===g?b.value=h:b.insertBefore(v,b.childNodes[k]||null),v.nodeValue=h;i=new h.constructor(h),i.nodes=[v]}else i.nodes.intact=!0}return i}}function d(b,c,d,e,f){for(var g in d){var i=d[g],j=e[g];if(!(g in e)||j!==i||b===a.document.activeElement){if(e[g]=i,"config"===g)continue;if("function"==typeof i&&0==g.indexOf("on"))b[g]=h(i,b);else if("style"===g)for(var k in i)(void 0===j||j[k]!==i[k])&&(b.style[k]=i[k]);else void 0!==f?"href"===g?b.setAttributeNS("http://www.w3.org/1999/xlink","href",i):"className"===g?b.setAttribute("class",i):b.setAttribute(g,i):"value"===g&&"input"===c?b.value!==i&&(b.value=i):g in b?b[g]=i:b.setAttribute(g,i)}}return e}function e(a){for(var b=0;b0&&("GET"==a.method?a.url=a.url+(a.url.indexOf("?")<0?"?":"&")+o(b):a.data=c(b)),a}function q(a,b){var c=a.match(/:[a-z]\w+/gi);if(c&&b)for(var d=0;de?y.push(b)-1:e,g=b==a.document||b==a.document.documentElement?x:b;z[f]=c(g,null,d,z[f],!1,0)},b.trust=function(a){return a=new String(a),a.$trusted=!0,a};var A=[],B=[],C=[],D=0,E=0,F=0,G=null;b.module=function(a,c){b.startComputation();var d=A.indexOf(a);0>d&&(d=A.length),A[d]=a,B[d]=c,C[d]=new c.controller,b.endComputation()},b.redraw=function(){if(D=a.performance&&a.performance.now?a.performance.now():(new a.Date).getTime(),D-E>16)i();else{var b=a.cancelAnimationFrame||a.clearTimeout,c=a.requestAnimationFrame||a.setTimeout;b(F),F=c(i,0)}};var H=0;b.startComputation=function(){H++},b.endComputation=function(){H=Math.max(H-1,0),0==H&&b.redraw()},b.withAttr=function(a,b){return function(c){b(a in c.currentTarget?c.currentTarget[a]:c.currentTarget.getAttribute(a))}};var I,J={pathname:"",hash:"#",search:"?"},K=function(){},L={};return b.route=function(){if(0===arguments.length)return I;if(3===arguments.length){I=a.location[b.route.mode].slice(J[b.route.mode].length);var c=arguments[0],d=arguments[1],e=arguments[2];K=function(a){var f=a.slice(J[b.route.mode].length);j(c,e,f)||b.route(d,!0)};var f="hash"==b.route.mode?"onhashchange":"onpopstate";a[f]=function(){K(a.location[b.route.mode])},G=l,a[f]()}else if(arguments[0].addEventListener){var g=arguments[0],h=arguments[1];g.href=J[b.route.mode]+g.pathname,h||(g.removeEventListener("click",k),g.addEventListener("click",k))}else if("string"==typeof arguments[0]){I=arguments[0];var i=arguments[1]===!0;a.history.pushState?(G=function(){a.history[i?"replaceState":"pushState"](null,a.document.title,J[b.route.mode]+I),l()},K(J[b.route.mode]+I)):a.location[b.route.mode]=I}},b.route.param=function(a){return L[a]},b.route.mode="search",b.prop=function(a){var b=function(){return arguments.length&&(a=arguments[0]),a};return b.toJSON=function(){return a},b},b.deferred=function(){var a=[],c=[],d={resolve:function(b){for(var c=0;c0&&(e.attrs[d]=h.join(" "))}e=g(e),e.attrs=g(e.attrs),e.children=b?a[2]:a[1];for(var j in c)e.attrs[j]=j==d?(e.attrs[j]||"")+" "+c[j]:c[j];return e}function c(b,g,h,i,j,k,l,m){if(null===h||void 0===h)return void(i&&e(i.nodes));if("retain"!==h.subtree){var n=u.call(i),o=u.call(h);if(n!=o&&(null!==i&&void 0!==i&&e(i.nodes),i=new h.constructor,i.nodes=[]),"[object Array]"==o){for(var p=[],q=i.length===h.length,r=0,s=0,t=0;s-1?new h.constructor(h):h,i.nodes=[w];else if(i.valueOf()!==h.valueOf()||j===!0){if(!l||l!==a.document.activeElement)if(h.$trusted){var y=i.nodes[0],p=[y];if(y){for(;y=y.nextSibling;)p.push(y);e(p),w=f(b,k,h)}else b.innerHTML=h}else w=i.nodes[0],"textarea"===g?b.value=h:l?l.innerHTML=h:(b.insertBefore(w,b.childNodes[k]||null),w.nodeValue=h);i=new h.constructor(h),i.nodes=[w]}else i.nodes.intact=!0}return i}}function d(b,c,d,e,f){for(var g in d){var i=d[g],j=e[g];if(!(g in e)||j!==i||b===a.document.activeElement){if(e[g]=i,"config"===g)continue;if("function"==typeof i&&0==g.indexOf("on"))b[g]=h(i,b);else if("style"===g)for(var k in i)console.log(b),(void 0===j||j[k]!==i[k])&&(b.style[k]=i[k]);else void 0!==f?"href"===g?b.setAttributeNS("http://www.w3.org/1999/xlink","href",i):"className"===g?b.setAttribute("class",i):b.setAttribute(g,i):"value"===g&&"input"===c?b.value!==i&&(b.value=i):g in b?b[g]=i:b.setAttribute(g,i)}}return e}function e(a){for(var b=0;b0&&("GET"==a.method?a.url=a.url+(a.url.indexOf("?")<0?"?":"&")+o(b):a.data=c(b)),a}function q(a,b){var c=a.match(/:[a-z]\w+/gi);if(c&&b)for(var d=0;de?y.push(b)-1:e,g=b==a.document||b==a.document.documentElement?x:b;z[f]=c(g,null,d,z[f],!1,0,null,void 0)},b.trust=function(a){return a=new String(a),a.$trusted=!0,a};var A=[],B=[],C=[],D=0,E=0,F=0,G=null;b.module=function(a,c){b.startComputation();var d=A.indexOf(a);0>d&&(d=A.length),A[d]=a,B[d]=c,C[d]=new c.controller,b.endComputation()},b.redraw=function(){if(D=a.performance&&a.performance.now?a.performance.now():(new a.Date).getTime(),D-E>16)i();else{var b=a.cancelAnimationFrame||a.clearTimeout,c=a.requestAnimationFrame||a.setTimeout;b(F),F=c(i,0)}};var H=0;b.startComputation=function(){H++},b.endComputation=function(){H=Math.max(H-1,0),0==H&&b.redraw()},b.withAttr=function(a,b){return function(c){b(a in c.currentTarget?c.currentTarget[a]:c.currentTarget.getAttribute(a))}};var I,J={pathname:"",hash:"#",search:"?"},K=function(){},L={};return b.route=function(){if(0===arguments.length)return I;if(3===arguments.length){I=a.location[b.route.mode].slice(J[b.route.mode].length);var c=arguments[0],d=arguments[1],e=arguments[2];K=function(a){var f=a.slice(J[b.route.mode].length);j(c,e,f)||b.route(d,!0)};var f="hash"==b.route.mode?"onhashchange":"onpopstate";a[f]=function(){K(a.location[b.route.mode])},G=l,a[f]()}else if(arguments[0].addEventListener){var g=arguments[0],h=arguments[1];g.href=J[b.route.mode]+g.pathname,h||(g.removeEventListener("click",k),g.addEventListener("click",k))}else if("string"==typeof arguments[0]){I=arguments[0];var i=arguments[1]===!0;a.history.pushState?(G=function(){a.history[i?"replaceState":"pushState"](null,a.document.title,J[b.route.mode]+I),l()},K(J[b.route.mode]+I)):a.location[b.route.mode]=I}},b.route.param=function(a){return L[a]},b.route.mode="search",b.prop=function(a){var b=function(){return arguments.length&&(a=arguments[0]),a};return b.toJSON=function(){return a},b},b.deferred=function(){var a=[],c=[],d={resolve:function(b){for(var c=0;c