From c603619f00ecdf901be5d9904145335f98a882de Mon Sep 17 00:00:00 2001 From: Alan Knowles Date: Wed, 27 Aug 2014 15:54:39 +0800 Subject: [PATCH] resources/roo.builder.js --- resources/roo.builder.js | 109 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 108 insertions(+), 1 deletion(-) diff --git a/resources/roo.builder.js b/resources/roo.builder.js index a15027871..24f00c75e 100644 --- a/resources/roo.builder.js +++ b/resources/roo.builder.js @@ -16,7 +16,114 @@ Builder = { id : 1, - + + saveHTML : function(web_frame) + { + print("TRAVERSE DOM?"); + + var dom = document.body; + print(dom); + var ret = ''; + //Roo.select('body > div',true).each(function(el) { + this.traverseDOMTree(function(s) { ret+=s; }, dom, 1); + alert("IPC:SAVEHTML:" + dom); + return ret; + }, + + + traverseDOMTree : function(cb, currentElement, depth) { + if (!currentElement) { + + return; + } + if (currentElement.class_name.match(/roo-dynamic/)) { + return; + } + + //Roo.log(currentElement); + var j; + var nodeName = currentElement.node_name; + var tagName = currentElement.tag_name; + + if (nodeName == '#text') { + cb(currentElement.node_value); + return; + + } + + + + if(nodeName == 'BR'){ + cb("
"); + return; + } + if (nodeName != 'BODY') { + + + + var i = 0; + // Prints the node tagName, such as , , etc + if (tagName) { + var attr = []; + for(i = 0; i < currentElement.attributes.length;i++) { + var aname = currentElement.attributes.item(i).name; + if (aname=='id') { + aname= 'xbuilderid'; + } + // skip + if (currentElement.attributes.item(i).value == 'builderel') { + return; + } + attr.push(aname + '="' + currentElement.attributes.item(i).value + '"' ); + } + + + cb("<"+currentElement.tag_name+ ( attr.length ? (' ' + attr.join(' ') ) : '') + ">"); + } + else { + cb("[unknown tag]"); + } + } else { + tagName = false; + } + // Traverse the tree + i = 0; + var currentElementChild = currentElement.child_nodes.item(i); + var allText = true; + while (currentElementChild) { + // Formatting code (indent the tree so it looks nice on the screen) + + if (currentElementChild.node_name == '#text') { + cb(currentElementChild.node_value); + i++; + currentElementChild=currentElement.child_nodes.item(i); + continue; + } + allText = false; + cb("\n"); + for (j = 0; j < depth; j++) { + // ¦ is just a vertical line + cb(" "); + } + + + // Recursively traverse the tree structure of the child node + this.traverseDOMTree(cb, currentElementChild, depth+1); + i++; + currentElementChild=currentElement.child_nodes.item(i); + } + if (!allText) { + // The remaining code is mostly for formatting the tree + cb("\n"); + for (j = 0; j < depth - 1; j++) { + cb(" "); + } + } + if (tagName) { + cb(""); + } + + }, // this lot is to deal with draging // selecting? - not used at present -- 2.39.2