From 9dcffab2ac8a8a6b2d7fc86b425abfd1cf3ea528 Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Tue, 8 Apr 2014 15:48:15 -0400 Subject: [PATCH] don't touch DOM to check for parenthood --- archive/v0.1.4/mithril-tests.js | 12 ++++++------ archive/v0.1.4/mithril.js | 12 ++++++------ archive/v0.1.4/mithril.min.js | 2 +- archive/v0.1.4/mithril.min.map | 2 +- archive/v0.1.4/mithril.min.zip | Bin 20825 -> 20873 bytes mithril.js | 12 ++++++------ 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/archive/v0.1.4/mithril-tests.js b/archive/v0.1.4/mithril-tests.js index 200111a3..fde7a491 100644 --- a/archive/v0.1.4/mithril-tests.js +++ b/archive/v0.1.4/mithril-tests.js @@ -32,7 +32,7 @@ new function(window) { } return cell } - function build(parent, data, cached) { + function build(parent, data, cached, shouldReattach) { if (data === null || data === undefined) { if (cached) clear(cached.nodes) return @@ -49,7 +49,7 @@ new function(window) { if (dataType == "[object Array]") { var nodes = [], intact = cached.length === data.length for (var i = 0; i < data.length; i++) { - var item = build(parent, data[i], cached[i]) + var item = build(parent, data[i], cached[i], shouldReattach) if (item === undefined) continue if (!item.nodes.intact) intact = false cached[i] = item @@ -69,15 +69,15 @@ new function(window) { var node, isNew = cached.nodes.length === 0 if (isNew) { node = window.document.createElement(data.tag) - cached = {tag: data.tag, attrs: setAttributes(node, data.attrs, {}), children: build(node, data.children, cached.children), nodes: [node]} + cached = {tag: data.tag, attrs: setAttributes(node, data.attrs, {}), children: build(node, data.children, cached.children, true), nodes: [node]} parent.appendChild(node) } else { node = cached.nodes[0] setAttributes(node, data.attrs, cached.attrs) - cached.children = build(node, data.children, cached.children) + cached.children = build(node, data.children, cached.children, false) cached.nodes.intact = true - if (node.parentNode !== parent) parent.appendChild(node) + if (shouldReattach === true) parent.appendChild(node) } if (type.call(data.attrs["config"]) == "[object Function]") data.attrs["config"](node, !isNew) } @@ -180,7 +180,7 @@ new function(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, cell, cellCache[id]) + cellCache[id] = build(node, cell, cellCache[id], false) } m.trust = function(value) { diff --git a/archive/v0.1.4/mithril.js b/archive/v0.1.4/mithril.js index 86cd8aa6..7fcb3937 100644 --- a/archive/v0.1.4/mithril.js +++ b/archive/v0.1.4/mithril.js @@ -32,7 +32,7 @@ new function(window) { } return cell } - function build(parent, data, cached) { + function build(parent, data, cached, shouldReattach) { if (data === null || data === undefined) { if (cached) clear(cached.nodes) return @@ -49,7 +49,7 @@ new function(window) { if (dataType == "[object Array]") { var nodes = [], intact = cached.length === data.length for (var i = 0; i < data.length; i++) { - var item = build(parent, data[i], cached[i]) + var item = build(parent, data[i], cached[i], shouldReattach) if (item === undefined) continue if (!item.nodes.intact) intact = false cached[i] = item @@ -69,15 +69,15 @@ new function(window) { var node, isNew = cached.nodes.length === 0 if (isNew) { node = window.document.createElement(data.tag) - cached = {tag: data.tag, attrs: setAttributes(node, data.attrs, {}), children: build(node, data.children, cached.children), nodes: [node]} + cached = {tag: data.tag, attrs: setAttributes(node, data.attrs, {}), children: build(node, data.children, cached.children, true), nodes: [node]} parent.appendChild(node) } else { node = cached.nodes[0] setAttributes(node, data.attrs, cached.attrs) - cached.children = build(node, data.children, cached.children) + cached.children = build(node, data.children, cached.children, false) cached.nodes.intact = true - if (node.parentNode !== parent) parent.appendChild(node) + if (shouldReattach === true) parent.appendChild(node) } if (type.call(data.attrs["config"]) == "[object Function]") data.attrs["config"](node, !isNew) } @@ -180,7 +180,7 @@ new function(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, cell, cellCache[id]) + cellCache[id] = build(node, cell, cellCache[id], false) } m.trust = function(value) { diff --git a/archive/v0.1.4/mithril.min.js b/archive/v0.1.4/mithril.min.js index ea3fb882..6c01d404 100644 --- a/archive/v0.1.4/mithril.min.js +++ b/archive/v0.1.4/mithril.min.js @@ -4,5 +4,5 @@ http://github.com/lhorie/mithril.js (c) Leo Horie License: MIT */ -!new function(a){function b(e,f,g){if(null===f||void 0===f)return void(g&&d(g.nodes));if("retain"!==f.subtree){var h=s.call(g),i=s.call(f);if(h!=i&&(null!==g&&void 0!==g&&d(g.nodes),g=new f.constructor,g.nodes=[]),"[object Array]"==i){for(var j=[],k=g.length===f.length,l=0;l-1?new f.constructor(f):f,g.nodes=[n]}else if(g.valueOf()!==f.valueOf()){if(f.$trusted){var q=g.nodes[0],j=[q];if(q){for(;q=q.nextSibling;)j.push(q);d(j);var p=e.lastChild;e.insertAdjacentHTML("beforeend",f),n=p?p.nextSibling:e.firstChild}else e.innerHTML=f}else n=g.nodes[0],e.appendChild(n),n.nodeValue=f;g=new f.constructor(f),g.nodes=[n]}else g.nodes.intact=!0}return g}}function c(b,c,d){for(var e in c){var g=c[e],h=d[e];if(!(e in d)||h!==g||b===a.document.activeElement){if("config"===e)continue;if("function"==typeof g&&0==e.indexOf("on"))String(g)!==String(h)&&(b[e]=f(g,b));else if("style"===e)for(var i in g)(void 0===h||h[i]!==g[i])&&(b.style[i]=g[i]);else e in b?b[e]=g:b.setAttribute(e,g);d[e]=g}}return d}function d(a){for(var b=0;b16)m.redraw();else{var b=a.cancelAnimationFrame||a.clearTimeout,c=a.requestAnimationFrame||a.setTimeout;b(E),E=c(m.redraw,0)}}function h(a,b,c){J={};for(var d in b){if(d==c)return!void m.module(a,b[d]);var e=new RegExp("^"+d.replace(/:[^\/]+/g,"([^\\/]+)")+"$");if(e.test(c))return!void c.replace(e,function(){for(var c=d.match(/:[^\/]+/g),e=[].slice.call(arguments,1,-2),f=0;f0&&("GET"==a.method?a.url=a.url+(a.url.indexOf("?")<0?"?":"&")+n(b):a.data=c(b)),a}function p(a,b){var c=a.match(/:[a-z]\w+/gi);if(c&&b)for(var d=0;d0&&(f.attrs[d]=h.join(" "))}f=e(f),f.attrs=e(f.attrs),f.children=b?a[2]:a[1];for(var j in c)f.attrs[j]=j==d?(f.attrs[j]||"")+" "+c[j]:c[j];return f};var v,w={insertAdjacentHTML:function(b,c){a.document.write(c),a.document.close()},appendChild:function(b){void 0===v&&(v=a.document.createElement("html")),"HTML"==b.nodeName?v=b:v.appendChild(b),a.document.documentElement!==v&&a.document.replaceChild(v,a.document.documentElement)}},x=[],y={};m.render=function(c,d){var e=x.indexOf(c),f=0>e?x.push(c)-1:e,g=c==a.document||c==a.document.documentElement?w:c;y[f]=b(g,d,y[f])},m.trust=function(a){return a=new String(a),a.$trusted=!0,a};var z,A={view:function(){}},B={},C=0,D=0,E=0;m.module=function(a,b){m.startComputation(),z=a,A=b,B=new b.controller,m.endComputation()},m.redraw=function(){m.render(z,A.view(B)),D=C};var F=0,G=null;m.startComputation=function(){F++},m.endComputation=function(){F=Math.max(F-1,0),0==F&&(g(),G&&(G(),G=null))},m.withAttr=function(a,b){return function(c){b(a in c.currentTarget?c.currentTarget[a]:c.currentTarget.getAttribute(a))}};var H={pathname:"",hash:"#",search:"?"},I=function(){},J={};m.route=function(){if(3==arguments.length){var b=arguments[0],c=arguments[1],d=arguments[2];I=function(a){var e=a.slice(H[m.route.mode].length);h(b,d,e)||m.route(c,!0)};var e="hash"==m.route.mode?"onhashchange":"onpopstate";a[e]=function(){I(a.location[m.route.mode])},G=j,a[e]()}else if(arguments[0].addEventListener){var f=arguments[0],g=arguments[1];g||(f.removeEventListener("click",i),f.addEventListener("click",i))}else if("string"==typeof arguments[0]){var k=arguments[0],l=arguments[1]===!0;a.history.pushState?(G=function(){a.history[l?"replaceState":"pushState"](null,a.document.title,H[m.route.mode]+k),j()},I(H[m.route.mode]+k)):a.location[m.route.mode]=k}},m.route.param=function(a){return J[a]},m.route.mode="search",m.prop=function(a){return function(){return arguments.length&&(a=arguments[0]),a}},m.deferred=function(){var a=[],b=[],c={resolve:function(b){for(var c=0;c-1?new f.constructor(f):f,g.nodes=[o]}else if(g.valueOf()!==f.valueOf()){if(f.$trusted){var r=g.nodes[0],k=[r];if(r){for(;r=r.nextSibling;)k.push(r);d(k);var q=e.lastChild;e.insertAdjacentHTML("beforeend",f),o=q?q.nextSibling:e.firstChild}else e.innerHTML=f}else o=g.nodes[0],e.appendChild(o),o.nodeValue=f;g=new f.constructor(f),g.nodes=[o]}else g.nodes.intact=!0}return g}}function c(b,c,d){for(var e in c){var g=c[e],h=d[e];if(!(e in d)||h!==g||b===a.document.activeElement){if("config"===e)continue;if("function"==typeof g&&0==e.indexOf("on"))String(g)!==String(h)&&(b[e]=f(g,b));else if("style"===e)for(var i in g)(void 0===h||h[i]!==g[i])&&(b.style[i]=g[i]);else e in b?b[e]=g:b.setAttribute(e,g);d[e]=g}}return d}function d(a){for(var b=0;b16)m.redraw();else{var b=a.cancelAnimationFrame||a.clearTimeout,c=a.requestAnimationFrame||a.setTimeout;b(E),E=c(m.redraw,0)}}function h(a,b,c){J={};for(var d in b){if(d==c)return!void m.module(a,b[d]);var e=new RegExp("^"+d.replace(/:[^\/]+/g,"([^\\/]+)")+"$");if(e.test(c))return!void c.replace(e,function(){for(var c=d.match(/:[^\/]+/g),e=[].slice.call(arguments,1,-2),f=0;f0&&("GET"==a.method?a.url=a.url+(a.url.indexOf("?")<0?"?":"&")+n(b):a.data=c(b)),a}function p(a,b){var c=a.match(/:[a-z]\w+/gi);if(c&&b)for(var d=0;d0&&(f.attrs[d]=h.join(" "))}f=e(f),f.attrs=e(f.attrs),f.children=b?a[2]:a[1];for(var j in c)f.attrs[j]=j==d?(f.attrs[j]||"")+" "+c[j]:c[j];return f};var v,w={insertAdjacentHTML:function(b,c){a.document.write(c),a.document.close()},appendChild:function(b){void 0===v&&(v=a.document.createElement("html")),"HTML"==b.nodeName?v=b:v.appendChild(b),a.document.documentElement!==v&&a.document.replaceChild(v,a.document.documentElement)}},x=[],y={};m.render=function(c,d){var e=x.indexOf(c),f=0>e?x.push(c)-1:e,g=c==a.document||c==a.document.documentElement?w:c;y[f]=b(g,d,y[f],!1)},m.trust=function(a){return a=new String(a),a.$trusted=!0,a};var z,A={view:function(){}},B={},C=0,D=0,E=0;m.module=function(a,b){m.startComputation(),z=a,A=b,B=new b.controller,m.endComputation()},m.redraw=function(){m.render(z,A.view(B)),D=C};var F=0,G=null;m.startComputation=function(){F++},m.endComputation=function(){F=Math.max(F-1,0),0==F&&(g(),G&&(G(),G=null))},m.withAttr=function(a,b){return function(c){b(a in c.currentTarget?c.currentTarget[a]:c.currentTarget.getAttribute(a))}};var H={pathname:"",hash:"#",search:"?"},I=function(){},J={};m.route=function(){if(3==arguments.length){var b=arguments[0],c=arguments[1],d=arguments[2];I=function(a){var e=a.slice(H[m.route.mode].length);h(b,d,e)||m.route(c,!0)};var e="hash"==m.route.mode?"onhashchange":"onpopstate";a[e]=function(){I(a.location[m.route.mode])},G=j,a[e]()}else if(arguments[0].addEventListener){var f=arguments[0],g=arguments[1];g||(f.removeEventListener("click",i),f.addEventListener("click",i))}else if("string"==typeof arguments[0]){var k=arguments[0],l=arguments[1]===!0;a.history.pushState?(G=function(){a.history[l?"replaceState":"pushState"](null,a.document.title,H[m.route.mode]+k),j()},I(H[m.route.mode]+k)):a.location[m.route.mode]=k}},m.route.param=function(a){return J[a]},m.route.mode="search",m.prop=function(a){return function(){return arguments.length&&(a=arguments[0]),a}},m.deferred=function(){var a=[],b=[],c={resolve:function(b){for(var c=0;co)E7Pr2j`>WH`cRbUfjcw&XhKsXnx-V$5zrAi6u&e4 z>1zwz6>V2dUpHN~P8LP8GuRKhD-a+kx-hye5}+`;D2i^{255nf>yp#o)dB z?&sWd@4Jus^ZTA3eBimdo*El}bp-$ZbMpO|{^6&;`S=?nBOkwa^@pRZ{NB_1(-pZB zD46xSZ&zZ~!MY?xDbrz}PHol5a~&@0RK%#6s>sw;a}#gJ5;RZS$_r;XfY>zv-}2!0dM09rpM{ zVg*D5pjUR__@84}=9xDrG0JY`k+XfmE`*b$72j$8!EIImyYTq5hpYpP>Ts?+v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