X-Git-Url: http://git.roojs.org/?p=app.Builder.js;a=blobdiff_plain;f=resources%2Froo.builder.js;h=a53f114afc92243b84185d2071d73cab282743a8;hp=24f00c75ea6cc9d65e472699fa8a8fa71f41a328;hb=HEAD;hpb=c603619f00ecdf901be5d9904145335f98a882de diff --git a/resources/roo.builder.js b/resources/roo.builder.js index 24f00c75e..a53f114af 100644 --- a/resources/roo.builder.js +++ b/resources/roo.builder.js @@ -17,39 +17,46 @@ Builder = { - saveHTML : function(web_frame) + saveHTML : function( ) { - print("TRAVERSE DOM?"); + //print("TRAVERSE DOM?"); var dom = document.body; - print(dom); + //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:" + dom); + alert("IPC:SAVEHTML:" + ret); return ret; }, traverseDOMTree : function(cb, currentElement, depth) { - if (!currentElement) { + if (!currentElement ) { return; } - if (currentElement.class_name.match(/roo-dynamic/)) { + //console.log(currentElement); + if (currentElement.className && currentElement.className.match(/roo-dynamic/)) { return; } //Roo.log(currentElement); var j; - var nodeName = currentElement.node_name; - var tagName = currentElement.tag_name; + var nodeName = currentElement.nodeName; + var tagName = currentElement.tagName; if (nodeName == '#text') { - cb(currentElement.node_value); + cb(currentElement.nodeValue); return; } + if (nodeName.match(/^#/)) { // comments? + return; + } @@ -58,27 +65,34 @@ Builder = { 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') { + var attre = currentElement.attributes.item(i); + var aname = attre.name; + var aval = attre.value || ''; + if (aname=='id' && aval.match(/^roo\-/)) { // only roo -elements hide.. aname= 'xbuilderid'; } - // skip - if (currentElement.attributes.item(i).value == 'builderel') { + // skip -- component created by the builder? + if (aval == 'builderel') { return; } - attr.push(aname + '="' + currentElement.attributes.item(i).value + '"' ); + attr.push(aname + '="' + aval + '"' ); //?? escaping attributes? } - cb("<"+currentElement.tag_name+ ( attr.length ? (' ' + attr.join(' ') ) : '') + ">"); + cb("<"+currentElement.tagName+ ( attr.length ? (' ' + attr.join(' ') ) : '') + ">"); } else { cb("[unknown tag]"); @@ -86,17 +100,19 @@ Builder = { } else { tagName = false; } + + // Traverse the tree i = 0; - var currentElementChild = currentElement.child_nodes.item(i); + 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.node_name == '#text') { - cb(currentElementChild.node_value); + if (currentElementChild.nodeName == '#text') { + cb(currentElementChild.nodeValue); i++; - currentElementChild=currentElement.child_nodes.item(i); + currentElementChild=currentElement.childNodes.item(i); continue; } allText = false; @@ -110,7 +126,7 @@ Builder = { // Recursively traverse the tree structure of the child node this.traverseDOMTree(cb, currentElementChild, depth+1); i++; - currentElementChild=currentElement.child_nodes.item(i); + currentElementChild=currentElement.childNodes.item(i); } if (!allText) { // The remaining code is mostly for formatting the tree @@ -270,7 +286,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() @@ -300,6 +316,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']); @@ -313,12 +332,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']); + } - if (!tree.items || !tree.items.length) { return; } + tree.el.attr('xtype', tree['|xns'] + '.' + tree['xtype']); + //Roo.log(tree); + //Roo.log("Add xtype") - 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); + } + } @@ -327,6 +366,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