fix dialog on htmleditor link
[roojs1] / Roo / DomHelper.js
index e889ac0..a896788 100644 (file)
@@ -252,8 +252,9 @@ Roo.DomHelper = function(){
     var updateNode = function(from, to)
     {
         // should we handle non-standard elements?
-        
+        Roo.log(["UpdateNode" , from, to]);
         if (from.nodeType != to.nodeType) {
+            Roo.log(["ReplaceChild - mismatch notType" , to, from ]);
             from.parentNode.replaceChild(to, from);
         }
         
@@ -265,9 +266,15 @@ Roo.DomHelper = function(){
             from.data = to.data;
             return;
         }
-        
+        if (!from.parentNode) {
+            // not sure why this is happening?
+            return;
+        }
         // assume 'to' doesnt have '1/3 nodetypes!
+        // not sure why, by from, parent node might not exist?
         if (from.nodeType !=1 || from.tagName != to.tagName) {
+            Roo.log(["ReplaceChild" , from, to ]);
+            
             from.parentNode.replaceChild(to, from);
             return;
         }
@@ -277,13 +284,22 @@ Roo.DomHelper = function(){
             if (to.hasAttribute(ar[i].name)) {
                 continue;
             }
+            if (ar[i].name == 'id') { // always keep ids?
+               continue;
+            }
+            //if (ar[i].name == 'style') {
+            //   throw "style removed?";
+            //}
+            Roo.log("removeAttribute" + ar[i].name);
             from.removeAttribute(ar[i].name);
         }
         ar = to.attributes;
         for(var i = 0; i< ar.length;i++) {
             if (from.getAttribute(ar[i].name) == to.getAttribute(ar[i].name)) {
+                Roo.log("skipAttribute " + ar[i].name  + '=' + to.getAttribute(ar[i].name));
                 continue;
             }
+            Roo.log("updateAttribute " + ar[i].name + '=>' + to.getAttribute(ar[i].name));
             from.setAttribute(ar[i].name, to.getAttribute(ar[i].name));
         }
         // children
@@ -291,19 +307,34 @@ Roo.DomHelper = function(){
         var tar = Array.from(to.childNodes);
         // if the lengths are different.. then it's probably a editable content change, rather than
         // a change of the block definition..
-        if (from.innerHTML == to.innerHTML) {
+        
+        // this did notwork , as our rebuilt nodes did not include ID's so did not match at all.
+         /*if (from.innerHTML == to.innerHTML) {
             return;
         }
         if (far.length != tar.length) {
             from.innerHTML = to.innerHTML;
             return;
         }
+        */
         
-        for(var i = 0; i < far.length; i++) {
-            updateNode(far[i], tar[i]);
+        for(var i = 0; i < Math.max(tar.length, far.length); i++) {
+            if (i >= far.length) {
+                from.appendChild(tar[i]);
+                Roo.log(["add", tar[i]]);
+                
+            } else if ( i  >= tar.length) {
+                from.removeChild(far[i]);
+                Roo.log(["remove", far[i]]);
+            } else {
+                
+                updateNode(far[i], tar[i]);
+            }    
         }
         
         
+        
+        
     };