Skip to content

Commit

Permalink
Removing Closure library goog. calls from app_controller.js
Browse files Browse the repository at this point in the history
  • Loading branch information
AnmAtAnm committed Jun 15, 2018
1 parent 7d19f2f commit 4cd4f3b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
37 changes: 13 additions & 24 deletions demos/blockfactory/app_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,8 @@
*
* @author quachtina96 (Tina Quach)
*/
goog.provide('AppController');

goog.require('goog.dom.classlist');
goog.require('goog.dom.xml');
goog.require('goog.ui.PopupColorPicker');
goog.require('goog.ui.ColorPicker');

goog.require('goog.dom.xml'); // Used to detect Closure

/**
* Controller for the Blockly Factory
Expand Down Expand Up @@ -157,9 +152,7 @@ AppController.prototype.exportBlockLibraryToFile = function() {
*/
AppController.prototype.formatBlockLibraryForExport_ = function(blockXmlMap) {
// Create DOM for XML.
var xmlDom = goog.dom.createDom('xml', {
'xmlns':"http://www.w3.org/1999/xhtml"
});
var xmlDom = document.createElementNS('http://www.w3.org/1999/xhtml', 'xml');

// Append each block node to XML DOM.
for (var blockType in blockXmlMap) {
Expand All @@ -180,29 +173,25 @@ AppController.prototype.formatBlockLibraryForExport_ = function(blockXmlMap) {
* @private
*/
AppController.prototype.formatBlockLibraryForImport_ = function(xmlText) {
var xmlDom = Blockly.Xml.textToDom(xmlText);

// Get array of XMLs. Use an asterisk (*) instead of a tag name for the XPath
// selector, to match all elements at that level and get all factory_base
// blocks.
var blockNodes = goog.dom.xml.selectNodes(xmlDom, '*');
var inputXml = Blockly.Xml.textToDom(xmlText);
// Convert the live HTMLCollection of child Elements into a static array,
// since the addition to editorWorkspaceXml below removes it from inputXml.
var inputChildren = Array.from(inputXml.children);

// Create empty map. The line below creates a truly empy object. It doesn't
// have built-in attributes/functions such as length or toString.
var blockXmlTextMap = Object.create(null);

// Populate map.
for (var i = 0, blockNode; blockNode = blockNodes[i]; i++) {

for (var i = 0, blockNode; blockNode = inputChildren[i]; i++) {
// Add outer XML tag to the block for proper injection in to the
// main workspace.
// Create DOM for XML.
var xmlDom = goog.dom.createDom('xml', {
'xmlns':"http://www.w3.org/1999/xhtml"
});
xmlDom.appendChild(blockNode);
var editorWorkspaceXml =
document.createElementNS('http://www.w3.org/1999/xhtml', 'xml');
editorWorkspaceXml.appendChild(blockNode);

xmlText = Blockly.Xml.domToText(xmlDom);
xmlText = Blockly.Xml.domToText(editorWorkspaceXml);
// All block types should be lowercase.
var blockType = this.getBlockTypeFromXml_(xmlText).toLowerCase();
// Some names are invalid so fix them up.
Expand Down Expand Up @@ -372,9 +361,9 @@ AppController.prototype.onTab = function() {
AppController.prototype.styleTabs_ = function() {
for (var tabName in this.tabMap) {
if (this.selectedTab == tabName) {
goog.dom.classlist.addRemove(this.tabMap[tabName], 'taboff', 'tabon');
this.tabMap[tabName].classList.replace('taboff', 'tabon');
} else {
goog.dom.classlist.addRemove(this.tabMap[tabName], 'tabon', 'taboff');
this.tabMap[tabName].classList.replace('tabon', 'taboff');
}
}
};
Expand Down
2 changes: 2 additions & 0 deletions demos/blockfactory/workspacefactory/wfactory_init.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
* @author Emma Dauterman (evd2014)
*/

goog.require('goog.ui.PopupColorPicker');
goog.require('goog.ui.ColorPicker');

/**
* Namespace for workspace factory initialization methods.
Expand Down

0 comments on commit 4cd4f3b

Please sign in to comment.