diff --git a/core/block_events.js b/core/block_events.js index 75ded21bc..a062bea49 100644 --- a/core/block_events.js +++ b/core/block_events.js @@ -36,8 +36,9 @@ goog.provide('Blockly.Events.Move'); // Deprecated. goog.require('Blockly.Events'); goog.require('Blockly.Events.Abstract'); +// TODO Fix circular dependencies +//goog.require('Blockly.Xml'); -goog.require('goog.dom'); goog.require('goog.math.Coordinate'); @@ -273,7 +274,7 @@ Blockly.Events.Create.prototype.fromJson = function(json) { Blockly.Events.Create.prototype.run = function(forward) { var workspace = this.getEventWorkspace_(); if (forward) { - var xml = goog.dom.createDom('xml'); + var xml = Blockly.Xml.createElement('xml'); xml.appendChild(this.xml); Blockly.Xml.domToWorkspace(xml, workspace); } else { @@ -363,7 +364,7 @@ Blockly.Events.Delete.prototype.run = function(forward) { } } } else { - var xml = goog.dom.createDom('xml'); + var xml = Blockly.Xml.createElement('xml'); xml.appendChild(this.oldXml); Blockly.Xml.domToWorkspace(xml, workspace); } diff --git a/core/mutator.js b/core/mutator.js index 1aedae875..3f5cf1c98 100644 --- a/core/mutator.js +++ b/core/mutator.js @@ -33,8 +33,7 @@ goog.require('Blockly.Events.Ui'); goog.require('Blockly.Icon'); goog.require('Blockly.utils'); goog.require('Blockly.WorkspaceSvg'); - -goog.require('goog.dom'); +goog.require('Blockly.Xml'); /** @@ -131,9 +130,11 @@ Blockly.Mutator.prototype.createEditor_ = function() { null); // Convert the list of names into a list of XML objects for the flyout. if (this.quarkNames_.length) { - var quarkXml = goog.dom.createDom('xml'); + var quarkXml = Blockly.Xml.createElement('xml'); for (var i = 0, quarkName; quarkName = this.quarkNames_[i]; i++) { - quarkXml.appendChild(goog.dom.createDom('block', {'type': quarkName})); + var element = Blockly.Xml.createElement('block'); + element.setAttribute('type', quarkName); + quarkXml.appendChild(element); } } else { var quarkXml = null; diff --git a/core/procedures.js b/core/procedures.js index 4d384f995..59ec20a89 100644 --- a/core/procedures.js +++ b/core/procedures.js @@ -36,8 +36,7 @@ goog.require('Blockly.Events.BlockChange'); goog.require('Blockly.Field'); goog.require('Blockly.Names'); goog.require('Blockly.Workspace'); - -goog.require('goog.dom'); +goog.require('Blockly.Xml'); /** @@ -186,12 +185,13 @@ Blockly.Procedures.flyoutCategory = function(workspace) { // // do something // - var block = goog.dom.createDom('block'); + var block = Blockly.Xml.createElement('block'); block.setAttribute('type', 'procedures_defnoreturn'); block.setAttribute('gap', 16); - var nameField = goog.dom.createDom('field', null, - Blockly.Msg['PROCEDURES_DEFNORETURN_PROCEDURE']); + var nameField = Blockly.Xml.createElement('field'); nameField.setAttribute('name', 'NAME'); + nameField.appendChild(Blockly.Xml.createTextNode( + Blockly.Msg['PROCEDURES_DEFNORETURN_PROCEDURE'])); block.appendChild(nameField); xmlList.push(block); } @@ -199,18 +199,19 @@ Blockly.Procedures.flyoutCategory = function(workspace) { // // do something // - var block = goog.dom.createDom('block'); + var block = Blockly.Xml.createElement('block'); block.setAttribute('type', 'procedures_defreturn'); block.setAttribute('gap', 16); - var nameField = goog.dom.createDom('field', null, - Blockly.Msg['PROCEDURES_DEFRETURN_PROCEDURE']); + var nameField = Blockly.Xml.createElement('field'); nameField.setAttribute('name', 'NAME'); + nameField.appendChild(Blockly.Xml.createTextNode( + Blockly.Msg['PROCEDURES_DEFRETURN_PROCEDURE'])); block.appendChild(nameField); xmlList.push(block); } if (Blockly.Blocks['procedures_ifreturn']) { // - var block = goog.dom.createDom('block'); + var block = Blockly.Xml.createElement('block'); block.setAttribute('type', 'procedures_ifreturn'); block.setAttribute('gap', 16); xmlList.push(block); @@ -229,14 +230,14 @@ Blockly.Procedures.flyoutCategory = function(workspace) { // // // - var block = goog.dom.createDom('block'); + var block = Blockly.Xml.createElement('block'); block.setAttribute('type', templateName); block.setAttribute('gap', 16); - var mutation = goog.dom.createDom('mutation'); + var mutation = Blockly.Xml.createElement('mutation'); mutation.setAttribute('name', name); block.appendChild(mutation); for (var j = 0; j < args.length; j++) { - var arg = goog.dom.createDom('arg'); + var arg = Blockly.Xml.createElement('arg'); arg.setAttribute('name', args[j]); mutation.appendChild(arg); } diff --git a/core/variables.js b/core/variables.js index 1eb057dfe..2dfcd1cf3 100644 --- a/core/variables.js +++ b/core/variables.js @@ -35,7 +35,6 @@ goog.require('Blockly.constants'); goog.require('Blockly.VariableModel'); goog.require('Blockly.Workspace'); -goog.require('goog.dom'); goog.require('goog.string'); @@ -149,7 +148,7 @@ Blockly.Variables.allDeveloperVariables = function(workspace) { */ Blockly.Variables.flyoutCategory = function(workspace) { var xmlList = []; - var button = goog.dom.createDom('button'); + var button = document.createElement('button'); button.setAttribute('text', '%{BKY_NEW_VARIABLE}'); button.setAttribute('callbackKey', 'CREATE_VARIABLE'); diff --git a/core/variables_dynamic.js b/core/variables_dynamic.js index fc76f32a1..2b0a37bf1 100644 --- a/core/variables_dynamic.js +++ b/core/variables_dynamic.js @@ -34,8 +34,6 @@ goog.require('Blockly.VariableModel'); // TODO Fix circular dependencies // goog.require('Blockly.Workspace'); -goog.require('goog.dom'); - Blockly.VariablesDynamic.onCreateVariableButtonClick_String = function(button) { Blockly.Variables.createVariableButtonHandler(button.getTargetWorkspace(), null, 'String'); @@ -54,14 +52,15 @@ Blockly.VariablesDynamic.onCreateVariableButtonClick_Colour = function(button) { */ Blockly.VariablesDynamic.flyoutCategory = function(workspace) { var xmlList = []; - var button = goog.dom.createDom('button'); + var button = document.createElement('button'); button.setAttribute('text', Blockly.Msg['NEW_STRING_VARIABLE']); button.setAttribute('callbackKey', 'CREATE_VARIABLE_STRING'); xmlList.push(button); - button = goog.dom.createDom('button'); + button = document.createElement('button'); button.setAttribute('text', Blockly.Msg['NEW_NUMBER_VARIABLE']); button.setAttribute('callbackKey', 'CREATE_VARIABLE_NUMBER'); - xmlList.push(button);button = goog.dom.createDom('button'); + xmlList.push(button); + button = document.createElement('button'); button.setAttribute('text', Blockly.Msg['NEW_COLOUR_VARIABLE']); button.setAttribute('callbackKey', 'CREATE_VARIABLE_COLOUR'); xmlList.push(button); diff --git a/core/workspace_comment.js b/core/workspace_comment.js index 06cb7ddd4..290e2d0c1 100644 --- a/core/workspace_comment.js +++ b/core/workspace_comment.js @@ -31,8 +31,8 @@ goog.require('Blockly.Events.CommentCreate'); goog.require('Blockly.Events.CommentDelete'); goog.require('Blockly.Events.CommentMove'); goog.require('Blockly.utils'); +goog.require('Blockly.Xml'); -goog.require('goog.dom'); goog.require('goog.math.Coordinate'); @@ -278,7 +278,7 @@ Blockly.WorkspaceComment.prototype.toXmlWithXY = function(opt_noId) { * @package */ Blockly.WorkspaceComment.prototype.toXml = function(opt_noId) { - var commentElement = goog.dom.createDom('comment'); + var commentElement = Blockly.Xml.createElement('comment'); if (!opt_noId) { commentElement.setAttribute('id', this.id); } diff --git a/core/ws_comment_events.js b/core/ws_comment_events.js index c5e35631a..da644ffbe 100644 --- a/core/ws_comment_events.js +++ b/core/ws_comment_events.js @@ -32,8 +32,8 @@ goog.provide('Blockly.Events.CommentMove'); goog.require('Blockly.Events'); goog.require('Blockly.Events.Abstract'); +goog.require('Blockly.Xml'); -goog.require('goog.dom'); goog.require('goog.math.Coordinate'); @@ -227,7 +227,7 @@ Blockly.Events.CommentCreate.prototype.run = function(forward) { Blockly.Events.CommentCreateDeleteHelper = function(event, create) { var workspace = event.getEventWorkspace_(); if (create) { - var xml = goog.dom.createDom('xml'); + var xml = Blockly.Xml.createElement('xml'); xml.appendChild(event.xml); Blockly.Xml.domToWorkspace(xml, workspace); } else { diff --git a/core/xml.js b/core/xml.js index 993b71319..5f8ccef55 100644 --- a/core/xml.js +++ b/core/xml.js @@ -33,8 +33,6 @@ goog.provide('Blockly.Xml'); goog.require('Blockly.Events.BlockCreate'); goog.require('Blockly.Events.VarCreate'); -goog.require('goog.dom'); - /** * Encode a block tree as XML. @@ -43,7 +41,7 @@ goog.require('goog.dom'); * @return {!Element} XML document. */ Blockly.Xml.workspaceToDom = function(workspace, opt_noId) { - var xml = goog.dom.createDom('xml'); + var xml = Blockly.Xml.createElement('xml'); var variablesElement = Blockly.Xml.variablesToDom( Blockly.Variables.allUsedVarModels(workspace)); if (variablesElement.hasChildNodes()) { @@ -67,9 +65,10 @@ Blockly.Xml.workspaceToDom = function(workspace, opt_noId) { * @return {!Element} List of XML elements. */ Blockly.Xml.variablesToDom = function(variableList) { - var variables = goog.dom.createDom('variables'); + var variables = Blockly.Xml.createElement('variables'); for (var i = 0, variable; variable = variableList[i]; i++) { - var element = goog.dom.createDom('variable', null, variable.name); + var element = Blockly.Xml.createElement('variable'); + element.appendChild(Blockly.Xml.createTextNode(variable.name)); element.setAttribute('type', variable.type); element.setAttribute('id', variable.getId()); variables.appendChild(element); @@ -123,7 +122,8 @@ Blockly.Xml.fieldToDomVariable_ = function(field) { if (!variable) { throw Error('Tried to serialize a variable field with no variable.'); } - var container = goog.dom.createDom('field', null, variable.name); + var container = Blockly.Xml.createElement('field'); + container.appendChild(Blockly.Xml.createTextNode(variable.name)); container.setAttribute('name', field.name); container.setAttribute('id', variable.getId()); container.setAttribute('variabletype', variable.type); @@ -142,7 +142,8 @@ Blockly.Xml.fieldToDom_ = function(field) { if (field.referencesVariables()) { return Blockly.Xml.fieldToDomVariable_(field); } else { - var container = goog.dom.createDom('field', null, field.getValue()); + var container = Blockly.Xml.createElement('field'); + container.appendChild(Blockly.Xml.createTextNode(field.getValue())); container.setAttribute('name', field.name); return container; } @@ -176,7 +177,7 @@ Blockly.Xml.allFieldsToDom_ = function(block, element) { * @return {!Element} Tree of XML elements. */ Blockly.Xml.blockToDom = function(block, opt_noId) { - var element = goog.dom.createDom(block.isShadow() ? 'shadow' : 'block'); + var element = Blockly.Xml.createElement(block.isShadow() ? 'shadow' : 'block'); element.setAttribute('type', block.type); if (!opt_noId) { element.setAttribute('id', block.id); @@ -193,7 +194,8 @@ Blockly.Xml.blockToDom = function(block, opt_noId) { var commentText = block.getCommentText(); if (commentText) { - var commentElement = goog.dom.createDom('comment', null, commentText); + var commentElement = Blockly.Xml.createElement('comment'); + containerElement.appendChild(Blockly.Xml.createTextNode(commentText)); if (typeof block.comment == 'object') { commentElement.setAttribute('pinned', block.comment.isVisible()); var hw = block.comment.getBubbleSize(); @@ -204,7 +206,8 @@ Blockly.Xml.blockToDom = function(block, opt_noId) { } if (block.data) { - var dataElement = goog.dom.createDom('data', null, block.data); + var dataElement = Blockly.Xml.createElement('data'); + dataElement.appendChild(Blockly.Xml.createTextNode(block.data)); element.appendChild(dataElement); } @@ -216,9 +219,9 @@ Blockly.Xml.blockToDom = function(block, opt_noId) { } else { var childBlock = input.connection.targetBlock(); if (input.type == Blockly.INPUT_VALUE) { - container = goog.dom.createDom('value'); + container = Blockly.Xml.createElement('value'); } else if (input.type == Blockly.NEXT_STATEMENT) { - container = goog.dom.createDom('statement'); + container = Blockly.Xml.createElement('statement'); } var shadow = input.connection.getShadowDom(); if (shadow && (!childBlock || !childBlock.isShadow())) { @@ -255,8 +258,9 @@ Blockly.Xml.blockToDom = function(block, opt_noId) { var nextBlock = block.getNextBlock(); if (nextBlock) { - var container = goog.dom.createDom('next', null, - Blockly.Xml.blockToDom(nextBlock, opt_noId)); + var container = Blockly.Xml.createElement('next'); + container.appendChild(Blockly.Xml.createTextNode( + Blockly.Xml.blockToDom(nextBlock, opt_noId))); element.appendChild(container); } var shadow = block.nextConnection && block.nextConnection.getShadowDom(); @@ -862,6 +866,27 @@ Blockly.Xml.deleteNext = function(xmlBlock) { } }; +/** + * Create DOM element for XML. + * @param {tagName} name Name of DOM element. + * @return {!Element} New DOM element. + */ +Blockly.Xml.createElement = function(tagName) { + // TODO: Namespace this element. + // TODO: Support node.js. + return document.createElement(tagName); +}; + +/** + * Create text element for XML. + * @param {text} text Text content. + * @return {!Node} New DOM node. + */ +Blockly.Xml.createTextNode = function(text) { + // TODO: Support node.js. + return document.createTextNode(text); +}; + // Export symbols that would otherwise be renamed by Closure compiler. if (!goog.global['Blockly']) { goog.global['Blockly'] = {};