myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r992044 - /myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Dom.js
Date Thu, 02 Sep 2010 18:39:55 GMT
Author: lu4242
Date: Thu Sep  2 18:39:55 2010
New Revision: 992044

URL: http://svn.apache.org/viewvc?rev=992044&view=rev
Log:
MYFACES-2904 javascript _Dom._outerHtml does not handle table items (<tr>, <tbody>.
...)

Modified:
    myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Dom.js

Modified: myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Dom.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Dom.js?rev=992044&r1=992043&r2=992044&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Dom.js
(original)
+++ myfaces/core/trunk/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Dom.js
Thu Sep  2 18:39:55 2010
@@ -222,10 +222,18 @@ myfaces._impl.core._Runtime.singletonExt
     },
 
     _outerHTMLCompliant: function(item, markup) {
-
-        var dummyPlaceHolder = this.getDummyPlaceHolder(); //document.createElement("div");
-        dummyPlaceHolder.innerHTML = markup;
-        var evalNodes = dummyPlaceHolder.childNodes;
+        var evalNodes;
+        var itemNodeName = item.nodeName.toLowerCase();
+        if (itemNodeName == "table" || itemNodeName == "thead" ||
+            itemNodeName == "tbody" || itemNodeName == "tfoot" ||
+            itemNodeName == "th"    || itemNodeName == "tr"    ||
+            itemNodeName == "td"){
+            evalNodes = this._outerHTMLGetEvalTableNodes(item, markup);
+        } else {
+            var dummyPlaceHolder = this.getDummyPlaceHolder(); //document.createElement("div");
+            dummyPlaceHolder.innerHTML = markup;
+            evalNodes = dummyPlaceHolder.childNodes;
+        }
         var evalNodeLen = evalNodes.length;
 
         if (evalNodeLen == 1) {
@@ -235,10 +243,39 @@ myfaces._impl.core._Runtime.singletonExt
         } else {
             return this.replaceElements(item, evalNodes);
         }
-
     },
 
-
+    _outerHTMLGetEvalTableNodes: function(item, markup) {
+        var evalNodes;
+        var itemNodeName = item.nodeName.toLowerCase();
+        var probe = this.getDummyPlaceHolder(); //document.createElement("div");
+        if (itemNodeName == "td"){
+            probe.innerHTML = "<table><tbody><tr><td></td></tr></tbody></table>";
+        } else {
+            probe.innerHTML = "<table><"+itemNodeName+"></"+itemNodeName+">"+"</table>";
+        }
+        var depth = 0;
+        var newProbe = probe;
+        while (newProbe) {
+            newProbe = newProbe.childNodes[0];
+            depth++;
+        }
+        depth--;
+        this._removeChildNodes(probe, false);
+        probe.innerHTML = "";
+        var dummyPlaceHolder = this.getDummyPlaceHolder();//document.createElement("div");
+        if (itemNodeName == "td"){
+            dummyPlaceHolder.innerHTML = "<table><tbody><tr>"+markup+"</tr></tbody></table>";
+        } else {
+            dummyPlaceHolder.innerHTML = "<table>"+markup+"</table>";
+        }
+        evalNodes = dummyPlaceHolder;
+        for (var cnt = 0; cnt < depth; cnt++) {
+            evalNodes = evalNodes.childNodes[0];
+        }
+        evalNodes = (evalNodes.parentNode) ? evalNodes.parentNode.childNodes : null;
+        return evalNodes
+    },
 
 
     /**
@@ -260,8 +297,17 @@ myfaces._impl.core._Runtime.singletonExt
         //http://blogs.perl.org/users/clinton_gormley/2010/02/forcing-ie-to-accept-script-tags-in-innerhtml.html
         //we have to cope with deficiencies between ie and its simulations in this case
         var probe = this.getDummyPlaceHolder();//document.createElement("div");
-
-        probe.innerHTML = "<table><tbody><tr><td><div></div></td></tr></tbody></table>";
+        var isTableContentTag = false;
+        var itemNodeName = item.nodeName.toLowerCase();
+        if (itemNodeName == "thead" || itemNodeName == "tbody" || itemNodeName == "tfoot"
||
+            itemNodeName == "th"    || itemNodeName == "tr"){
+            probe.innerHTML = "<table><"+itemNodeName+"></"+itemNodeName+">"+"</table>";
+            isTableContentTag = true;
+        } else if (itemNodeName == "td"){
+            probe.innerHTML = "<table><tbody><tr><td></td></tr></tbody></table>";
+        } else {
+            probe.innerHTML = "<table><tbody><tr><td><div></div></td></tr></tbody></table>";
+        }
         var depth = 0;
         var newProbe = probe;
         while (newProbe) {
@@ -276,10 +322,16 @@ myfaces._impl.core._Runtime.singletonExt
 
         var dummyPlaceHolder = this.getDummyPlaceHolder();//document.createElement("div");
 
-
         //fortunately a table element also works which is less critical than form elements
regarding
         //the inner content
-        dummyPlaceHolder.innerHTML = "<table><tbody><tr><td>" + markup
+ "</td></tr></tbody></table>";
+        if (isTableContentTag){
+            dummyPlaceHolder.innerHTML = "<table>"+markup+"</table>";
+        }else if (itemNodeName == "td"){
+            dummyPlaceHolder.innerHTML = "<table><tbody><tr>"+markup+"</tr></tbody></table>";
+        }else{
+            dummyPlaceHolder.innerHTML = "<table><tbody><tr><td>"
+ markup + "</td></tr></tbody></table>";
+        }
+        
         evalNodes = dummyPlaceHolder;
 
         for (var cnt = 0; cnt < depth; cnt++) {



Mime
View raw message