X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=resources%2Froo.builder.js;h=2163657daada9296502f5d01a5503b5f7f78db8e;hb=bca805c292ae29615ca9649e453407edb960d3d8;hp=a15027871bda8a4b78077fd3edc9adbd0356911a;hpb=bf3eb87a5c0e746beadebd4953656799b8bb9a60;p=app.Builder.js diff --git a/resources/roo.builder.js b/resources/roo.builder.js index a15027871..2163657da 100644 --- a/resources/roo.builder.js +++ b/resources/roo.builder.js @@ -16,7 +16,128 @@ Builder = { id : 1, + + saveHTML : function( ) + { + //print("TRAVERSE DOM?"); + + var dom = document.body; + //print(dom); + var ret = ''; + //Roo.select('body > div',true).each(function(el) { + // if the tree is not ready yet? + + + this.traverseDOMTree(function(s) { ret+=s; }, dom, 1); + alert("IPC:SAVEHTML:" + ret); + return ret; + }, + + + traverseDOMTree : function(cb, currentElement, depth) { + if (!currentElement ) { + + return; + } + //console.log(currentElement); + if (currentElement.className && currentElement.className.match(/roo-dynamic/)) { + return; + } + + //Roo.log(currentElement); + var j; + var nodeName = currentElement.nodeName; + var tagName = currentElement.tagName; + + if (nodeName == '#text') { + cb(currentElement.nodeValue); + return; + + } + if (nodeName.match(/^#/)) { // comments? + return; + } + + + + if(nodeName == 'BR'){ + cb("
"); + return; + } + if (nodeName != 'BODY') { + //Roo.log(currentElement); + if (currentElement.hasAttribute('flexy:include')) { + + cb( ''); + return; + } + + 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.tagName+ ( attr.length ? (' ' + attr.join(' ') ) : '') + ">"); + } + else { + cb("[unknown tag]"); + } + } else { + tagName = false; + } + + + // Traverse the tree + i = 0; + var currentElementChild = currentElement.childNodes.item(i); + var allText = true; + while (currentElementChild) { + // Formatting code (indent the tree so it looks nice on the screen) + + if (currentElementChild.nodeName == '#text') { + cb(currentElementChild.nodeValue); + i++; + currentElementChild=currentElement.childNodes.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.childNodes.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 @@ -163,7 +284,7 @@ Builder = { } id = ''+ id; var bid = id.length ? 'builder-' + id : ''; - console.log('{ "hover-node" : "' + bid + '"}'); + //console.log('{ "hover-node" : "' + bid + '"}'); this.lastID = id; }, clearBootstrap : function() @@ -193,6 +314,9 @@ Builder = { applyFlexy: function(tree) { + if (!tree.el) { + return; + } if (typeof(tree['flexy:foreach']) != 'undefined') { //Roo.log("add flexy:foreach"); tree.el.attr('flexy:foreach', tree['flexy:foreach']); @@ -206,12 +330,32 @@ Builder = { tree.el.attr('xtype', tree['xtype-bootstrap']); } + if (typeof(tree['flexy:include']) != 'undefined') { + //Roo.log("add flexy:if"); + tree.el.attr('flexy:include', tree['flexy:include']); + } + + if (typeof(tree['flexy:ignore']) != 'undefined') { + //Roo.log("add flexy:if"); + tree.el.attr('flexy:ignore', tree['flexy:ignore']); + } + + tree.el.attr('xtype', tree['|xns'] + '.' + tree['xtype']); + Roo.log(tree); + //Roo.log("Add xtype") - if (!tree.items || !tree.items.length) { return; } - for (var i = 0; i < tree.items.length; i++){ - this.applyFlexy(tree.items[i]); + + if (tree.items && tree.items.length > 0) { + //Roo.log(tree); + for (var i = 0; i < tree.items.length; i++){ + this.applyFlexy(tree.items[i]); + } } + if (typeof(tree.menu) == 'object') { + this.applyFlexy(tree.menu); + } + } @@ -220,6 +364,8 @@ Builder = { Roo.onReady(function() { Builder.clearBootstrap(); }); Roo.XComponent.on('buildcomplete', function() { Roo.log("xcomponent built!"); + var m = Roo.XComponent.modules; + Builder.applyFlexy(m[m.length-1].el); - Builder.applyFlexy(Roo.XComponent.modules[0].el); + Builder.saveHTML.defer(100, Builder); }); \ No newline at end of file