- commit
- d50ff2f2a74fba68b990fc7a471a268de75fed9a
- parent
- ab7a025d56d2b97eeb1e5268c1007c05d115330f
- Author
- Tobias Bengfort <tobias.bengfort@gmx.net>
- Date
- 2015-08-25 07:23
ignore root nodes in updateDOM
Diffstat
| M | src/muu-update-dom.js | 48 | +++++++++++++++++++++++++----------------------- |
1 files changed, 25 insertions, 23 deletions
diff --git a/src/muu-update-dom.js b/src/muu-update-dom.js
@@ -1,5 +1,5 @@ 1 1 /**2 -1 * Recreate DOM `source` in `target` by making only small adjustments.-1 2 * Recreate children of `source` in `target` by making only small adjustments. 3 3 * 4 4 * *The following section explains details about the current implementation. 5 5 * These are likely to change in the future.* @@ -49,32 +49,34 @@ define(['muu-js-helpers'], function(_) { 49 49 var nt = target.childNodes.length; 50 50 var ns = source.childNodes.length; 51 5152 -1 if (target.nodeType === source.nodeType && target.nodeName === source.nodeName && target.type === source.type) {53 -1 if (target.nodeType === 1) {54 -1 var muuClasses = _.filter(target.classList, function(cls) {55 -1 return cls.lastIndexOf('muu-', 0) === 0;56 -1 });57 -1 updateAttributes(target, source);58 -1 _.forEach(muuClasses, function(cls) {59 -1 target.classList.add(cls);60 -1 });61 -1 } else if (target.nodeType === 3) {62 -1 target.nodeValue = source.nodeValue;63 -1 }-1 52 for (var i = ns; i < nt; i++) { -1 53 target.removeChild(target.childNodes[ns]); -1 54 } -1 55 for (i = nt; i < ns; i++) { -1 56 target.appendChild(source.childNodes[nt]); -1 57 } -1 58 for (i = 0; i < nt && i < ns; i++) { -1 59 var tchild = target.childNodes[i]; -1 60 var schild = source.childNodes[i]; 64 6165 -1 if (target.nodeType !== 1 || !target.classList.contains('muu-isolate')) {66 -1 for (var i = ns; i < nt; i++) {67 -1 target.removeChild(target.childNodes[ns]);68 -1 }69 -1 for (i = nt; i < ns; i++) {70 -1 target.appendChild(source.childNodes[nt]);-1 62 if (tchild.nodeType === schild.nodeType && tchild.nodeName === schild.nodeName && tchild.type === schild.type) { -1 63 if (tchild.nodeType === 1) { -1 64 var muuClasses = _.filter(tchild.classList, function(cls) { -1 65 return cls.lastIndexOf('muu-', 0) === 0; -1 66 }); -1 67 updateAttributes(tchild, schild); -1 68 _.forEach(muuClasses, function(cls) { -1 69 tchild.classList.add(cls); -1 70 }); -1 71 } else if (tchild.nodeType === 3) { -1 72 tchild.nodeValue = schild.nodeValue; 71 73 }72 -1 for (i = 0; i < nt && i < ns; i++) {73 -1 updateDOM(target.childNodes[i], source.childNodes[i]);-1 74 if (tchild.nodeType !== 3 && !tchild.classList.contains('muu-isolate')) { -1 75 updateDOM(tchild, schild); 74 76 } -1 77 } else { -1 78 tchild.parentNode.replaceChild(schild, tchild); 75 79 }76 -1 } else {77 -1 target.parentNode.replaceChild(source, target);78 80 } 79 81 }; 80 82