diff --git a/blockly_compressed.js b/blockly_compressed.js index faf63e175..d78923f02 100644 --- a/blockly_compressed.js +++ b/blockly_compressed.js @@ -942,7 +942,7 @@ b.setAttribute("collapsed",!0);a.disabled&&b.setAttribute("disabled",!0);a.isDel Blockly.Xml.domToPrettyText=function(a){a=Blockly.Xml.domToText(a).split("<");for(var b="",c=1;c"!=d.slice(-2)&&(b+=" ")}a=a.join("\n");a=a.replace(/(<(\w+)\b[^>]*>[^\n]*)\n *<\/\2>/g,"$1");return a.replace(/^\n/,"")}; Blockly.Xml.textToDom=function(a){a=(new DOMParser).parseFromString(a,"text/xml");if(!a||!a.firstChild||"xml"!=a.firstChild.nodeName.toLowerCase()||a.firstChild!==a.lastChild)throw"Blockly.Xml.textToDom did not obtain a valid XML tree.";return a.firstChild}; Blockly.Xml.domToWorkspace=function(a,b){var c;Blockly.RTL&&(c=a.getWidth());for(var d=0,e;e=b.childNodes[d];d++)if("block"==e.nodeName.toLowerCase()){var f=Blockly.Xml.domToBlock(a,e),g=parseInt(e.getAttribute("x"),10);e=parseInt(e.getAttribute("y"),10);isNaN(g)||isNaN(e)||f.moveBy(Blockly.RTL?c-g:g,e)}}; -Blockly.Xml.domToBlock=function(a,b,c){b=Blockly.Xml.domToBlockHeadless_(a,b,c);if(a.rendered){a=b.getDescendants();for(c=a.length-1;0<=c;c--)a[c].setConnectionsHidden(!0),a[c].initSvg();for(c=a.length-1;0<=c;c--)a[c].render(!1);for(c=a.length-1;0<=c;c--)a[c].setConnectionsHidden(!1);b.updateDisabled();Blockly.fireUiEvent(window,"resize")}return b}; +Blockly.Xml.domToBlock=function(a,b,c){b=Blockly.Xml.domToBlockHeadless_(a,b,c);if(a.rendered){var d=b.getDescendants();for(a=d.length-1;0<=a;a--)d[a].setConnectionsHidden(!0),d[a].initSvg();for(a=d.length-1;0<=a;a--)d[a].render(!1);window.setTimeout(function(){for(var a=d.length-1;0<=a;a--)d[a].setConnectionsHidden(!1)},1);b.updateDisabled();Blockly.fireUiEvent(window,"resize")}return b}; Blockly.Xml.domToBlockHeadless_=function(a,b,c){var d=null,e=b.getAttribute("type");if(!e)throw"Block type unspecified: \n"+b.outerHTML;var f=b.getAttribute("id");if(c&&f){d=Blockly.Block.getById(f,a);if(!d)throw"Couldn't get Block with id: "+f;f=d.getParent();d.workspace&&d.dispose(!0,!1,!0);d.fill(a,e);d.parent_=f}else d=Blockly.Block.obtain(a,e);for(var g=null,f=0,h;h=b.childNodes[f];f++)if(3!=h.nodeType||!h.data.match(/^\s*$/)){for(var g=null,k=0,l;l=h.childNodes[k];k++)3==l.nodeType&&l.data.match(/^\s*$/)|| (g=l);k=h.getAttribute("name");switch(h.nodeName.toLowerCase()){case "mutation":d.domToMutation&&(d.domToMutation(h),d.initSvg&&d.initSvg());break;case "comment":d.setCommentText(h.textContent);var p=h.getAttribute("pinned");p&&setTimeout(function(){d.comment&&d.comment.setVisible&&d.comment.setVisible("true"==p)},1);g=parseInt(h.getAttribute("w"),10);h=parseInt(h.getAttribute("h"),10);!isNaN(g)&&!isNaN(h)&&d.comment&&d.comment.setVisible&&d.comment.setBubbleSize(g,h);break;case "title":case "field":d.setFieldValue(h.textContent, k);break;case "value":case "statement":h=d.getInput(k);if(!h)throw"Input "+k+" does not exist in block "+e;if(g&&"block"==g.nodeName.toLowerCase())if(g=Blockly.Xml.domToBlockHeadless_(a,g,c),g.outputConnection)h.connection.connect(g.outputConnection);else if(g.previousConnection)h.connection.connect(g.previousConnection);else throw"Child block does not have output or previous statement.";break;case "next":if(g&&"block"==g.nodeName.toLowerCase()){if(!d.nextConnection)throw"Next statement does not exist."; diff --git a/core/xml.js b/core/xml.js index dda39f0e5..da81e0b4f 100644 --- a/core/xml.js +++ b/core/xml.js @@ -254,9 +254,13 @@ Blockly.Xml.domToBlock = function(workspace, xmlBlock, opt_reuseBlock) { for (var i = blocks.length - 1; i >= 0; i--) { blocks[i].render(false); } - for (var i = blocks.length - 1; i >= 0; i--) { - blocks[i].setConnectionsHidden(false); - } + // Populating the connection database may be defered until after the blocks + // have renderend. + window.setTimeout(function() { + for (var i = blocks.length - 1; i >= 0; i--) { + blocks[i].setConnectionsHidden(false); + } + }, 1); topBlock.updateDisabled(); // Fire an event to allow scrollbars to resize. Blockly.fireUiEvent(window, 'resize');