mirror of
https://github.com/google/blockly.git
synced 2026-01-08 01:20:12 +01:00
Removing (most) Closure from BlockFactory (#1925)
Replacing all Closure goog. library calls from BlockFactory, with the exception of the ColorPicker and the test for the warning about running without Closure. This includes (almost) all goog.provide and goog.require statements.
This commit is contained in:
committed by
GitHub
parent
a87dcc66fb
commit
b4cfe263fa
@@ -22,7 +22,8 @@
|
|||||||
* @fileoverview Stubbed interface functions for analytics integration.
|
* @fileoverview Stubbed interface functions for analytics integration.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
goog.provide('BlocklyDevTools.Analytics');
|
var BlocklyDevTools = BlocklyDevTools || Object.create(null);
|
||||||
|
BlocklyDevTools.Analytics = BlocklyDevTools.Analytics || Object.create(null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether these stub methods should log analytics calls to the console.
|
* Whether these stub methods should log analytics calls to the console.
|
||||||
|
|||||||
@@ -25,17 +25,8 @@
|
|||||||
*
|
*
|
||||||
* @author quachtina96 (Tina Quach)
|
* @author quachtina96 (Tina Quach)
|
||||||
*/
|
*/
|
||||||
goog.provide('AppController');
|
|
||||||
|
|
||||||
goog.require('BlockFactory');
|
|
||||||
goog.require('BlocklyDevTools.Analytics');
|
|
||||||
goog.require('FactoryUtils');
|
|
||||||
goog.require('BlockLibraryController');
|
|
||||||
goog.require('BlockExporterController');
|
|
||||||
goog.require('goog.dom.classlist');
|
|
||||||
goog.require('goog.ui.PopupColorPicker');
|
|
||||||
goog.require('goog.ui.ColorPicker');
|
|
||||||
|
|
||||||
|
goog.require('goog.dom.xml'); // Used to detect Closure
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller for the Blockly Factory
|
* Controller for the Blockly Factory
|
||||||
@@ -161,9 +152,7 @@ AppController.prototype.exportBlockLibraryToFile = function() {
|
|||||||
*/
|
*/
|
||||||
AppController.prototype.formatBlockLibraryForExport_ = function(blockXmlMap) {
|
AppController.prototype.formatBlockLibraryForExport_ = function(blockXmlMap) {
|
||||||
// Create DOM for XML.
|
// Create DOM for XML.
|
||||||
var xmlDom = goog.dom.createDom('xml', {
|
var xmlDom = document.createElementNS('http://www.w3.org/1999/xhtml', 'xml');
|
||||||
'xmlns':"http://www.w3.org/1999/xhtml"
|
|
||||||
});
|
|
||||||
|
|
||||||
// Append each block node to XML DOM.
|
// Append each block node to XML DOM.
|
||||||
for (var blockType in blockXmlMap) {
|
for (var blockType in blockXmlMap) {
|
||||||
@@ -184,29 +173,25 @@ AppController.prototype.formatBlockLibraryForExport_ = function(blockXmlMap) {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
AppController.prototype.formatBlockLibraryForImport_ = function(xmlText) {
|
AppController.prototype.formatBlockLibraryForImport_ = function(xmlText) {
|
||||||
var xmlDom = Blockly.Xml.textToDom(xmlText);
|
var inputXml = Blockly.Xml.textToDom(xmlText);
|
||||||
|
// Convert the live HTMLCollection of child Elements into a static array,
|
||||||
// Get array of XMLs. Use an asterisk (*) instead of a tag name for the XPath
|
// since the addition to editorWorkspaceXml below removes it from inputXml.
|
||||||
// selector, to match all elements at that level and get all factory_base
|
var inputChildren = Array.from(inputXml.children);
|
||||||
// blocks.
|
|
||||||
var blockNodes = goog.dom.xml.selectNodes(xmlDom, '*');
|
|
||||||
|
|
||||||
// Create empty map. The line below creates a truly empy object. It doesn't
|
// Create empty map. The line below creates a truly empy object. It doesn't
|
||||||
// have built-in attributes/functions such as length or toString.
|
// have built-in attributes/functions such as length or toString.
|
||||||
var blockXmlTextMap = Object.create(null);
|
var blockXmlTextMap = Object.create(null);
|
||||||
|
|
||||||
// Populate map.
|
// 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
|
// Add outer XML tag to the block for proper injection in to the
|
||||||
// main workspace.
|
// main workspace.
|
||||||
// Create DOM for XML.
|
// Create DOM for XML.
|
||||||
var xmlDom = goog.dom.createDom('xml', {
|
var editorWorkspaceXml =
|
||||||
'xmlns':"http://www.w3.org/1999/xhtml"
|
document.createElementNS('http://www.w3.org/1999/xhtml', 'xml');
|
||||||
});
|
editorWorkspaceXml.appendChild(blockNode);
|
||||||
xmlDom.appendChild(blockNode);
|
|
||||||
|
|
||||||
xmlText = Blockly.Xml.domToText(xmlDom);
|
xmlText = Blockly.Xml.domToText(editorWorkspaceXml);
|
||||||
// All block types should be lowercase.
|
// All block types should be lowercase.
|
||||||
var blockType = this.getBlockTypeFromXml_(xmlText).toLowerCase();
|
var blockType = this.getBlockTypeFromXml_(xmlText).toLowerCase();
|
||||||
// Some names are invalid so fix them up.
|
// Some names are invalid so fix them up.
|
||||||
@@ -376,9 +361,9 @@ AppController.prototype.onTab = function() {
|
|||||||
AppController.prototype.styleTabs_ = function() {
|
AppController.prototype.styleTabs_ = function() {
|
||||||
for (var tabName in this.tabMap) {
|
for (var tabName in this.tabMap) {
|
||||||
if (this.selectedTab == tabName) {
|
if (this.selectedTab == tabName) {
|
||||||
goog.dom.classlist.addRemove(this.tabMap[tabName], 'taboff', 'tabon');
|
this.tabMap[tabName].classList.replace('taboff', 'tabon');
|
||||||
} else {
|
} else {
|
||||||
goog.dom.classlist.addRemove(this.tabMap[tabName], 'tabon', 'taboff');
|
this.tabMap[tabName].classList.replace('tabon', 'taboff');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -23,21 +23,15 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Namespace for BlockDefinitionExtractor.
|
* Namespace to contain all functions needed to extract block definition from
|
||||||
*/
|
|
||||||
goog.provide('BlockDefinitionExtractor');
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class to contain all functions needed to extract block definition from
|
|
||||||
* the block preview data structure.
|
* the block preview data structure.
|
||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
BlockDefinitionExtractor = BlockDefinitionExtractor || Object.create(null);
|
var BlockDefinitionExtractor = BlockDefinitionExtractor || Object.create(null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a BlockFactory workspace that reflects the block structure of the
|
* Builds a BlockFactory workspace that reflects the block structure of the
|
||||||
* exmaple block.
|
* example block.
|
||||||
*
|
*
|
||||||
* @param {!Blockly.Block} block The reference block from which the definition
|
* @param {!Blockly.Block} block The reference block from which the definition
|
||||||
* will be extracted.
|
* will be extracted.
|
||||||
@@ -45,7 +39,7 @@ BlockDefinitionExtractor = BlockDefinitionExtractor || Object.create(null);
|
|||||||
* workspace.
|
* workspace.
|
||||||
*/
|
*/
|
||||||
BlockDefinitionExtractor.buildBlockFactoryWorkspace = function(block) {
|
BlockDefinitionExtractor.buildBlockFactoryWorkspace = function(block) {
|
||||||
var workspaceXml = goog.dom.createDom('xml');
|
var workspaceXml = document.createElement('xml');
|
||||||
workspaceXml.append(
|
workspaceXml.append(
|
||||||
BlockDefinitionExtractor.factoryBase_(block, block.type));
|
BlockDefinitionExtractor.factoryBase_(block, block.type));
|
||||||
|
|
||||||
@@ -64,7 +58,7 @@ BlockDefinitionExtractor.buildBlockFactoryWorkspace = function(block) {
|
|||||||
*/
|
*/
|
||||||
BlockDefinitionExtractor.newDomElement_ = function(name, opt_attrs, opt_text) {
|
BlockDefinitionExtractor.newDomElement_ = function(name, opt_attrs, opt_text) {
|
||||||
// Avoid createDom(..)'s attributes argument for being too HTML specific.
|
// Avoid createDom(..)'s attributes argument for being too HTML specific.
|
||||||
var elem = goog.dom.createDom(name);
|
var elem = document.createElement(name);
|
||||||
if (opt_attrs) {
|
if (opt_attrs) {
|
||||||
for (var key in opt_attrs) {
|
for (var key in opt_attrs) {
|
||||||
elem.setAttribute(key, opt_attrs[key]);
|
elem.setAttribute(key, opt_attrs[key]);
|
||||||
@@ -164,16 +158,17 @@ BlockDefinitionExtractor.factoryBase_ = function(block, name) {
|
|||||||
factoryBaseEl.append(helpUrlValue);
|
factoryBaseEl.append(helpUrlValue);
|
||||||
|
|
||||||
// Convert colour_ to hue value 0-360 degrees
|
// Convert colour_ to hue value 0-360 degrees
|
||||||
// TODO(#1247): Solve off-by-one errors.
|
var colour_hue = block.getHue(); // May be null if not set via hue.
|
||||||
// TODO: Deal with colors that don't map to standard hues. (Needs improved
|
if (colour_hue) {
|
||||||
// block definitions.)
|
var colourBlock = BlockDefinitionExtractor.colourBlockFromHue_(colour_hue);
|
||||||
var colour_hue = Math.floor(
|
var colourInputValue =
|
||||||
goog.color.hexToHsv(block.colour_)[0]); // Off by one... sometimes
|
BlockDefinitionExtractor.newDomElement_('value', {name: 'COLOUR'});
|
||||||
var colourBlock = BlockDefinitionExtractor.colourBlockFromHue_(colour_hue);
|
colourInputValue.append(colourBlock);
|
||||||
var colourInputValue =
|
factoryBaseEl.append(colourInputValue);
|
||||||
BlockDefinitionExtractor.newDomElement_('value', {name: 'COLOUR'});
|
} else {
|
||||||
colourInputValue.append(colourBlock);
|
// Editor will not have a colour block and preview will render black.
|
||||||
factoryBaseEl.append(colourInputValue);
|
// TODO: Support RGB colours in the block editor.
|
||||||
|
}
|
||||||
return factoryBaseEl;
|
return factoryBaseEl;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -480,7 +475,7 @@ BlockDefinitionExtractor.buildFieldDropdown_ = function(dropdown) {
|
|||||||
var menuGenerator = dropdown.menuGenerator_;
|
var menuGenerator = dropdown.menuGenerator_;
|
||||||
if (typeof menuGenerator === 'function') {
|
if (typeof menuGenerator === 'function') {
|
||||||
var options = menuGenerator();
|
var options = menuGenerator();
|
||||||
} else if (goog.isArray(menuGenerator)) {
|
} else if (Array.isArray(menuGenerator)) {
|
||||||
var options = menuGenerator;
|
var options = menuGenerator;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Unrecognized type of menuGenerator: ' + menuGenerator);
|
throw new Error('Unrecognized type of menuGenerator: ' + menuGenerator);
|
||||||
|
|||||||
@@ -29,22 +29,12 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
goog.provide('BlockExporterController');
|
|
||||||
|
|
||||||
goog.require('BlocklyDevTools.Analytics');
|
|
||||||
goog.require('FactoryUtils');
|
|
||||||
goog.require('StandardCategories');
|
|
||||||
goog.require('BlockExporterView');
|
|
||||||
goog.require('BlockExporterTools');
|
|
||||||
goog.require('goog.dom.xml');
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BlockExporter Controller Class
|
* BlockExporter Controller Class
|
||||||
* @param {!BlockLibrary.Storage} blockLibStorage Block Library Storage.
|
* @param {!BlockLibrary.Storage} blockLibStorage Block Library Storage.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
BlockExporterController = function(blockLibStorage) {
|
function BlockExporterController(blockLibStorage) {
|
||||||
// BlockLibrary.Storage object containing user's saved blocks.
|
// BlockLibrary.Storage object containing user's saved blocks.
|
||||||
this.blockLibStorage = blockLibStorage;
|
this.blockLibStorage = blockLibStorage;
|
||||||
// Utils for generating code to export.
|
// Utils for generating code to export.
|
||||||
@@ -132,11 +122,11 @@ BlockExporterController.prototype.export = function() {
|
|||||||
BlocklyDevTools.Analytics.onWarning(msg);
|
BlocklyDevTools.Analytics.onWarning(msg);
|
||||||
alert(msg);
|
alert(msg);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Get generator stub code in the selected language for the blocks.
|
// Get generator stub code in the selected language for the blocks.
|
||||||
var genStubs = this.tools.getGeneratorCode(blockXmlMap,
|
var genStubs = this.tools.getGeneratorCode(blockXmlMap,
|
||||||
language);
|
language);
|
||||||
|
|
||||||
// Download the file.
|
// Download the file.
|
||||||
FactoryUtils.createAndDownloadFile(
|
FactoryUtils.createAndDownloadFile(
|
||||||
genStubs, generatorStub_filename + '.js', 'javascript');
|
genStubs, generatorStub_filename + '.js', 'javascript');
|
||||||
|
|||||||
@@ -28,25 +28,15 @@
|
|||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
goog.provide('BlockExporterTools');
|
|
||||||
|
|
||||||
goog.require('FactoryUtils');
|
|
||||||
goog.require('BlockOption');
|
|
||||||
goog.require('goog.dom');
|
|
||||||
goog.require('goog.dom.xml');
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Block Exporter Tools Class
|
* Block Exporter Tools Class
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
BlockExporterTools = function() {
|
function BlockExporterTools() {
|
||||||
// Create container for hidden workspace.
|
// Create container for hidden workspace.
|
||||||
this.container = goog.dom.createDom('div', {
|
this.container = document.createElement('div');
|
||||||
'id': 'blockExporterTools_hiddenWorkspace'
|
this.container.id = 'blockExporterTools_hiddenWorkspace';
|
||||||
}, ''); // Empty quotes for empty div.
|
this.container.style.display = 'none'; // Hide the hidden workspace.
|
||||||
// Hide hidden workspace.
|
|
||||||
this.container.style.display = 'none';
|
|
||||||
document.body.appendChild(this.container);
|
document.body.appendChild(this.container);
|
||||||
/**
|
/**
|
||||||
* Hidden workspace for the Block Exporter that holds pieces that make
|
* Hidden workspace for the Block Exporter that holds pieces that make
|
||||||
@@ -167,45 +157,6 @@ BlockExporterTools.prototype.addBlockDefinitions = function(blockXmlMap) {
|
|||||||
eval(blockDefs);
|
eval(blockDefs);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Pulls information about all blocks in the block library to generate XML
|
|
||||||
* for the selector workpace's toolbox.
|
|
||||||
* @param {!BlockLibraryStorage} blockLibStorage Block Library Storage object.
|
|
||||||
* @return {!Element} XML representation of the toolbox.
|
|
||||||
*/
|
|
||||||
BlockExporterTools.prototype.generateToolboxFromLibrary
|
|
||||||
= function(blockLibStorage) {
|
|
||||||
// Create DOM for XML.
|
|
||||||
var xmlDom = goog.dom.createDom('xml', {
|
|
||||||
'id' : 'blockExporterTools_toolbox',
|
|
||||||
'style' : 'display:none'
|
|
||||||
});
|
|
||||||
|
|
||||||
var allBlockTypes = blockLibStorage.getBlockTypes();
|
|
||||||
// Object mapping block type to XML.
|
|
||||||
var blockXmlMap = blockLibStorage.getBlockXmlMap(allBlockTypes);
|
|
||||||
|
|
||||||
// Define the custom blocks in order to be able to create instances of
|
|
||||||
// them in the exporter workspace.
|
|
||||||
this.addBlockDefinitions(blockXmlMap);
|
|
||||||
|
|
||||||
for (var blockType in blockXmlMap) {
|
|
||||||
// Get block.
|
|
||||||
var block = FactoryUtils.getDefinedBlock(blockType, this.hiddenWorkspace);
|
|
||||||
var category = FactoryUtils.generateCategoryXml([block], blockType);
|
|
||||||
xmlDom.appendChild(category);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If there are no blocks in library and the map is empty, append dummy
|
|
||||||
// category.
|
|
||||||
if (Object.keys(blockXmlMap).length == 0) {
|
|
||||||
var category = goog.dom.createDom('category');
|
|
||||||
category.setAttribute('name','Next Saved Block');
|
|
||||||
xmlDom.appendChild(category);
|
|
||||||
}
|
|
||||||
return xmlDom;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate XML for the workspace factory's category from imported block
|
* Generate XML for the workspace factory's category from imported block
|
||||||
* definitions.
|
* definitions.
|
||||||
|
|||||||
@@ -27,19 +27,12 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
goog.provide('BlockExporterView');
|
|
||||||
|
|
||||||
goog.require('BlockExporterTools');
|
|
||||||
goog.require('BlockOption');
|
|
||||||
goog.require('goog.dom');
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BlockExporter View Class
|
* BlockExporter View Class
|
||||||
* @param {!Object} blockOptions Map of block types to BlockOption objects.
|
* @param {!Object} blockOptions Map of block types to BlockOption objects.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
BlockExporterView = function(blockOptions) {
|
function BlockExporterView(blockOptions) {
|
||||||
// Map of block types to BlockOption objects to select from.
|
// Map of block types to BlockOption objects to select from.
|
||||||
this.blockOptions = blockOptions;
|
this.blockOptions = blockOptions;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -32,14 +32,6 @@
|
|||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
goog.provide('BlockLibraryController');
|
|
||||||
|
|
||||||
goog.require('BlocklyDevTools.Analytics');
|
|
||||||
goog.require('BlockLibraryStorage');
|
|
||||||
goog.require('BlockLibraryView');
|
|
||||||
goog.require('BlockFactory');
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Block Library Controller Class
|
* Block Library Controller Class
|
||||||
* @param {string} blockLibraryName Desired name of Block Library, also used
|
* @param {string} blockLibraryName Desired name of Block Library, also used
|
||||||
@@ -48,7 +40,7 @@ goog.require('BlockFactory');
|
|||||||
* object that allows user to import a block library.
|
* object that allows user to import a block library.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
BlockLibraryController = function(blockLibraryName, opt_blockLibraryStorage) {
|
function BlockLibraryController(blockLibraryName, opt_blockLibraryStorage) {
|
||||||
this.name = blockLibraryName;
|
this.name = blockLibraryName;
|
||||||
// Create a new, empty Block Library Storage object, or load existing one.
|
// Create a new, empty Block Library Storage object, or load existing one.
|
||||||
this.storage = opt_blockLibraryStorage || new BlockLibraryStorage(this.name);
|
this.storage = opt_blockLibraryStorage || new BlockLibraryStorage(this.name);
|
||||||
@@ -144,7 +136,7 @@ BlockLibraryController.prototype.saveToBlockLibrary = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create block XML.
|
// Create block XML.
|
||||||
var xmlElement = goog.dom.createDom('xml');
|
var xmlElement = document.createElement('xml');
|
||||||
var block = FactoryUtils.getRootBlock(BlockFactory.mainWorkspace);
|
var block = FactoryUtils.getRootBlock(BlockFactory.mainWorkspace);
|
||||||
xmlElement.appendChild(Blockly.Xml.blockToDomWithXY(block));
|
xmlElement.appendChild(Blockly.Xml.blockToDomWithXY(block));
|
||||||
|
|
||||||
|
|||||||
@@ -27,9 +27,6 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
goog.provide('BlockLibraryStorage');
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a block library's storage.
|
* Represents a block library's storage.
|
||||||
* @param {string} blockLibraryName Desired name of Block Library, also used
|
* @param {string} blockLibraryName Desired name of Block Library, also used
|
||||||
@@ -37,7 +34,7 @@ goog.provide('BlockLibraryStorage');
|
|||||||
* @param {Object} opt_blocks Object mapping block type to XML.
|
* @param {Object} opt_blocks Object mapping block type to XML.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
BlockLibraryStorage = function(blockLibraryName, opt_blocks) {
|
function BlockLibraryStorage(blockLibraryName, opt_blocks) {
|
||||||
// Add prefix to this.name to avoid collisions in local storage.
|
// Add prefix to this.name to avoid collisions in local storage.
|
||||||
this.name = 'BlockLibraryStorage.' + blockLibraryName;
|
this.name = 'BlockLibraryStorage.' + blockLibraryName;
|
||||||
if (!opt_blocks) {
|
if (!opt_blocks) {
|
||||||
@@ -60,9 +57,7 @@ BlockLibraryStorage = function(blockLibraryName, opt_blocks) {
|
|||||||
* Reads the named block library from local storage and saves it in this.blocks.
|
* Reads the named block library from local storage and saves it in this.blocks.
|
||||||
*/
|
*/
|
||||||
BlockLibraryStorage.prototype.loadFromLocalStorage = function() {
|
BlockLibraryStorage.prototype.loadFromLocalStorage = function() {
|
||||||
// goog.global is synonymous to window, and allows for flexibility
|
var object = localStorage[this.name];
|
||||||
// between browsers.
|
|
||||||
var object = goog.global.localStorage[this.name];
|
|
||||||
this.blocks = object ? JSON.parse(object) : null;
|
this.blocks = object ? JSON.parse(object) : null;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -70,7 +65,7 @@ BlockLibraryStorage.prototype.loadFromLocalStorage = function() {
|
|||||||
* Writes the current block library (this.blocks) to local storage.
|
* Writes the current block library (this.blocks) to local storage.
|
||||||
*/
|
*/
|
||||||
BlockLibraryStorage.prototype.saveToLocalStorage = function() {
|
BlockLibraryStorage.prototype.saveToLocalStorage = function() {
|
||||||
goog.global.localStorage[this.name] = JSON.stringify(this.blocks);
|
localStorage[this.name] = JSON.stringify(this.blocks);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -27,12 +27,6 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
goog.provide('BlockLibraryView');
|
|
||||||
|
|
||||||
goog.require('goog.dom');
|
|
||||||
goog.require('goog.dom.classlist');
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BlockLibraryView Class
|
* BlockLibraryView Class
|
||||||
* @constructor
|
* @constructor
|
||||||
@@ -59,10 +53,10 @@ var BlockLibraryView = function() {
|
|||||||
*/
|
*/
|
||||||
BlockLibraryView.prototype.addOption = function(blockType, selected) {
|
BlockLibraryView.prototype.addOption = function(blockType, selected) {
|
||||||
// Create option.
|
// Create option.
|
||||||
var option = goog.dom.createDom('a', {
|
var option = document.createElement('a');
|
||||||
'id': 'dropdown_' + blockType,
|
option.id ='dropdown_' + blockType;
|
||||||
'class': 'blockLibOpt'
|
option.classList.add('blockLibOpt');
|
||||||
}, blockType);
|
option.textContent = blockType;
|
||||||
|
|
||||||
// Add option to dropdown.
|
// Add option to dropdown.
|
||||||
this.dropdown.appendChild(option);
|
this.dropdown.appendChild(option);
|
||||||
@@ -99,7 +93,7 @@ BlockLibraryView.prototype.setSelectedBlockType = function(blockTypeToSelect) {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
BlockLibraryView.prototype.selectOption_ = function(option) {
|
BlockLibraryView.prototype.selectOption_ = function(option) {
|
||||||
goog.dom.classlist.add(option, 'dropdown-content-selected');
|
option.classList.add('dropdown-content-selected');
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -109,7 +103,7 @@ BlockLibraryView.prototype.selectOption_ = function(option) {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
BlockLibraryView.prototype.deselectOption_ = function(option) {
|
BlockLibraryView.prototype.deselectOption_ = function(option) {
|
||||||
goog.dom.classlist.remove(option, 'dropdown-content-selected');
|
option.classList.remove('dropdown-content-selected');
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -150,13 +144,12 @@ BlockLibraryView.prototype.updateButtons =
|
|||||||
if (blockType == 'block_type') {
|
if (blockType == 'block_type') {
|
||||||
buttonFormatClass = 'button_alert';
|
buttonFormatClass = 'button_alert';
|
||||||
}
|
}
|
||||||
goog.dom.classlist.add(this.saveButton, buttonFormatClass);
|
this.saveButton.classList.add(buttonFormatClass);
|
||||||
this.saveButton.disabled = false;
|
this.saveButton.disabled = false;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// No changes to save.
|
// No changes to save.
|
||||||
var classesToRemove = ['button_alert', 'button_warn'];
|
this.saveButton.classList.remove('button_alert', 'button_warn');
|
||||||
goog.dom.classlist.removeAll(this.saveButton, classesToRemove);
|
|
||||||
this.saveButton.disabled = true;
|
this.saveButton.disabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,18 +19,15 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fileoverview Javascript for the BlockOption class, used to represent each of
|
* @fileoverview Javascript for the BlockOption class, used to represent each
|
||||||
* the various blocks that you may select. Each block option has a checkbox,
|
* of the various blocks that you may select in the Block Selector. Each block
|
||||||
* a label, and a preview workspace through which to view the block.
|
* option has a checkbox, a label, and a preview workspace through which to
|
||||||
|
* view the block.
|
||||||
*
|
*
|
||||||
* @author quachtina96 (Tina Quach)
|
* @author quachtina96 (Tina Quach)
|
||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
goog.provide('BlockOption');
|
|
||||||
goog.require('goog.dom');
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BlockOption Class
|
* BlockOption Class
|
||||||
* A block option includes checkbox, label, and div element that shows a preview
|
* A block option includes checkbox, label, and div element that shows a preview
|
||||||
@@ -70,48 +67,42 @@ var BlockOption = function(blockSelector, blockType, previewBlockXml) {
|
|||||||
*/
|
*/
|
||||||
BlockOption.prototype.createDom = function() {
|
BlockOption.prototype.createDom = function() {
|
||||||
// Create the div for the block option.
|
// Create the div for the block option.
|
||||||
var blockOptContainer = goog.dom.createDom('div', {
|
var blockOptContainer = document.createElement('div');
|
||||||
'id': this.blockType,
|
blockOptContainer.id = this.blockType;
|
||||||
'class': 'blockOption'
|
blockOptContainer.classList.add('blockOption');
|
||||||
}, ''); // Empty quotes for empty div.
|
|
||||||
|
|
||||||
// Create and append div in which to inject the workspace for viewing the
|
// Create and append div in which to inject the workspace for viewing the
|
||||||
// block option.
|
// block option.
|
||||||
var blockOptionPreview = goog.dom.createDom('div', {
|
var blockOptionPreview = document.createElement('div');
|
||||||
'id' : this.blockType + '_workspace',
|
blockOptionPreview.id = this.blockType + '_workspace';
|
||||||
'class': 'blockOption_preview'
|
blockOptionPreview.classList.add('blockOption_preview');
|
||||||
}, '');
|
|
||||||
blockOptContainer.appendChild(blockOptionPreview);
|
blockOptContainer.appendChild(blockOptionPreview);
|
||||||
|
|
||||||
// Create and append container to hold checkbox and label.
|
// Create and append container to hold checkbox and label.
|
||||||
var checkLabelContainer = goog.dom.createDom('div', {
|
var checkLabelContainer = document.createElement('div');
|
||||||
'class': 'blockOption_checkLabel'
|
checkLabelContainer.classList.add('blockOption_checkLabel');
|
||||||
}, '');
|
|
||||||
blockOptContainer.appendChild(checkLabelContainer);
|
blockOptContainer.appendChild(checkLabelContainer);
|
||||||
|
|
||||||
// Create and append container for checkbox.
|
// Create and append container for checkbox.
|
||||||
var checkContainer = goog.dom.createDom('div', {
|
var checkContainer = document.createElement('div');
|
||||||
'class': 'blockOption_check'
|
checkContainer.classList.add('blockOption_check');
|
||||||
}, '');
|
|
||||||
checkLabelContainer.appendChild(checkContainer);
|
checkLabelContainer.appendChild(checkContainer);
|
||||||
|
|
||||||
// Create and append checkbox.
|
// Create and append checkbox.
|
||||||
this.checkbox = goog.dom.createDom('input', {
|
this.checkbox = document.createElement('input');
|
||||||
'type': 'checkbox',
|
this.checkbox.id = this.blockType + '_check';
|
||||||
'id': this.blockType + '_check'
|
this.checkbox.setAttribute('type', 'checkbox');
|
||||||
}, '');
|
|
||||||
checkContainer.appendChild(this.checkbox);
|
checkContainer.appendChild(this.checkbox);
|
||||||
|
|
||||||
// Create and append container for block label.
|
// Create and append container for block label.
|
||||||
var labelContainer = goog.dom.createDom('div', {
|
var labelContainer = document.createElement('div');
|
||||||
'class': 'blockOption_label'
|
labelContainer.classList.add('blockOption_label');
|
||||||
}, '');
|
|
||||||
checkLabelContainer.appendChild(labelContainer);
|
checkLabelContainer.appendChild(labelContainer);
|
||||||
|
|
||||||
// Create and append text node for the label.
|
// Create and append text node for the label.
|
||||||
var labelText = goog.dom.createDom('p', {
|
var labelText = document.createElement('p');
|
||||||
'id': this.blockType + '_text'
|
labelText.id = this.blockType + '_text';
|
||||||
}, this.blockType);
|
labelText.textContent = this.blockType;
|
||||||
labelContainer.appendChild(labelText);
|
labelContainer.appendChild(labelText);
|
||||||
|
|
||||||
this.dom = blockOptContainer;
|
this.dom = blockOptContainer;
|
||||||
|
|||||||
@@ -32,10 +32,7 @@
|
|||||||
/**
|
/**
|
||||||
* Namespace for Block Factory.
|
* Namespace for Block Factory.
|
||||||
*/
|
*/
|
||||||
goog.provide('BlockFactory');
|
var BlockFactory = BlockFactory || Object.create(null);
|
||||||
|
|
||||||
goog.require('FactoryUtils');
|
|
||||||
goog.require('StandardCategories');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Workspace for user to build block.
|
* Workspace for user to build block.
|
||||||
|
|||||||
@@ -32,10 +32,7 @@
|
|||||||
/**
|
/**
|
||||||
* Namespace for FactoryUtils.
|
* Namespace for FactoryUtils.
|
||||||
*/
|
*/
|
||||||
goog.provide('FactoryUtils');
|
var FactoryUtils = FactoryUtils || Object.create(null);
|
||||||
|
|
||||||
goog.require('BlockDefinitionExtractor');
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get block definition code for the current block.
|
* Get block definition code for the current block.
|
||||||
@@ -768,7 +765,7 @@ FactoryUtils.getBlockTypeFromJsDefinition = function(blockDef) {
|
|||||||
*/
|
*/
|
||||||
FactoryUtils.generateCategoryXml = function(blocks, categoryName) {
|
FactoryUtils.generateCategoryXml = function(blocks, categoryName) {
|
||||||
// Create category DOM element.
|
// Create category DOM element.
|
||||||
var categoryElement = goog.dom.createDom('category');
|
var categoryElement = document.createElement('category');
|
||||||
categoryElement.setAttribute('name', categoryName);
|
categoryElement.setAttribute('name', categoryName);
|
||||||
|
|
||||||
// For each block, add block element to category.
|
// For each block, add block element to category.
|
||||||
@@ -892,7 +889,7 @@ FactoryUtils.injectCode = function(code, id) {
|
|||||||
pre.textContent = code;
|
pre.textContent = code;
|
||||||
code = pre.textContent;
|
code = pre.textContent;
|
||||||
code = PR.prettyPrintOne(code, 'js');
|
code = PR.prettyPrintOne(code, 'js');
|
||||||
pre.innerHTML = code;
|
pre.textContent = code;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
/**
|
/**
|
||||||
* Namespace for StandardCategories
|
* Namespace for StandardCategories
|
||||||
*/
|
*/
|
||||||
goog.provide('StandardCategories');
|
var StandardCategories = StandardCategories || Object.create(null);
|
||||||
|
|
||||||
|
|
||||||
// Map of standard category information necessary to add a standard category
|
// Map of standard category information necessary to add a standard category
|
||||||
|
|||||||
@@ -34,11 +34,6 @@
|
|||||||
* @author Emma Dauterman (evd2014)
|
* @author Emma Dauterman (evd2014)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
goog.require('BlocklyDevTools.Analytics');
|
|
||||||
goog.require('FactoryUtils');
|
|
||||||
goog.require('StandardCategories');
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for a WorkspaceFactoryController
|
* Class for a WorkspaceFactoryController
|
||||||
* @param {string} toolboxName Name of workspace toolbox XML.
|
* @param {string} toolboxName Name of workspace toolbox XML.
|
||||||
|
|||||||
@@ -28,8 +28,6 @@
|
|||||||
* @author Emma Dauterman (evd2014)
|
* @author Emma Dauterman (evd2014)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
goog.require('FactoryUtils');
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for a WorkspaceFactoryGenerator
|
* Class for a WorkspaceFactoryGenerator
|
||||||
@@ -61,11 +59,10 @@ WorkspaceFactoryGenerator = function(model) {
|
|||||||
*/
|
*/
|
||||||
WorkspaceFactoryGenerator.prototype.generateToolboxXml = function() {
|
WorkspaceFactoryGenerator.prototype.generateToolboxXml = function() {
|
||||||
// Create DOM for XML.
|
// Create DOM for XML.
|
||||||
var xmlDom = goog.dom.createDom('xml',
|
var xmlDom = document.createElement('xml');
|
||||||
{
|
xmlDom.id = 'toolbox';
|
||||||
'id' : 'toolbox',
|
xmlDom.style.display = 'none';
|
||||||
'style' : 'display:none'
|
|
||||||
});
|
|
||||||
if (!this.model.hasElements()) {
|
if (!this.model.hasElements()) {
|
||||||
// Toolbox has no categories. Use XML directly from workspace.
|
// Toolbox has no categories. Use XML directly from workspace.
|
||||||
this.loadToHiddenWorkspace_(this.model.getSelectedXml());
|
this.loadToHiddenWorkspace_(this.model.getSelectedXml());
|
||||||
@@ -88,10 +85,10 @@ WorkspaceFactoryGenerator.prototype.generateToolboxXml = function() {
|
|||||||
var element = toolboxList[i];
|
var element = toolboxList[i];
|
||||||
if (element.type == ListElement.TYPE_SEPARATOR) {
|
if (element.type == ListElement.TYPE_SEPARATOR) {
|
||||||
// If the next element is a separator.
|
// If the next element is a separator.
|
||||||
var nextElement = goog.dom.createDom('sep');
|
var nextElement = document.createElement('sep');
|
||||||
} else if (element.type == ListElement.TYPE_CATEGORY) {
|
} else if (element.type == ListElement.TYPE_CATEGORY) {
|
||||||
// If the next element is a category.
|
// If the next element is a category.
|
||||||
var nextElement = goog.dom.createDom('category');
|
var nextElement = document.createElement('category');
|
||||||
nextElement.setAttribute('name', element.name);
|
nextElement.setAttribute('name', element.name);
|
||||||
// Add a colour attribute if one exists.
|
// Add a colour attribute if one exists.
|
||||||
if (element.color != null) {
|
if (element.color != null) {
|
||||||
|
|||||||
@@ -27,7 +27,8 @@
|
|||||||
* @author Emma Dauterman (evd2014)
|
* @author Emma Dauterman (evd2014)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
goog.require('FactoryUtils');
|
goog.require('goog.ui.PopupColorPicker');
|
||||||
|
goog.require('goog.ui.ColorPicker');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Namespace for workspace factory initialization methods.
|
* Namespace for workspace factory initialization methods.
|
||||||
|
|||||||
@@ -28,7 +28,6 @@
|
|||||||
* @author Emma Dauterman (edauterman)
|
* @author Emma Dauterman (edauterman)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
goog.require('FactoryUtils');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for a WorkspaceFactoryView
|
* Class for a WorkspaceFactoryView
|
||||||
|
|||||||
Reference in New Issue
Block a user