sync
[roojs1] / Roo / htmleditor / TidySerializer.js
index d05ba33..f1fc44d 100644 (file)
@@ -6,21 +6,27 @@
  * @constructor
  * @method Serializer
  * @param {Object} settings Name/value settings object.
- * @param {tinymce.html.Schema} schema Schema instance to use.
  */
 
 
 Roo.htmleditor.TidySerializer = function(settings)
 {
-    Roo.apply(this.settings);
+    Roo.apply(thissettings);
     
     this.writer = new Roo.htmleditor.TidyWriter(settings);
     
-    //settings.validate = !('validate' in settings) || settings.validate;
-    //      self.schema = schema = schema || new Schema();
+    
 
 };
-Roo.apply(Roo.htmleditor.TidySerializer.prototype, {
+Roo.htmleditor.TidySerializer.prototype = {
+    
+    /**
+     * @param {boolean} inner do the inner of the node.
+     */
+    inner : false,
+    
+    writer : false,
+    
     /**
     * Serializes the specified node into a string.
     *
@@ -34,26 +40,28 @@ Roo.apply(Roo.htmleditor.TidySerializer.prototype, {
         
         // = settings.validate;
         var writer = this.writer;
+        var self  = this;
         this.handlers = {
             // #text
             3: function(node) {
-                writer.text(node.value, node.raw);
+                
+                writer.text(node.nodeValue, node);
             },
             // #comment
             8: function(node) {
-                writer.comment(node.value);
+                writer.comment(node.nodeValue);
             },
             // Processing instruction
             7: function(node) {
-                writer.pi(node.name, node.value);
+                writer.pi(node.name, node.nodeValue);
             },
             // Doctype
             10: function(node) {
-                writer.doctype(node.value);
+                writer.doctype(node.nodeValue);
             },
             // CDATA
             4: function(node) {
-                writer.cdata(node.value);
+                writer.cdata(node.nodeValue);
             },
             // Document fragment
             11: function(node) {
@@ -62,67 +70,51 @@ Roo.apply(Roo.htmleditor.TidySerializer.prototype, {
                     return;
                 }
                 while(node) {
-                    walk(node);
+                    self.walk(node);
                     node = node.nextSibling
                 }
             }
         };
         writer.reset();
-        1 != node.nodeType || this.inner ? handlers[11](node) : walk(node);
-    return writer.getContent();
+        1 != node.nodeType || this.inner ? this.handlers[11](node) : this.walk(node);
+        return writer.getContent();
+    },
 
-    function walk(node) {
-        var name, isEmpty, attrs, attrName, attrValue, sortedAttrs, i, l, elementRule, handler = handlers[node.type];
+    walk: function(node)
+    {
+        var attrName, attrValue, sortedAttrs, i, l, elementRule,
+            handler = this.handlers[node.nodeType];
+            
         if (handler) {
             handler(node);
-        } else {
-            name = node.name;
-            isEmpty = node.shortEnded;
-            attrs = node.attributes;
-            // Sort attributes
-            if (validate && attrs && attrs.length > 1) {
-                sortedAttrs = [];
-                sortedAttrs.map = {};
-                elementRule = schema.getElementRule(node.name);
-                if (elementRule) {
-                    for (i = 0, l = elementRule.attributesOrder.length; i < l; i++) {
-                        attrName = elementRule.attributesOrder[i];
-                        if (attrName in attrs.map) {
-                            attrValue = attrs.map[attrName];
-                            sortedAttrs.map[attrName] = attrValue;
-                            sortedAttrs.push({
-                                name: attrName,
-                                value: attrValue
-                            });
-                        }
-                    }
-                    for (i = 0, l = attrs.length; i < l; i++) {
-                        attrName = attrs[i].name;
-                        if (!(attrName in sortedAttrs.map)) {
-                            attrValue = attrs.map[attrName];
-                            sortedAttrs.map[attrName] = attrValue;
-                            sortedAttrs.push({
-                                name: attrName,
-                                value: attrValue
-                            });
-                        }
-                    }
-                    attrs = sortedAttrs;
-                }
-            }
-            writer.start(node.name, attrs, isEmpty);
-            if (!isEmpty) {
-                if (node = node.firstChild) {
-                    do {
-                        walk(node);
-                    } while (node = node.next);
-                }
-                writer.end(name);
-            }
+            return;
         }
+    
+        var name = node.nodeName;
+        var isEmpty = node.childNodes.length < 1;
+      
+        var writer = this.writer;
+        var attrs = node.attributes;
+        // Sort attributes
+        
+        writer.start(node.nodeName, attrs, isEmpty, node);
+        if (isEmpty) {
+            return;
+        }
+        node = node.firstChild;
+        if (!node) {
+            writer.end(name);
+            return;
+        }
+        while (node) {
+            this.walk(node);
+            node = node.nextSibling;
+        }
+        writer.end(name);
+        
+    
     }
     // Serialize element and treat all non elements as fragments
    
-};
-};
+};