nikhilgaud / blockly

Automatically exported from code.google.com/p/blockly
0 stars 0 forks source link

Blockly.Xml.workspaceToDom doesn´t work on Safari #255

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The original code of Blockly.Xml.domToWorkspace is:

Blockly.Xml.domToWorkspace = function(workspace, xml) {
  if (Blockly.RTL) {
    var width = workspace.getMetrics().viewWidth;
  }
  for (var x = 0, xmlChild; xmlChild = xml.childNodes[x]; x++) {
    if (xmlChild.nodeName.toLowerCase() == 'block') {
      var block = Blockly.Xml.domToBlock(workspace, xmlChild);
      var blockX = parseInt(xmlChild.getAttribute('x'), 10);
      var blockY = parseInt(xmlChild.getAttribute('y'), 10);
      if (!isNaN(blockX) && !isNaN(blockY)) {
        block.moveBy(Blockly.RTL ? width - blockX : blockX, blockY);
      }
    }
  }
};

It works very well on Chrome and FF. However, in Safari sometimes it can (and I 
don´t know why) retrieve an child node that doesn´t exists. So, I propose 
change the "for statement" as:

for (var x = 0; x < xml.childElementCount; x++) {
  var xmlChild = xml.childNodes[x];
  ...
}

This change works on the three browsers.

Original issue reported on code.google.com by adilson...@gmail.com on 16 Oct 2014 at 2:50

GoogleCodeExporter commented 9 years ago
Now, I made a mistake. The correct for statement is:

for (var x = 0; x < xml.childNodes.length; x++) {
  var xmlChild = xml.childNodes[x];
  ...
}

Original comment by adilson...@gmail.com on 16 Oct 2014 at 3:07

GoogleCodeExporter commented 9 years ago
Fixed.  Thanks!
https://groups.google.com/d/msg/blockly/-9d_OkvKBSQ/R-u59W2q4DoJ

Original comment by neil.fra...@gmail.com on 1 Mar 2015 at 9:05