Author: andyhot
Date: Mon Nov 20 15:37:40 2006
New Revision: 477408

URL: http://svn.apache.org/viewvc?view=rev&rev=477408
Log:
TAPESTRY-1129: Unpack emptry textareas for mozilla derivative browsers

Modified:
    tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/html.js
    tapestry/tapestry4/trunk/tapestry-framework/src/js/tests/test_html.js

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/html.js
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/html.js?view=diff&rev=477408&r1=477407&r2=477408
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/html.js 
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/html.js Mon Nov 
20 15:37:40 2006
@@ -5,6 +5,9 @@
  * Provides functionality related to parsing and rendering dom nodes.
  */
 tapestry.html={
+    
+        TextareaMatcher:'<textarea(.*?)/>', // regexp for compact textarea 
elements
+        TextareaReplacer:'<textarea$1></textarea>', // replace pattern for 
compact textareas
        
         /**
         * Function: getContentAsString
@@ -12,12 +15,12 @@
         * Takes a dom node and returns its contents rendered in a string.
          *
          * The resulting string does NOT contain any markup (or attributes) of
-         * the given node - only child nodes are rendered and returned.
+         * the given node - only child nodes are rendered and returned.Content
          *
          * Implementation Note: This function tries to make use of browser 
          * specific features (the xml attribute of nodes in IE and the 
XMLSerializer
          * object in Mozilla derivatives) - if those fails, a generic 
implementation
-         * is guaranteed to work in all platforms.
+         * is used that is guaranteed to work in all platforms.
         * 
         * Parameters: 
         * 
@@ -84,6 +87,7 @@
                if (s == "undefined")
                        return this._getContentAsStringGeneric(node);
            }
+            s = this._processTextareas(s);
            return s;
        },
        
@@ -106,5 +110,14 @@
                        }
                }
                return s;       
-       }
+       },
+        
+        _processTextareas:function(htmlData)
+       {
+               var match = new RegExp(tapestry.html.TextareaMatcher);
+                while (htmlData.match(match)){
+                    htmlData = htmlData.replace(match, 
tapestry.html.TextareaReplacer);
+                }
+               return htmlData;
+       }
 }

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/js/tests/test_html.js
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/tests/test_html.js?view=diff&rev=477408&r1=477407&r2=477408
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/tests/test_html.js 
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/tests/test_html.js Mon 
Nov 20 15:37:40 2006
@@ -23,6 +23,23 @@
         // only browser based tests will show if this is working
 }
 
+function test_html_getElementAsString(){
+    
+        var node = _createTestNode();
+        
+        var data = tapestry.html.getElementAsString(node).toLowerCase();
+        jum.assertEquals("<div id=\"testid\"><div 
id=\"testid2\">content</div></div>", data);
+}
+
+function test_html_processTextareas(){
+    var initial = "start<textarea id='2' rows=4/>";
+    var expected = "start<textarea id='2' rows=4></textarea>";
+    
+    jum.assertEquals(expected, tapestry.html._processTextareas(initial));
+    jum.assertEquals(expected + expected, 
+        tapestry.html._processTextareas(initial+initial));
+}
+
 function _createTestNode(element, empty){
        var node = document.createElement("div");
        node.setAttribute("id", "testid");


Reply via email to