X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=Roo%2Fhtmleditor%2FTidySerializer.js;h=243387d4e7795bc4e3cd9f70190050ce81e2ce79;hb=8aeccee3abcd73c8b5f57ecaf0e4bf407e5ab5e4;hp=5b8be8332a804c9b9ea1fe5fb8cec1f4b11641c4;hpb=d33992f97d79ab43c8d93e90424280b59945eef6;p=roojs1 diff --git a/Roo/htmleditor/TidySerializer.js b/Roo/htmleditor/TidySerializer.js index 5b8be8332a..243387d4e7 100644 --- a/Roo/htmleditor/TidySerializer.js +++ b/Roo/htmleditor/TidySerializer.js @@ -20,13 +20,15 @@ Roo.htmleditor.TidySerializer = function(settings) // 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. * @@ -79,58 +81,71 @@ Roo.apply(Roo.htmleditor.TidySerializer.prototype, { return writer.getContent(); }, - walk: function(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.type]; + 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 - }); - } + return; + } + + var name = node.nodeName; + var isEmpty = node.childNodes.length < 1; + var writer = this.writer; + var 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 + }); } - attrs = sortedAttrs; } - } - writer.start(node.name, attrs, isEmpty); - if (!isEmpty) { - if (node = node.firstChild) { - do { - walk(node); - } while (node = node.next); + 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 + }); + } } - writer.end(name); + attrs = sortedAttrs; } } + */ + writer.start(node.name, attrs, isEmpty); + if (isEmpty) { + return; + } + node = node.firstChild; + if (!node) { + writer.end(name); + return; + } + while (node) { + walk(node); + node = node.nextNode; + } + writer.end(name); + + } // Serialize element and treat all non elements as fragments -}; -}; +};