mirror of
https://github.com/google/blockly.git
synced 2025-12-15 22:00:07 +01:00
chore: Convert == to === and != to !== where possible. (#5599)
This commit is contained in:
@@ -201,7 +201,7 @@ AppController.prototype.getBlockTypeFromXml_ = function(xmlText) {
|
||||
var fields = factoryBaseBlockXml.getElementsByTagName('field');
|
||||
for (var i = 0; i < fields.length; i++) {
|
||||
// The field whose name is 'NAME' holds the block type as its value.
|
||||
if (fields[i].getAttribute('name') == 'NAME') {
|
||||
if (fields[i].getAttribute('name') === 'NAME') {
|
||||
return fields[i].childNodes[0].nodeValue;
|
||||
}
|
||||
}
|
||||
@@ -258,8 +258,8 @@ AppController.prototype.onTab = function() {
|
||||
var workspaceFactoryTab = this.tabMap[AppController.WORKSPACE_FACTORY];
|
||||
|
||||
// Warn user if they have unsaved changes when leaving Block Factory.
|
||||
if (this.lastSelectedTab == AppController.BLOCK_FACTORY &&
|
||||
this.selectedTab != AppController.BLOCK_FACTORY) {
|
||||
if (this.lastSelectedTab === AppController.BLOCK_FACTORY &&
|
||||
this.selectedTab !== AppController.BLOCK_FACTORY) {
|
||||
|
||||
var hasUnsavedChanges =
|
||||
!FactoryUtils.savedBlockChanges(this.blockLibraryController);
|
||||
@@ -280,12 +280,12 @@ AppController.prototype.onTab = function() {
|
||||
// Only enable key events in workspace factory if workspace factory tab is
|
||||
// selected.
|
||||
this.workspaceFactoryController.keyEventsEnabled =
|
||||
this.selectedTab == AppController.WORKSPACE_FACTORY;
|
||||
this.selectedTab === AppController.WORKSPACE_FACTORY;
|
||||
|
||||
// Turn selected tab on and other tabs off.
|
||||
this.styleTabs_();
|
||||
|
||||
if (this.selectedTab == AppController.EXPORTER) {
|
||||
if (this.selectedTab === AppController.EXPORTER) {
|
||||
BlocklyDevTools.Analytics.onNavigateTo('Exporter');
|
||||
|
||||
// Hide other tabs.
|
||||
@@ -308,7 +308,7 @@ AppController.prototype.onTab = function() {
|
||||
// Update the exporter's preview to reflect any changes made to the blocks.
|
||||
this.exporter.updatePreview();
|
||||
|
||||
} else if (this.selectedTab == AppController.BLOCK_FACTORY) {
|
||||
} else if (this.selectedTab === AppController.BLOCK_FACTORY) {
|
||||
BlocklyDevTools.Analytics.onNavigateTo('BlockFactory');
|
||||
|
||||
// Hide other tabs.
|
||||
@@ -317,7 +317,7 @@ AppController.prototype.onTab = function() {
|
||||
// Show Block Factory.
|
||||
FactoryUtils.show('blockFactoryContent');
|
||||
|
||||
} else if (this.selectedTab == AppController.WORKSPACE_FACTORY) {
|
||||
} else if (this.selectedTab === AppController.WORKSPACE_FACTORY) {
|
||||
// TODO: differentiate Workspace and Toolbox editor, based on the other tab state.
|
||||
BlocklyDevTools.Analytics.onNavigateTo('WorkspaceFactory');
|
||||
|
||||
@@ -343,7 +343,7 @@ AppController.prototype.onTab = function() {
|
||||
*/
|
||||
AppController.prototype.styleTabs_ = function() {
|
||||
for (var tabName in this.tabMap) {
|
||||
if (this.selectedTab == tabName) {
|
||||
if (this.selectedTab === tabName) {
|
||||
this.tabMap[tabName].classList.replace('taboff', 'tabon');
|
||||
} else {
|
||||
this.tabMap[tabName].classList.replace('tabon', 'taboff');
|
||||
@@ -585,7 +585,7 @@ AppController.prototype.initializeBlocklyStorage = function() {
|
||||
* Handle resizing of elements.
|
||||
*/
|
||||
AppController.prototype.onresize = function(event) {
|
||||
if (this.selectedTab == AppController.BLOCK_FACTORY) {
|
||||
if (this.selectedTab === AppController.BLOCK_FACTORY) {
|
||||
// Handle resizing of Block Factory elements.
|
||||
var expandList = [
|
||||
document.getElementById('blocklyPreviewContainer'),
|
||||
@@ -600,7 +600,7 @@ AppController.prototype.onresize = function(event) {
|
||||
expand.style.width = (expand.parentNode.offsetWidth - 2) + 'px';
|
||||
expand.style.height = (expand.parentNode.offsetHeight - 2) + 'px';
|
||||
}
|
||||
} else if (this.selectedTab == AppController.EXPORTER) {
|
||||
} else if (this.selectedTab === AppController.EXPORTER) {
|
||||
// Handle resize of Exporter block options.
|
||||
this.exporter.view.centerPreviewBlocks();
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ BlockExporterController.prototype.export = function() {
|
||||
BlocklyDevTools.Analytics.onExport(
|
||||
BlocklyDevTools.Analytics.BLOCK_DEFINITIONS,
|
||||
{
|
||||
format: (definitionFormat == 'JSON' ?
|
||||
format: (definitionFormat === 'JSON' ?
|
||||
BlocklyDevTools.Analytics.FORMAT_JSON :
|
||||
BlocklyDevTools.Analytics.FORMAT_JS)
|
||||
});
|
||||
@@ -226,9 +226,9 @@ BlockExporterController.prototype.selectUsedBlocks = function() {
|
||||
var unstoredCustomBlockTypes = [];
|
||||
|
||||
for (var i = 0, blockType; blockType = this.usedBlockTypes[i]; i++) {
|
||||
if (storedBlockTypes.indexOf(blockType) != -1) {
|
||||
if (storedBlockTypes.indexOf(blockType) !== -1) {
|
||||
sharedBlockTypes.push(blockType);
|
||||
} else if (StandardCategories.coreBlockTypes.indexOf(blockType) == -1) {
|
||||
} else if (StandardCategories.coreBlockTypes.indexOf(blockType) === -1) {
|
||||
unstoredCustomBlockTypes.push(blockType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ BlockExporterTools.prototype.getBlockDefinitions =
|
||||
}
|
||||
|
||||
// Surround json with [] and comma separate items.
|
||||
if (definitionFormat == "JSON") {
|
||||
if (definitionFormat === "JSON") {
|
||||
return "[" + blockCode.join(",\n") + "]";
|
||||
}
|
||||
return blockCode.join("\n\n");
|
||||
|
||||
@@ -111,7 +111,7 @@ BlockLibraryController.prototype.clearBlockLibrary = function() {
|
||||
BlockLibraryController.prototype.saveToBlockLibrary = function() {
|
||||
var blockType = this.getCurrentBlockType();
|
||||
// If user has not changed the name of the starter block.
|
||||
if (blockType == 'block_type') {
|
||||
if (blockType === 'block_type') {
|
||||
// Do not save block if it has the default type, 'block_type'.
|
||||
var msg = 'You cannot save a block under the name "block_type". Try ' +
|
||||
'changing the name before saving. Then, click on the "Block Library"' +
|
||||
@@ -151,7 +151,7 @@ BlockLibraryController.prototype.saveToBlockLibrary = function() {
|
||||
*/
|
||||
BlockLibraryController.prototype.has = function(blockType) {
|
||||
var blockLibrary = this.storage.blocks;
|
||||
return (blockType in blockLibrary && blockLibrary[blockType] != null);
|
||||
return (blockType in blockLibrary && blockLibrary[blockType] !== null);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,7 +26,7 @@ function BlockLibraryStorage(blockLibraryName, opt_blocks) {
|
||||
if (!opt_blocks) {
|
||||
// Initialize this.blocks by loading from local storage.
|
||||
this.loadFromLocalStorage();
|
||||
if (this.blocks == null) {
|
||||
if (this.blocks === null) {
|
||||
this.blocks = Object.create(null);
|
||||
// The line above is equivalent of {} except that this object is TRULY
|
||||
// empty. It doesn't have built-in attributes/functions such as length or
|
||||
|
||||
@@ -64,7 +64,7 @@ BlockLibraryView.prototype.setSelectedBlockType = function(blockTypeToSelect) {
|
||||
// if null or invalid block type selected.
|
||||
for (var blockType in this.optionMap) {
|
||||
var option = this.optionMap[blockType];
|
||||
if (blockType == blockTypeToSelect) {
|
||||
if (blockType === blockTypeToSelect) {
|
||||
this.selectOption_(option);
|
||||
} else {
|
||||
this.deselectOption_(option);
|
||||
@@ -127,7 +127,7 @@ BlockLibraryView.prototype.updateButtons =
|
||||
|
||||
// If block type is the default, 'block_type', make button red to alert
|
||||
// user.
|
||||
if (blockType == 'block_type') {
|
||||
if (blockType === 'block_type') {
|
||||
buttonFormatClass = 'button_alert';
|
||||
}
|
||||
this.saveButton.classList.add(buttonFormatClass);
|
||||
|
||||
@@ -95,21 +95,21 @@ Blockly.Blocks['factory_base'] = {
|
||||
var outputExists = this.getInput('OUTPUTTYPE');
|
||||
var topExists = this.getInput('TOPTYPE');
|
||||
var bottomExists = this.getInput('BOTTOMTYPE');
|
||||
if (option == 'LEFT') {
|
||||
if (option === 'LEFT') {
|
||||
if (!outputExists) {
|
||||
this.addTypeInput_('OUTPUTTYPE', 'output type');
|
||||
}
|
||||
} else if (outputExists) {
|
||||
this.removeInput('OUTPUTTYPE');
|
||||
}
|
||||
if (option == 'TOP' || option == 'BOTH') {
|
||||
if (option === 'TOP' || option === 'BOTH') {
|
||||
if (!topExists) {
|
||||
this.addTypeInput_('TOPTYPE', 'top type');
|
||||
}
|
||||
} else if (topExists) {
|
||||
this.removeInput('TOPTYPE');
|
||||
}
|
||||
if (option == 'BOTTOM' || option == 'BOTH') {
|
||||
if (option === 'BOTTOM' || option === 'BOTH') {
|
||||
if (!bottomExists) {
|
||||
this.addTypeInput_('BOTTOMTYPE', 'bottom type');
|
||||
}
|
||||
@@ -352,7 +352,7 @@ Blockly.Blocks['field_dropdown'] = {
|
||||
domToMutation: function(container) {
|
||||
// Parse XML to restore the menu options.
|
||||
var value = JSON.parse(container.getAttribute('options'));
|
||||
if (typeof value == 'number') {
|
||||
if (typeof value === 'number') {
|
||||
// Old format from before images were added. November 2016.
|
||||
this.optionList_ = [];
|
||||
for (var i = 0; i < value; i++) {
|
||||
@@ -384,9 +384,9 @@ Blockly.Blocks['field_dropdown'] = {
|
||||
this.optionList_.length = 0;
|
||||
var data = [];
|
||||
while (optionBlock) {
|
||||
if (optionBlock.type == 'field_dropdown_option_text') {
|
||||
if (optionBlock.type === 'field_dropdown_option_text') {
|
||||
this.optionList_.push('text');
|
||||
} else if (optionBlock.type == 'field_dropdown_option_image') {
|
||||
} else if (optionBlock.type === 'field_dropdown_option_image') {
|
||||
this.optionList_.push('image');
|
||||
}
|
||||
data.push([optionBlock.userData_, optionBlock.cpuData_]);
|
||||
@@ -398,7 +398,7 @@ Blockly.Blocks['field_dropdown'] = {
|
||||
for (var i = 0; i < this.optionList_.length; i++) {
|
||||
var userData = data[i][0];
|
||||
if (userData !== undefined) {
|
||||
if (typeof userData == 'string') {
|
||||
if (typeof userData === 'string') {
|
||||
this.setFieldValue(userData || 'option', 'USER' + i);
|
||||
} else {
|
||||
this.setFieldValue(userData.src, 'SRC' + i);
|
||||
@@ -434,13 +434,13 @@ Blockly.Blocks['field_dropdown'] = {
|
||||
var src = 'https://www.gstatic.com/codesite/ph/images/star_on.gif';
|
||||
for (var i = 0; i <= this.optionList_.length; i++) {
|
||||
var type = this.optionList_[i];
|
||||
if (type == 'text') {
|
||||
if (type === 'text') {
|
||||
this.appendDummyInput('OPTION' + i)
|
||||
.appendField('•')
|
||||
.appendField(new Blockly.FieldTextInput('option'), 'USER' + i)
|
||||
.appendField(',')
|
||||
.appendField(new Blockly.FieldTextInput('OPTIONNAME'), 'CPU' + i);
|
||||
} else if (type == 'image') {
|
||||
} else if (type === 'image') {
|
||||
this.appendDummyInput('OPTION' + i)
|
||||
.appendField('•')
|
||||
.appendField('image')
|
||||
@@ -466,10 +466,10 @@ Blockly.Blocks['field_dropdown'] = {
|
||||
}
|
||||
},
|
||||
getUserData: function(n) {
|
||||
if (this.optionList_[n] == 'text') {
|
||||
if (this.optionList_[n] === 'text') {
|
||||
return this.getFieldValue('USER' + n);
|
||||
}
|
||||
if (this.optionList_[n] == 'image') {
|
||||
if (this.optionList_[n] === 'image') {
|
||||
return {
|
||||
src: this.getFieldValue('SRC' + n),
|
||||
width: Number(this.getFieldValue('WIDTH' + n)),
|
||||
@@ -633,7 +633,7 @@ Blockly.Blocks['type_group'] = {
|
||||
for (var i = 0; i < this.typeCount_; i++) {
|
||||
var input = this.appendValueInput('TYPE' + i)
|
||||
.setCheck('Type');
|
||||
if (i == 0) {
|
||||
if (i === 0) {
|
||||
input.appendField('any of');
|
||||
}
|
||||
}
|
||||
@@ -664,7 +664,7 @@ Blockly.Blocks['type_group'] = {
|
||||
// Disconnect any children that don't belong.
|
||||
for (var i = 0; i < this.typeCount_; i++) {
|
||||
var connection = this.getInput('TYPE' + i).connection.targetConnection;
|
||||
if (connection && connections.indexOf(connection) == -1) {
|
||||
if (connection && connections.indexOf(connection) === -1) {
|
||||
connection.disconnect();
|
||||
}
|
||||
}
|
||||
@@ -693,7 +693,7 @@ Blockly.Blocks['type_group'] = {
|
||||
for (var i = 0; i < this.typeCount_; i++) {
|
||||
if (!this.getInput('TYPE' + i)) {
|
||||
var input = this.appendValueInput('TYPE' + i);
|
||||
if (i == 0) {
|
||||
if (i === 0) {
|
||||
input.appendField('any of');
|
||||
}
|
||||
}
|
||||
@@ -863,7 +863,7 @@ function fieldNameCheck(referenceBlock) {
|
||||
for (var i = 0, block; block = blocks[i]; i++) {
|
||||
var otherName = block.getFieldValue('FIELDNAME');
|
||||
if (!block.disabled && !block.getInheritedDisabled() &&
|
||||
otherName && otherName.toLowerCase() == name) {
|
||||
otherName && otherName.toLowerCase() === name) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
@@ -888,7 +888,7 @@ function inputNameCheck(referenceBlock) {
|
||||
for (var i = 0, block; block = blocks[i]; i++) {
|
||||
var otherName = block.getFieldValue('INPUTNAME');
|
||||
if (!block.disabled && !block.getInheritedDisabled() &&
|
||||
otherName && otherName.toLowerCase() == name) {
|
||||
otherName && otherName.toLowerCase() === name) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ function cp_open(e) {
|
||||
} else {
|
||||
div.innerHTML = 'X';
|
||||
}
|
||||
if (currentColour == colour.toLowerCase()) {
|
||||
if (currentColour === colour.toLowerCase()) {
|
||||
div.className = 'cp_current'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,8 +86,8 @@ BlockFactory.formatChange = function() {
|
||||
var mask = document.getElementById('blocklyMask');
|
||||
var languagePre = document.getElementById('languagePre');
|
||||
var languageTA = document.getElementById('languageTA');
|
||||
if (document.getElementById('format').value == 'Manual-JSON' ||
|
||||
document.getElementById('format').value == 'Manual-JS') {
|
||||
if (document.getElementById('format').value === 'Manual-JSON' ||
|
||||
document.getElementById('format').value === 'Manual-JS') {
|
||||
Blockly.common.getMainWorkspace().hideChaff();
|
||||
mask.style.display = 'block';
|
||||
languagePre.style.display = 'none';
|
||||
@@ -123,9 +123,9 @@ BlockFactory.updateLanguage = function() {
|
||||
|
||||
if (!BlockFactory.updateBlocksFlag) {
|
||||
var format = document.getElementById('format').value;
|
||||
if (format == 'Manual-JSON') {
|
||||
if (format === 'Manual-JSON') {
|
||||
format = 'JSON';
|
||||
} else if (format == 'Manual-JS') {
|
||||
} else if (format === 'Manual-JS') {
|
||||
format = 'JavaScript';
|
||||
}
|
||||
|
||||
@@ -159,11 +159,11 @@ BlockFactory.updateGenerator = function(block) {
|
||||
BlockFactory.updatePreview = function() {
|
||||
// Toggle between LTR/RTL if needed (also used in first display).
|
||||
var newDir = document.getElementById('direction').value;
|
||||
if (BlockFactory.oldDir != newDir) {
|
||||
if (BlockFactory.oldDir !== newDir) {
|
||||
if (BlockFactory.previewWorkspace) {
|
||||
BlockFactory.previewWorkspace.dispose();
|
||||
}
|
||||
var rtl = newDir == 'rtl';
|
||||
var rtl = newDir === 'rtl';
|
||||
BlockFactory.previewWorkspace = Blockly.inject('preview',
|
||||
{rtl: rtl,
|
||||
media: '../../media/',
|
||||
@@ -190,14 +190,14 @@ BlockFactory.updatePreview = function() {
|
||||
delete Blockly.Blocks[key];
|
||||
}
|
||||
|
||||
if (format == 'JSON') {
|
||||
if (format === 'JSON') {
|
||||
var json = JSON.parse(code);
|
||||
Blockly.Blocks[json.type || BlockFactory.UNNAMED] = {
|
||||
init: function() {
|
||||
this.jsonInit(json);
|
||||
}
|
||||
};
|
||||
} else if (format == 'JavaScript') {
|
||||
} else if (format === 'JavaScript') {
|
||||
try {
|
||||
eval(code);
|
||||
} catch (e) {
|
||||
@@ -229,11 +229,11 @@ BlockFactory.updatePreview = function() {
|
||||
// Warn user only if their block type is already exists in Blockly's
|
||||
// standard library.
|
||||
var rootBlock = FactoryUtils.getRootBlock(BlockFactory.mainWorkspace);
|
||||
if (StandardCategories.coreBlockTypes.indexOf(blockType) != -1) {
|
||||
if (StandardCategories.coreBlockTypes.indexOf(blockType) !== -1) {
|
||||
rootBlock.setWarningText('A core Blockly block already exists ' +
|
||||
'under this name.');
|
||||
|
||||
} else if (blockType == 'block_type') {
|
||||
} else if (blockType === 'block_type') {
|
||||
// Warn user to let them know they can't save a block under the default
|
||||
// name 'block_type'
|
||||
rootBlock.setWarningText('You cannot save a block with the default ' +
|
||||
@@ -284,7 +284,7 @@ BlockFactory.disableEnableLink = function() {
|
||||
var linkButton = document.getElementById('linkButton');
|
||||
var saveBlockButton = document.getElementById('localSaveButton');
|
||||
var saveToLibButton = document.getElementById('saveToBlockLibraryButton');
|
||||
var disabled = document.getElementById('format').value.substr(0, 6) == 'Manual';
|
||||
var disabled = document.getElementById('format').value.substr(0, 6) === 'Manual';
|
||||
linkButton.disabled = disabled;
|
||||
saveBlockButton.disabled = disabled;
|
||||
saveToLibButton.disabled = disabled;
|
||||
@@ -308,11 +308,11 @@ BlockFactory.isStarterBlock = function() {
|
||||
// The starter block does not have blocks nested into the factory_base block.
|
||||
rootBlock.getChildren().length > 0 ||
|
||||
// The starter block's name is the default, 'block_type'.
|
||||
rootBlock.getFieldValue('NAME').trim().toLowerCase() != 'block_type' ||
|
||||
rootBlock.getFieldValue('NAME').trim().toLowerCase() !== 'block_type' ||
|
||||
// The starter block has no connections.
|
||||
rootBlock.getFieldValue('CONNECTIONS') != 'NONE' ||
|
||||
rootBlock.getFieldValue('CONNECTIONS') !== 'NONE' ||
|
||||
// The starter block has automatic inputs.
|
||||
rootBlock.getFieldValue('INLINE') != 'AUTO'
|
||||
rootBlock.getFieldValue('INLINE') !== 'AUTO'
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ FactoryUtils.getGeneratorStub = function(block, generatorLanguage) {
|
||||
" = block.getFieldValue('" + name + "');");
|
||||
} else if (field instanceof Blockly.FieldCheckbox) {
|
||||
code.push(makeVar('checkbox', name) +
|
||||
" = block.getFieldValue('" + name + "') == 'TRUE';");
|
||||
" = block.getFieldValue('" + name + "') === 'TRUE';");
|
||||
} else if (field instanceof Blockly.FieldDropdown) {
|
||||
code.push(makeVar('dropdown', name) +
|
||||
" = block.getFieldValue('" + name + "');");
|
||||
@@ -122,11 +122,11 @@ FactoryUtils.getGeneratorStub = function(block, generatorLanguage) {
|
||||
}
|
||||
var name = input.name;
|
||||
if (name) {
|
||||
if (input.type == Blockly.INPUT_VALUE) {
|
||||
if (input.type === Blockly.INPUT_VALUE) {
|
||||
code.push(makeVar('value', name) +
|
||||
" = Blockly." + language + ".valueToCode(block, '" + name +
|
||||
"', Blockly." + language + ".ORDER_ATOMIC);");
|
||||
} else if (input.type == Blockly.NEXT_STATEMENT) {
|
||||
} else if (input.type === Blockly.NEXT_STATEMENT) {
|
||||
code.push(makeVar('statements', name) +
|
||||
" = Blockly." + language + ".statementToCode(block, '" +
|
||||
name + "');");
|
||||
@@ -176,7 +176,7 @@ FactoryUtils.formatJson_ = function(blockType, rootBlock) {
|
||||
var fields = FactoryUtils.getFieldsJson_(
|
||||
contentsBlock.getInputTargetBlock('FIELDS'));
|
||||
for (var i = 0; i < fields.length; i++) {
|
||||
if (typeof fields[i] == 'string') {
|
||||
if (typeof fields[i] === 'string') {
|
||||
message.push(fields[i].replace(/%/g, '%%'));
|
||||
} else {
|
||||
args.push(fields[i]);
|
||||
@@ -186,7 +186,7 @@ FactoryUtils.formatJson_ = function(blockType, rootBlock) {
|
||||
|
||||
var input = {type: contentsBlock.type};
|
||||
// Dummy inputs don't have names. Other inputs do.
|
||||
if (contentsBlock.type != 'input_dummy') {
|
||||
if (contentsBlock.type !== 'input_dummy') {
|
||||
input.name = contentsBlock.getFieldValue('INPUTNAME');
|
||||
}
|
||||
var check = JSON.parse(
|
||||
@@ -195,7 +195,7 @@ FactoryUtils.formatJson_ = function(blockType, rootBlock) {
|
||||
input.check = check;
|
||||
}
|
||||
var align = contentsBlock.getFieldValue('ALIGN');
|
||||
if (align != 'LEFT') {
|
||||
if (align !== 'LEFT') {
|
||||
input.align = align;
|
||||
}
|
||||
args.push(input);
|
||||
@@ -206,11 +206,11 @@ FactoryUtils.formatJson_ = function(blockType, rootBlock) {
|
||||
contentsBlock.nextConnection.targetBlock();
|
||||
}
|
||||
// Remove last input if dummy and not empty.
|
||||
if (lastInput && lastInput.type == 'input_dummy') {
|
||||
if (lastInput && lastInput.type === 'input_dummy') {
|
||||
var fields = lastInput.getInputTargetBlock('FIELDS');
|
||||
if (fields && FactoryUtils.getFieldsJson_(fields).join('').trim() != '') {
|
||||
if (fields && FactoryUtils.getFieldsJson_(fields).join('').trim() !== '') {
|
||||
var align = lastInput.getFieldValue('ALIGN');
|
||||
if (align != 'LEFT') {
|
||||
if (align !== 'LEFT') {
|
||||
JS.lastDummyAlign0 = align;
|
||||
}
|
||||
args.pop();
|
||||
@@ -222,9 +222,9 @@ FactoryUtils.formatJson_ = function(blockType, rootBlock) {
|
||||
JS.args0 = args;
|
||||
}
|
||||
// Generate inline/external switch.
|
||||
if (rootBlock.getFieldValue('INLINE') == 'EXT') {
|
||||
if (rootBlock.getFieldValue('INLINE') === 'EXT') {
|
||||
JS.inputsInline = false;
|
||||
} else if (rootBlock.getFieldValue('INLINE') == 'INT') {
|
||||
} else if (rootBlock.getFieldValue('INLINE') === 'INT') {
|
||||
JS.inputsInline = true;
|
||||
}
|
||||
// Generate output, or next/previous connections.
|
||||
@@ -287,7 +287,7 @@ FactoryUtils.formatJavaScript_ = function(blockType, rootBlock, workspace) {
|
||||
if (!contentsBlock.disabled && !contentsBlock.getInheritedDisabled()) {
|
||||
var name = '';
|
||||
// Dummy inputs don't have names. Other inputs do.
|
||||
if (contentsBlock.type != 'input_dummy') {
|
||||
if (contentsBlock.type !== 'input_dummy') {
|
||||
name =
|
||||
JSON.stringify(contentsBlock.getFieldValue('INPUTNAME'));
|
||||
}
|
||||
@@ -297,7 +297,7 @@ FactoryUtils.formatJavaScript_ = function(blockType, rootBlock, workspace) {
|
||||
code.push(' .setCheck(' + check + ')');
|
||||
}
|
||||
var align = contentsBlock.getFieldValue('ALIGN');
|
||||
if (align != 'LEFT') {
|
||||
if (align !== 'LEFT') {
|
||||
code.push(' .setAlign(Blockly.ALIGN_' + align + ')');
|
||||
}
|
||||
var fields = FactoryUtils.getFieldsJs_(
|
||||
@@ -312,9 +312,9 @@ FactoryUtils.formatJavaScript_ = function(blockType, rootBlock, workspace) {
|
||||
contentsBlock.nextConnection.targetBlock();
|
||||
}
|
||||
// Generate inline/external switch.
|
||||
if (rootBlock.getFieldValue('INLINE') == 'EXT') {
|
||||
if (rootBlock.getFieldValue('INLINE') === 'EXT') {
|
||||
code.push(' this.setInputsInline(false);');
|
||||
} else if (rootBlock.getFieldValue('INLINE') == 'INT') {
|
||||
} else if (rootBlock.getFieldValue('INLINE') === 'INT') {
|
||||
code.push(' this.setInputsInline(true);');
|
||||
}
|
||||
// Generate output, or next/previous connections.
|
||||
@@ -410,11 +410,11 @@ FactoryUtils.getFieldsJs_ = function(block) {
|
||||
Number(block.getFieldValue('PRECISION'))
|
||||
];
|
||||
// Remove any trailing arguments that aren't needed.
|
||||
if (args[3] == 0) {
|
||||
if (args[3] === 0) {
|
||||
args.pop();
|
||||
if (args[2] == Infinity) {
|
||||
if (args[2] === Infinity) {
|
||||
args.pop();
|
||||
if (args[1] == -Infinity) {
|
||||
if (args[1] === -Infinity) {
|
||||
args.pop();
|
||||
}
|
||||
}
|
||||
@@ -541,7 +541,7 @@ FactoryUtils.getFieldsJson_ = function(block) {
|
||||
fields.push({
|
||||
type: block.type,
|
||||
name: block.getFieldValue('FIELDNAME'),
|
||||
checked: block.getFieldValue('CHECKED') == 'TRUE'
|
||||
checked: block.getFieldValue('CHECKED') === 'TRUE'
|
||||
});
|
||||
break;
|
||||
case 'field_colour':
|
||||
@@ -579,7 +579,7 @@ FactoryUtils.getFieldsJson_ = function(block) {
|
||||
width: Number(block.getFieldValue('WIDTH')),
|
||||
height: Number(block.getFieldValue('HEIGHT')),
|
||||
alt: block.getFieldValue('ALT'),
|
||||
flipRtl: block.getFieldValue('FLIP_RTL') == 'TRUE'
|
||||
flipRtl: block.getFieldValue('FLIP_RTL') === 'TRUE'
|
||||
});
|
||||
break;
|
||||
}
|
||||
@@ -598,11 +598,11 @@ FactoryUtils.getFieldsJson_ = function(block) {
|
||||
*/
|
||||
FactoryUtils.getOptTypesFrom = function(block, name) {
|
||||
var types = FactoryUtils.getTypesFrom_(block, name);
|
||||
if (types.length == 0) {
|
||||
if (types.length === 0) {
|
||||
return undefined;
|
||||
} else if (types.indexOf('null') != -1) {
|
||||
} else if (types.indexOf('null') !== -1) {
|
||||
return 'null';
|
||||
} else if (types.length == 1) {
|
||||
} else if (types.length === 1) {
|
||||
return types[0];
|
||||
} else {
|
||||
return '[' + types.join(', ') + ']';
|
||||
@@ -622,9 +622,9 @@ FactoryUtils.getTypesFrom_ = function(block, name) {
|
||||
var types;
|
||||
if (!typeBlock || typeBlock.disabled) {
|
||||
types = [];
|
||||
} else if (typeBlock.type == 'type_other') {
|
||||
} else if (typeBlock.type === 'type_other') {
|
||||
types = [JSON.stringify(typeBlock.getFieldValue('TYPE'))];
|
||||
} else if (typeBlock.type == 'type_group') {
|
||||
} else if (typeBlock.type === 'type_group') {
|
||||
types = [];
|
||||
for (var n = 0; n < typeBlock.typeCount_; n++) {
|
||||
types = types.concat(FactoryUtils.getTypesFrom_(typeBlock, 'TYPE' + n));
|
||||
@@ -652,7 +652,7 @@ FactoryUtils.getTypesFrom_ = function(block, name) {
|
||||
FactoryUtils.getRootBlock = function(workspace) {
|
||||
var blocks = workspace.getTopBlocks(false);
|
||||
for (var i = 0, block; block = blocks[i]; i++) {
|
||||
if (block.type == 'factory_base') {
|
||||
if (block.type === 'factory_base') {
|
||||
return block;
|
||||
}
|
||||
}
|
||||
@@ -735,7 +735,7 @@ FactoryUtils.getDefinedBlock = function(blockType, workspace) {
|
||||
FactoryUtils.getBlockTypeFromJsDefinition = function(blockDef) {
|
||||
var indexOfStartBracket = blockDef.indexOf('[\'');
|
||||
var indexOfEndBracket = blockDef.indexOf('\']');
|
||||
if (indexOfStartBracket != -1 && indexOfEndBracket != -1) {
|
||||
if (indexOfStartBracket !== -1 && indexOfEndBracket !== -1) {
|
||||
return blockDef.substring(indexOfStartBracket + 2, indexOfEndBracket);
|
||||
} else {
|
||||
throw Error('Could not parse block type out of JavaScript block ' +
|
||||
@@ -777,9 +777,9 @@ FactoryUtils.parseJsBlockDefinitions = function(blockDefsString) {
|
||||
var blockDefArray = [];
|
||||
var defStart = blockDefsString.indexOf('Blockly.Blocks');
|
||||
|
||||
while (blockDefsString.indexOf('Blockly.Blocks', defStart) != -1) {
|
||||
while (blockDefsString.indexOf('Blockly.Blocks', defStart) !== -1) {
|
||||
var nextStart = blockDefsString.indexOf('Blockly.Blocks', defStart + 1);
|
||||
if (nextStart == -1) {
|
||||
if (nextStart === -1) {
|
||||
// This is the last block definition.
|
||||
nextStart = blockDefsString.length;
|
||||
}
|
||||
@@ -807,12 +807,12 @@ FactoryUtils.parseJsonBlockDefinitions = function(blockDefsString) {
|
||||
// are balanced.
|
||||
for (var i = 0; i < blockDefsString.length; i++) {
|
||||
var currentChar = blockDefsString[i];
|
||||
if (currentChar == '{') {
|
||||
if (currentChar === '{') {
|
||||
unbalancedBracketCount++;
|
||||
}
|
||||
else if (currentChar == '}') {
|
||||
else if (currentChar === '}') {
|
||||
unbalancedBracketCount--;
|
||||
if (unbalancedBracketCount == 0 && i > 0) {
|
||||
if (unbalancedBracketCount === 0 && i > 0) {
|
||||
// The brackets are balanced. We've got a complete block definition.
|
||||
var blockDef = blockDefsString.substring(defStart, i + 1);
|
||||
blockDefArray.push(blockDef);
|
||||
@@ -833,7 +833,7 @@ FactoryUtils.defineAndGetBlockTypes = function(blockDefsString, format) {
|
||||
var blockTypes = [];
|
||||
|
||||
// Define blocks and get block types.
|
||||
if (format == 'JSON') {
|
||||
if (format === 'JSON') {
|
||||
var blockDefArray = FactoryUtils.parseJsonBlockDefinitions(blockDefsString);
|
||||
|
||||
// Populate array of blocktypes and define each block.
|
||||
@@ -848,7 +848,7 @@ FactoryUtils.defineAndGetBlockTypes = function(blockDefsString, format) {
|
||||
}
|
||||
};
|
||||
}
|
||||
} else if (format == 'JavaScript') {
|
||||
} else if (format === 'JavaScript') {
|
||||
var blockDefArray = FactoryUtils.parseJsBlockDefinitions(blockDefsString);
|
||||
|
||||
// Populate array of block types.
|
||||
@@ -890,8 +890,8 @@ FactoryUtils.injectCode = function(code, id) {
|
||||
*/
|
||||
FactoryUtils.sameBlockXml = function(blockXml1, blockXml2) {
|
||||
// Each XML element should contain a single child element with a 'block' tag
|
||||
if (blockXml1.tagName.toLowerCase() != 'xml' ||
|
||||
blockXml2.tagName.toLowerCase() != 'xml') {
|
||||
if (blockXml1.tagName.toLowerCase() !== 'xml' ||
|
||||
blockXml2.tagName.toLowerCase() !== 'xml') {
|
||||
throw Error('Expected two XML elements, received elements with tag ' +
|
||||
'names: ' + blockXml1.tagName + ' and ' + blockXml2.tagName + '.');
|
||||
}
|
||||
@@ -916,7 +916,7 @@ FactoryUtils.sameBlockXml = function(blockXml1, blockXml2) {
|
||||
blockXmlText2 = blockXmlText2.replace(/\s+/g, '');
|
||||
|
||||
// Return whether or not changes have been saved.
|
||||
return blockXmlText1 == blockXmlText2;
|
||||
return blockXmlText1 === blockXmlText2;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -982,11 +982,11 @@ FactoryUtils.hasVariableField = function(block) {
|
||||
*/
|
||||
FactoryUtils.isProcedureBlock = function(block) {
|
||||
return block &&
|
||||
(block.type == 'procedures_defnoreturn' ||
|
||||
block.type == 'procedures_defreturn' ||
|
||||
block.type == 'procedures_callnoreturn' ||
|
||||
block.type == 'procedures_callreturn' ||
|
||||
block.type == 'procedures_ifreturn');
|
||||
(block.type === 'procedures_defnoreturn' ||
|
||||
block.type === 'procedures_defreturn' ||
|
||||
block.type === 'procedures_callnoreturn' ||
|
||||
block.type === 'procedures_callreturn' ||
|
||||
block.type === 'procedures_ifreturn');
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -369,7 +369,7 @@
|
||||
// Manual JavaScript works but requires use of eval().
|
||||
// TODO(#1269): Replace eval() with JS-Interpreter before
|
||||
// re-enabling "Manual JavaScript" mode.
|
||||
if (document.location.href.indexOf('file://') == 0) {
|
||||
if (document.location.href.indexOf('file://') === 0) {
|
||||
document.write(
|
||||
'<option value="Manual-JS">Manual JavaScript…</option>');
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ WorkspaceFactoryController.prototype.switchElement = function(id) {
|
||||
Blockly.Events.disable();
|
||||
// Caches information to reload or generate XML if switching to/from element.
|
||||
// Only saves if a category is selected.
|
||||
if (this.model.getSelectedId() != null && id != null) {
|
||||
if (this.model.getSelectedId() !== null && id !== null) {
|
||||
this.model.getSelected().saveFromWorkspace(this.toolboxWorkspace);
|
||||
}
|
||||
// Load element.
|
||||
@@ -263,13 +263,13 @@ WorkspaceFactoryController.prototype.switchElement = function(id) {
|
||||
*/
|
||||
WorkspaceFactoryController.prototype.clearAndLoadElement = function(id) {
|
||||
// Unselect current tab if switching to and from an element.
|
||||
if (this.model.getSelectedId() != null && id != null) {
|
||||
if (this.model.getSelectedId() !== null && id !== null) {
|
||||
this.view.setCategoryTabSelection(this.model.getSelectedId(), false);
|
||||
}
|
||||
|
||||
// If switching to another category, set category selection in the model and
|
||||
// view.
|
||||
if (id != null) {
|
||||
if (id !== null) {
|
||||
// Set next category.
|
||||
this.model.setSelectedById(id);
|
||||
|
||||
@@ -301,7 +301,7 @@ WorkspaceFactoryController.prototype.clearAndLoadElement = function(id) {
|
||||
*/
|
||||
WorkspaceFactoryController.prototype.exportXmlFile = function(exportMode) {
|
||||
// Get file name.
|
||||
if (exportMode == WorkspaceFactoryController.MODE_TOOLBOX) {
|
||||
if (exportMode === WorkspaceFactoryController.MODE_TOOLBOX) {
|
||||
var fileName = prompt('File Name for toolbox XML:', 'toolbox.xml');
|
||||
} else {
|
||||
var fileName = prompt('File Name for pre-loaded workspace XML:',
|
||||
@@ -312,12 +312,12 @@ WorkspaceFactoryController.prototype.exportXmlFile = function(exportMode) {
|
||||
}
|
||||
|
||||
// Generate XML.
|
||||
if (exportMode == WorkspaceFactoryController.MODE_TOOLBOX) {
|
||||
if (exportMode === WorkspaceFactoryController.MODE_TOOLBOX) {
|
||||
// Export the toolbox XML.
|
||||
var configXml = Blockly.Xml.domToPrettyText(
|
||||
this.generator.generateToolboxXml());
|
||||
this.hasUnsavedToolboxChanges = false;
|
||||
} else if (exportMode == WorkspaceFactoryController.MODE_PRELOAD) {
|
||||
} else if (exportMode === WorkspaceFactoryController.MODE_PRELOAD) {
|
||||
// Export the pre-loaded block XML.
|
||||
var configXml = Blockly.Xml.domToPrettyText(
|
||||
this.generator.generateWorkspaceXml());
|
||||
@@ -333,11 +333,11 @@ WorkspaceFactoryController.prototype.exportXmlFile = function(exportMode) {
|
||||
var data = new Blob([configXml], {type: 'text/xml'});
|
||||
this.view.createAndDownloadFile(fileName, data);
|
||||
|
||||
if (exportMode == WorkspaceFactoryController.MODE_TOOLBOX) {
|
||||
if (exportMode === WorkspaceFactoryController.MODE_TOOLBOX) {
|
||||
BlocklyDevTools.Analytics.onExport(
|
||||
BlocklyDevTools.Analytics.TOOLBOX,
|
||||
{ format: BlocklyDevTools.Analytics.FORMAT_XML });
|
||||
} else if (exportMode == WorkspaceFactoryController.MODE_PRELOAD) {
|
||||
} else if (exportMode === WorkspaceFactoryController.MODE_PRELOAD) {
|
||||
BlocklyDevTools.Analytics.onExport(
|
||||
BlocklyDevTools.Analytics.WORKSPACE_CONTENTS,
|
||||
{ format: BlocklyDevTools.Analytics.FORMAT_XML });
|
||||
@@ -402,7 +402,7 @@ WorkspaceFactoryController.prototype.updatePreview = function() {
|
||||
this.generator.generateToolboxXml());
|
||||
|
||||
// No categories, creates a simple flyout.
|
||||
if (tree.getElementsByTagName('category').length == 0) {
|
||||
if (tree.getElementsByTagName('category').length === 0) {
|
||||
// No categories, creates a simple flyout.
|
||||
if (this.previewWorkspace.toolbox_) {
|
||||
this.reinjectPreview(tree); // Switch to simple flyout, expensive.
|
||||
@@ -436,20 +436,20 @@ WorkspaceFactoryController.prototype.updatePreview = function() {
|
||||
* be called after making changes to the workspace.
|
||||
*/
|
||||
WorkspaceFactoryController.prototype.saveStateFromWorkspace = function() {
|
||||
if (this.selectedMode == WorkspaceFactoryController.MODE_TOOLBOX) {
|
||||
if (this.selectedMode === WorkspaceFactoryController.MODE_TOOLBOX) {
|
||||
// If currently editing the toolbox.
|
||||
// Update flags if toolbox has been changed.
|
||||
if (this.model.getSelectedXml() !=
|
||||
if (this.model.getSelectedXml() !==
|
||||
Blockly.Xml.workspaceToDom(this.toolboxWorkspace)) {
|
||||
this.hasUnsavedToolboxChanges = true;
|
||||
}
|
||||
|
||||
this.model.getSelected().saveFromWorkspace(this.toolboxWorkspace);
|
||||
|
||||
} else if (this.selectedMode == WorkspaceFactoryController.MODE_PRELOAD) {
|
||||
} else if (this.selectedMode === WorkspaceFactoryController.MODE_PRELOAD) {
|
||||
// If currently editing the pre-loaded workspace.
|
||||
// Update flags if preloaded blocks have been changed.
|
||||
if (this.model.getPreloadXml() !=
|
||||
if (this.model.getPreloadXml() !==
|
||||
Blockly.Xml.workspaceToDom(this.toolboxWorkspace)) {
|
||||
this.hasUnsavedPreloadChanges = true;
|
||||
}
|
||||
@@ -486,7 +486,7 @@ WorkspaceFactoryController.prototype.changeSelectedCategory = function(name,
|
||||
colour) {
|
||||
var selected = this.model.getSelected();
|
||||
// Return if a category is not selected.
|
||||
if (selected.type != ListElement.TYPE_CATEGORY) {
|
||||
if (selected.type !== ListElement.TYPE_CATEGORY) {
|
||||
return;
|
||||
}
|
||||
// Change colour of selected category.
|
||||
@@ -571,12 +571,12 @@ WorkspaceFactoryController.prototype.loadCategoryByName = function(name) {
|
||||
if (!this.isStandardCategoryName(name)) {
|
||||
return;
|
||||
}
|
||||
if (this.model.hasVariables() && name.toLowerCase() == 'variables') {
|
||||
if (this.model.hasVariables() && name.toLowerCase() === 'variables') {
|
||||
alert('A Variables category already exists. You cannot create multiple' +
|
||||
' variables categories.');
|
||||
return;
|
||||
}
|
||||
if (this.model.hasProcedures() && name.toLowerCase() == 'functions') {
|
||||
if (this.model.hasProcedures() && name.toLowerCase() === 'functions') {
|
||||
alert('A Functions category already exists. You cannot create multiple' +
|
||||
' functions categories.');
|
||||
return;
|
||||
@@ -704,7 +704,7 @@ WorkspaceFactoryController.prototype.importFile = function(file, importMode) {
|
||||
// Print error message if fail.
|
||||
try {
|
||||
var tree = Blockly.Xml.textToDom(reader.result);
|
||||
if (importMode == WorkspaceFactoryController.MODE_TOOLBOX) {
|
||||
if (importMode === WorkspaceFactoryController.MODE_TOOLBOX) {
|
||||
// Switch mode.
|
||||
controller.setMode(WorkspaceFactoryController.MODE_TOOLBOX);
|
||||
|
||||
@@ -724,7 +724,7 @@ WorkspaceFactoryController.prototype.importFile = function(file, importMode) {
|
||||
controller.importToolboxFromTree_(tree);
|
||||
BlocklyDevTools.Analytics.onImport('Toolbox.xml');
|
||||
|
||||
} else if (importMode == WorkspaceFactoryController.MODE_PRELOAD) {
|
||||
} else if (importMode === WorkspaceFactoryController.MODE_PRELOAD) {
|
||||
// Switch mode.
|
||||
controller.setMode(WorkspaceFactoryController.MODE_PRELOAD);
|
||||
|
||||
@@ -772,7 +772,7 @@ WorkspaceFactoryController.prototype.importToolboxFromTree_ = function(tree) {
|
||||
this.model.clearToolboxList();
|
||||
this.view.clearToolboxTabs();
|
||||
|
||||
if (tree.getElementsByTagName('category').length == 0) {
|
||||
if (tree.getElementsByTagName('category').length === 0) {
|
||||
// No categories present.
|
||||
// Load all the blocks into a single category evenly spaced.
|
||||
Blockly.Xml.domToWorkspace(tree, this.toolboxWorkspace);
|
||||
@@ -788,7 +788,7 @@ WorkspaceFactoryController.prototype.importToolboxFromTree_ = function(tree) {
|
||||
// Categories/separators present.
|
||||
for (var i = 0, item; item = tree.children[i]; i++) {
|
||||
|
||||
if (item.tagName == 'category') {
|
||||
if (item.tagName === 'category') {
|
||||
// If the element is a category, create a new category and switch to it.
|
||||
this.createCategory(item.getAttribute('name'), false);
|
||||
var category = this.model.getElementByIndex(i);
|
||||
@@ -1016,12 +1016,12 @@ WorkspaceFactoryController.prototype.convertShadowBlocks = function() {
|
||||
*/
|
||||
WorkspaceFactoryController.prototype.setMode = function(mode) {
|
||||
// No work to change mode that's currently set.
|
||||
if (this.selectedMode == mode) {
|
||||
if (this.selectedMode === mode) {
|
||||
return;
|
||||
}
|
||||
|
||||
// No work to change mode that's currently set.
|
||||
if (this.selectedMode == mode) {
|
||||
if (this.selectedMode === mode) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1034,7 +1034,7 @@ WorkspaceFactoryController.prototype.setMode = function(mode) {
|
||||
// Update help text above workspace.
|
||||
this.view.updateHelpText(mode);
|
||||
|
||||
if (mode == WorkspaceFactoryController.MODE_TOOLBOX) {
|
||||
if (mode === WorkspaceFactoryController.MODE_TOOLBOX) {
|
||||
// Open the toolbox editing space.
|
||||
this.model.savePreloadXml
|
||||
(Blockly.Xml.workspaceToDom(this.toolboxWorkspace));
|
||||
@@ -1115,7 +1115,7 @@ WorkspaceFactoryController.prototype.readOptions_ = function() {
|
||||
} else {
|
||||
var maxBlocksValue =
|
||||
document.getElementById('option_maxBlocks_number').value;
|
||||
optionsObj['maxBlocks'] = typeof maxBlocksValue == 'string' ?
|
||||
optionsObj['maxBlocks'] = typeof maxBlocksValue === 'string' ?
|
||||
parseInt(maxBlocksValue) : maxBlocksValue;
|
||||
}
|
||||
optionsObj['trashcan'] =
|
||||
@@ -1142,10 +1142,10 @@ WorkspaceFactoryController.prototype.readOptions_ = function() {
|
||||
var grid = Object.create(null);
|
||||
var spacingValue =
|
||||
document.getElementById('gridOption_spacing_number').value;
|
||||
grid['spacing'] = typeof spacingValue == 'string' ?
|
||||
grid['spacing'] = typeof spacingValue === 'string' ?
|
||||
parseInt(spacingValue) : spacingValue;
|
||||
var lengthValue = document.getElementById('gridOption_length_number').value;
|
||||
grid['length'] = typeof lengthValue == 'string' ?
|
||||
grid['length'] = typeof lengthValue === 'string' ?
|
||||
parseInt(lengthValue) : lengthValue;
|
||||
grid['colour'] = document.getElementById('gridOption_colour_text').value;
|
||||
if (!readonly) {
|
||||
@@ -1164,19 +1164,19 @@ WorkspaceFactoryController.prototype.readOptions_ = function() {
|
||||
document.getElementById('zoomOption_wheel_checkbox').checked;
|
||||
var startScaleValue =
|
||||
document.getElementById('zoomOption_startScale_number').value;
|
||||
zoom['startScale'] = typeof startScaleValue == 'string' ?
|
||||
zoom['startScale'] = typeof startScaleValue === 'string' ?
|
||||
Number(startScaleValue) : startScaleValue;
|
||||
var maxScaleValue =
|
||||
document.getElementById('zoomOption_maxScale_number').value;
|
||||
zoom['maxScale'] = typeof maxScaleValue == 'string' ?
|
||||
zoom['maxScale'] = typeof maxScaleValue === 'string' ?
|
||||
Number(maxScaleValue) : maxScaleValue;
|
||||
var minScaleValue =
|
||||
document.getElementById('zoomOption_minScale_number').value;
|
||||
zoom['minScale'] = typeof minScaleValue == 'string' ?
|
||||
zoom['minScale'] = typeof minScaleValue === 'string' ?
|
||||
Number(minScaleValue) : minScaleValue;
|
||||
var scaleSpeedValue =
|
||||
document.getElementById('zoomOption_scaleSpeed_number').value;
|
||||
zoom['scaleSpeed'] = typeof scaleSpeedValue == 'string' ?
|
||||
zoom['scaleSpeed'] = typeof scaleSpeedValue === 'string' ?
|
||||
Number(scaleSpeedValue) : scaleSpeedValue;
|
||||
optionsObj['zoom'] = zoom;
|
||||
}
|
||||
@@ -1235,7 +1235,7 @@ WorkspaceFactoryController.prototype.importBlocks = function(file, format) {
|
||||
(Blockly.Xml.workspaceToDom(controller.toolboxWorkspace));
|
||||
|
||||
BlocklyDevTools.Analytics.onImport('BlockDefinitions' +
|
||||
(format == 'JSON' ? '.json' : '.js'));
|
||||
(format === 'JSON' ? '.json' : '.js'));
|
||||
} catch (e) {
|
||||
msg = 'Cannot read blocks from file.';
|
||||
alert(msg);
|
||||
|
||||
@@ -55,7 +55,7 @@ WorkspaceFactoryGenerator.prototype.generateToolboxXml = function() {
|
||||
this.appendHiddenWorkspaceToDom_(xmlDom);
|
||||
} else {
|
||||
// Toolbox has categories.
|
||||
// Assert that selected != null
|
||||
// Assert that selected !== null
|
||||
if (!this.model.getSelected()) {
|
||||
throw Error('Selected is null when the toolbox is empty.');
|
||||
}
|
||||
@@ -69,19 +69,19 @@ WorkspaceFactoryGenerator.prototype.generateToolboxXml = function() {
|
||||
// groups in the flyout.
|
||||
for (var i = 0; i < toolboxList.length; i++) {
|
||||
var element = toolboxList[i];
|
||||
if (element.type == ListElement.TYPE_SEPARATOR) {
|
||||
if (element.type === ListElement.TYPE_SEPARATOR) {
|
||||
// If the next element is a separator.
|
||||
var nextElement = Blockly.utils.xml.createElement('sep');
|
||||
} else if (element.type == ListElement.TYPE_CATEGORY) {
|
||||
} else if (element.type === ListElement.TYPE_CATEGORY) {
|
||||
// If the next element is a category.
|
||||
var nextElement = Blockly.utils.xml.createElement('category');
|
||||
nextElement.setAttribute('name', element.name);
|
||||
// Add a colour attribute if one exists.
|
||||
if (element.colour != null) {
|
||||
if (element.colour !== null) {
|
||||
nextElement.setAttribute('colour', element.colour);
|
||||
}
|
||||
// Add a custom attribute if one exists.
|
||||
if (element.custom != null) {
|
||||
if (element.custom !== null) {
|
||||
nextElement.setAttribute('custom', element.custom);
|
||||
}
|
||||
// Load that category to hidden workspace, setting user-generated shadow
|
||||
@@ -129,10 +129,10 @@ WorkspaceFactoryGenerator.prototype.generateInjectString = function() {
|
||||
}
|
||||
var str = '';
|
||||
for (var key in obj) {
|
||||
if (key == 'grid' || key == 'zoom') {
|
||||
if (key === 'grid' || key === 'zoom') {
|
||||
var temp = tabChar + key + ' : {\n' + addAttributes(obj[key],
|
||||
tabChar + '\t') + tabChar + '}, \n';
|
||||
} else if (typeof obj[key] == 'string') {
|
||||
} else if (typeof obj[key] === 'string') {
|
||||
var temp = tabChar + key + ' : \'' + obj[key] + '\', \n';
|
||||
} else {
|
||||
var temp = tabChar + key + ' : ' + obj[key] + ', \n';
|
||||
|
||||
@@ -61,7 +61,7 @@ WorkspaceFactoryInit.initColourPicker_ = function(controller) {
|
||||
var row = [];
|
||||
for (var i = 0; i < colours.length; i++) {
|
||||
row.push(colours[i]);
|
||||
if (row.length == maxCols) {
|
||||
if (row.length === maxCols) {
|
||||
grid.push(row);
|
||||
row = [];
|
||||
}
|
||||
@@ -235,7 +235,7 @@ WorkspaceFactoryInit.assignWorkspaceFactoryClickHandlers_ =
|
||||
function() {
|
||||
var selected = controller.model.getSelected();
|
||||
// Return if a category is not selected.
|
||||
if (selected.type != ListElement.TYPE_CATEGORY) {
|
||||
if (selected.type !== ListElement.TYPE_CATEGORY) {
|
||||
return;
|
||||
}
|
||||
document.getElementById('categoryName').value = selected.name;
|
||||
@@ -304,14 +304,14 @@ WorkspaceFactoryInit.addWorkspaceFactoryEventListeners_ = function(controller) {
|
||||
// Don't let arrow keys have any effect if not in Workspace Factory
|
||||
// editing the toolbox.
|
||||
if (!(controller.keyEventsEnabled && controller.selectedMode
|
||||
== WorkspaceFactoryController.MODE_TOOLBOX)) {
|
||||
=== WorkspaceFactoryController.MODE_TOOLBOX)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.keyCode == 38) {
|
||||
if (e.keyCode === 38) {
|
||||
// Arrow up.
|
||||
controller.moveElement(-1);
|
||||
} else if (e.keyCode == 40) {
|
||||
} else if (e.keyCode === 40) {
|
||||
// Arrow down.
|
||||
controller.moveElement(1);
|
||||
}
|
||||
@@ -334,9 +334,9 @@ WorkspaceFactoryInit.addWorkspaceFactoryEventListeners_ = function(controller) {
|
||||
// Not listening for Blockly create events because causes the user to drop
|
||||
// blocks when dragging them into workspace. Could cause problems if ever
|
||||
// load blocks into workspace directly without calling updatePreview.
|
||||
if (e.type == Blockly.Events.BLOCK_MOVE ||
|
||||
e.type == Blockly.Events.BLOCK_DELETE ||
|
||||
e.type == Blockly.Events.BLOCK_CHANGE) {
|
||||
if (e.type === Blockly.Events.BLOCK_MOVE ||
|
||||
e.type === Blockly.Events.BLOCK_DELETE ||
|
||||
e.type === Blockly.Events.BLOCK_CHANGE) {
|
||||
controller.saveStateFromWorkspace();
|
||||
controller.updatePreview();
|
||||
}
|
||||
@@ -345,8 +345,8 @@ WorkspaceFactoryInit.addWorkspaceFactoryEventListeners_ = function(controller) {
|
||||
// Only enable "Edit Block" when a block is selected and it has a
|
||||
// surrounding parent, meaning it is nested in another block (blocks that
|
||||
// are not nested in parents cannot be shadow blocks).
|
||||
if (e.type == Blockly.Events.BLOCK_MOVE ||
|
||||
e.type == Blockly.Events.SELECTED) {
|
||||
if (e.type === Blockly.Events.BLOCK_MOVE ||
|
||||
e.type === Blockly.Events.SELECTED) {
|
||||
var selected = Blockly.common.getSelected();
|
||||
|
||||
// Show shadow button if a block is selected. Show "Add Shadow" if
|
||||
@@ -361,7 +361,7 @@ WorkspaceFactoryInit.addWorkspaceFactoryEventListeners_ = function(controller) {
|
||||
WorkspaceFactoryInit.displayRemoveShadow_(false);
|
||||
}
|
||||
|
||||
if (selected != null && selected.getSurroundParent() != null &&
|
||||
if (selected !== null && selected.getSurroundParent() !== null &&
|
||||
!controller.isUserGenShadowBlock(selected.getSurroundParent().id)) {
|
||||
// Selected block is a valid shadow block or could be a valid shadow
|
||||
// block.
|
||||
@@ -378,7 +378,7 @@ WorkspaceFactoryInit.addWorkspaceFactoryEventListeners_ = function(controller) {
|
||||
} else {
|
||||
// Selected block cannot be a valid shadow block.
|
||||
|
||||
if (selected != null && isInvalidBlockPlacement(selected)) {
|
||||
if (selected !== null && isInvalidBlockPlacement(selected)) {
|
||||
// Selected block breaks shadow block rules.
|
||||
// Invalid shadow block if (1) a shadow block no longer has a valid
|
||||
// parent, or (2) a normal block is inside of a shadow block.
|
||||
@@ -403,7 +403,7 @@ WorkspaceFactoryInit.addWorkspaceFactoryEventListeners_ = function(controller) {
|
||||
// be a shadow block.
|
||||
|
||||
// Remove possible 'invalid shadow block placement' warning.
|
||||
if (selected != null && controller.isDefinedBlock(selected) &&
|
||||
if (selected !== null && controller.isDefinedBlock(selected) &&
|
||||
(!FactoryUtils.hasVariableField(selected) ||
|
||||
!controller.isUserGenShadowBlock(selected.id))) {
|
||||
selected.setWarningText(null);
|
||||
@@ -419,7 +419,7 @@ WorkspaceFactoryInit.addWorkspaceFactoryEventListeners_ = function(controller) {
|
||||
|
||||
// Convert actual shadow blocks added from the toolbox to user-generated
|
||||
// shadow blocks.
|
||||
if (e.type == Blockly.Events.BLOCK_CREATE) {
|
||||
if (e.type === Blockly.Events.BLOCK_CREATE) {
|
||||
controller.convertShadowBlocks();
|
||||
|
||||
// Let the user create a Variables or Functions category if they use
|
||||
|
||||
@@ -54,8 +54,8 @@ WorkspaceFactoryModel = function() {
|
||||
*/
|
||||
WorkspaceFactoryModel.prototype.hasCategoryByName = function(name) {
|
||||
for (var i = 0; i < this.toolboxList.length; i++) {
|
||||
if (this.toolboxList[i].type == ListElement.TYPE_CATEGORY &&
|
||||
this.toolboxList[i].name == name) {
|
||||
if (this.toolboxList[i].type === ListElement.TYPE_CATEGORY &&
|
||||
this.toolboxList[i].name === name) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -95,9 +95,9 @@ WorkspaceFactoryModel.prototype.hasElements = function() {
|
||||
*/
|
||||
WorkspaceFactoryModel.prototype.addElementToList = function(element) {
|
||||
// Update state if the copied category has a custom tag.
|
||||
this.hasVariableCategory = element.custom == 'VARIABLE' ? true :
|
||||
this.hasVariableCategory = element.custom === 'VARIABLE' ? true :
|
||||
this.hasVariableCategory;
|
||||
this.hasProcedureCategory = element.custom == 'PROCEDURE' ? true :
|
||||
this.hasProcedureCategory = element.custom === 'PROCEDURE' ? true :
|
||||
this.hasProcedureCategory;
|
||||
// Add element to toolboxList.
|
||||
this.toolboxList.push(element);
|
||||
@@ -115,9 +115,9 @@ WorkspaceFactoryModel.prototype.deleteElementFromList = function(index) {
|
||||
return; // No entry to delete.
|
||||
}
|
||||
// Check if need to update flags.
|
||||
this.hasVariableCategory = this.toolboxList[index].custom == 'VARIABLE' ?
|
||||
this.hasVariableCategory = this.toolboxList[index].custom === 'VARIABLE' ?
|
||||
false : this.hasVariableCategory;
|
||||
this.hasProcedureCategory = this.toolboxList[index].custom == 'PROCEDURE' ?
|
||||
this.hasProcedureCategory = this.toolboxList[index].custom === 'PROCEDURE' ?
|
||||
false : this.hasProcedureCategory;
|
||||
// Remove element.
|
||||
this.toolboxList.splice(index, 1);
|
||||
@@ -130,7 +130,7 @@ WorkspaceFactoryModel.prototype.deleteElementFromList = function(index) {
|
||||
* of blocks displayed.
|
||||
*/
|
||||
WorkspaceFactoryModel.prototype.createDefaultSelectedIfEmpty = function() {
|
||||
if (this.toolboxList.length == 0) {
|
||||
if (this.toolboxList.length === 0) {
|
||||
this.flyout = new ListElement(ListElement.TYPE_FLYOUT);
|
||||
this.selected = this.flyout;
|
||||
}
|
||||
@@ -158,7 +158,7 @@ WorkspaceFactoryModel.prototype.moveElementToIndex = function(element, newIndex,
|
||||
|
||||
/**
|
||||
* Returns the ID of the currently selected element. Returns null if there are
|
||||
* no categories (if selected == null).
|
||||
* no categories (if selected === null).
|
||||
* @return {string} The ID of the element currently selected.
|
||||
*/
|
||||
WorkspaceFactoryModel.prototype.getSelectedId = function() {
|
||||
@@ -167,7 +167,7 @@ WorkspaceFactoryModel.prototype.getSelectedId = function() {
|
||||
|
||||
/**
|
||||
* Returns the name of the currently selected category. Returns null if there
|
||||
* are no categories (if selected == null) or the selected element is not
|
||||
* are no categories (if selected === null) or the selected element is not
|
||||
* a category (in which case its name is null).
|
||||
* @return {string} The name of the category currently selected.
|
||||
*/
|
||||
@@ -200,7 +200,7 @@ WorkspaceFactoryModel.prototype.setSelectedById = function(id) {
|
||||
*/
|
||||
WorkspaceFactoryModel.prototype.getIndexByElementId = function(id) {
|
||||
for (var i = 0; i < this.toolboxList.length; i++) {
|
||||
if (this.toolboxList[i].id == id) {
|
||||
if (this.toolboxList[i].id === id) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@@ -215,7 +215,7 @@ WorkspaceFactoryModel.prototype.getIndexByElementId = function(id) {
|
||||
*/
|
||||
WorkspaceFactoryModel.prototype.getElementById = function(id) {
|
||||
for (var i = 0; i < this.toolboxList.length; i++) {
|
||||
if (this.toolboxList[i].id == id) {
|
||||
if (this.toolboxList[i].id === id) {
|
||||
return this.toolboxList[i];
|
||||
}
|
||||
}
|
||||
@@ -259,7 +259,7 @@ WorkspaceFactoryModel.prototype.getToolboxList = function() {
|
||||
*/
|
||||
WorkspaceFactoryModel.prototype.getCategoryIdByName = function(name) {
|
||||
for (var i = 0; i < this.toolboxList.length; i++) {
|
||||
if (this.toolboxList[i].name == name) {
|
||||
if (this.toolboxList[i].name === name) {
|
||||
return this.toolboxList[i].id;
|
||||
}
|
||||
}
|
||||
@@ -293,7 +293,7 @@ WorkspaceFactoryModel.prototype.addShadowBlock = function(blockId) {
|
||||
*/
|
||||
WorkspaceFactoryModel.prototype.removeShadowBlock = function(blockId) {
|
||||
for (var i = 0; i < this.shadowBlocks.length; i++) {
|
||||
if (this.shadowBlocks[i] == blockId) {
|
||||
if (this.shadowBlocks[i] === blockId) {
|
||||
this.shadowBlocks.splice(i, 1);
|
||||
return;
|
||||
}
|
||||
@@ -308,7 +308,7 @@ WorkspaceFactoryModel.prototype.removeShadowBlock = function(blockId) {
|
||||
*/
|
||||
WorkspaceFactoryModel.prototype.isShadowBlock = function(blockId) {
|
||||
for (var i = 0; i < this.shadowBlocks.length; i++) {
|
||||
if (this.shadowBlocks[i] == blockId) {
|
||||
if (this.shadowBlocks[i] === blockId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -341,14 +341,14 @@ WorkspaceFactoryModel.prototype.getShadowBlocksInWorkspace =
|
||||
*/
|
||||
WorkspaceFactoryModel.prototype.addCustomTag = function(category, tag) {
|
||||
// Only update list elements that are categories.
|
||||
if (category.type != ListElement.TYPE_CATEGORY) {
|
||||
if (category.type !== ListElement.TYPE_CATEGORY) {
|
||||
return;
|
||||
}
|
||||
// Only update the tag to be 'VARIABLE' or 'PROCEDURE'.
|
||||
if (tag == 'VARIABLE') {
|
||||
if (tag === 'VARIABLE') {
|
||||
this.hasVariableCategory = true;
|
||||
category.custom = 'VARIABLE';
|
||||
} else if (tag == 'PROCEDURE') {
|
||||
} else if (tag === 'PROCEDURE') {
|
||||
this.hasProcedureCategory = true;
|
||||
category.custom = 'PROCEDURE';
|
||||
}
|
||||
@@ -397,7 +397,7 @@ WorkspaceFactoryModel.prototype.getAllUsedBlockTypes = function() {
|
||||
// Add block types if not already in list.
|
||||
for (var i = 0; i < blocks.length; i++) {
|
||||
var type = blocks[i].getAttribute('type');
|
||||
if (list.indexOf(type) == -1) {
|
||||
if (list.indexOf(type) === -1) {
|
||||
list.push(type);
|
||||
}
|
||||
}
|
||||
@@ -410,7 +410,7 @@ WorkspaceFactoryModel.prototype.getAllUsedBlockTypes = function() {
|
||||
// If has categories, add block types for each category.
|
||||
|
||||
for (var i = 0, category; category = this.toolboxList[i]; i++) {
|
||||
if (category.type == ListElement.TYPE_CATEGORY) {
|
||||
if (category.type === ListElement.TYPE_CATEGORY) {
|
||||
pushBlockTypesToList(category.xml, blockTypeList);
|
||||
}
|
||||
}
|
||||
@@ -446,9 +446,9 @@ WorkspaceFactoryModel.prototype.updateLibBlockTypes = function(blockTypes) {
|
||||
*/
|
||||
WorkspaceFactoryModel.prototype.isDefinedBlockType = function(blockType) {
|
||||
var isStandardBlock =
|
||||
StandardCategories.coreBlockTypes.indexOf(blockType) != -1;
|
||||
var isLibBlock = this.libBlockTypes.indexOf(blockType) != -1;
|
||||
var isImportedBlock = this.importedBlockTypes.indexOf(blockType) != -1;
|
||||
StandardCategories.coreBlockTypes.indexOf(blockType) !== -1;
|
||||
var isLibBlock = this.libBlockTypes.indexOf(blockType) !== -1;
|
||||
var isImportedBlock = this.importedBlockTypes.indexOf(blockType) !== -1;
|
||||
return (isStandardBlock || isLibBlock || isImportedBlock);
|
||||
};
|
||||
|
||||
@@ -498,8 +498,8 @@ ListElement.TYPE_FLYOUT = 'flyout';
|
||||
*/
|
||||
ListElement.prototype.saveFromWorkspace = function(workspace) {
|
||||
// Only save XML for categories and flyouts.
|
||||
if (this.type == ListElement.TYPE_FLYOUT ||
|
||||
this.type == ListElement.TYPE_CATEGORY) {
|
||||
if (this.type === ListElement.TYPE_FLYOUT ||
|
||||
this.type === ListElement.TYPE_CATEGORY) {
|
||||
this.xml = Blockly.Xml.workspaceToDom(workspace);
|
||||
}
|
||||
};
|
||||
@@ -512,7 +512,7 @@ ListElement.prototype.saveFromWorkspace = function(workspace) {
|
||||
*/
|
||||
ListElement.prototype.changeName = function(name) {
|
||||
// Only update list elements that are categories.
|
||||
if (this.type != ListElement.TYPE_CATEGORY) {
|
||||
if (this.type !== ListElement.TYPE_CATEGORY) {
|
||||
return;
|
||||
}
|
||||
this.name = name;
|
||||
@@ -525,7 +525,7 @@ ListElement.prototype.changeName = function(name) {
|
||||
* or null if none.
|
||||
*/
|
||||
ListElement.prototype.changeColour = function(colour) {
|
||||
if (this.type != ListElement.TYPE_CATEGORY) {
|
||||
if (this.type !== ListElement.TYPE_CATEGORY) {
|
||||
return;
|
||||
}
|
||||
this.colour = colour;
|
||||
|
||||
@@ -35,7 +35,7 @@ WorkspaceFactoryView.prototype.addCategoryRow = function(name, id) {
|
||||
var count = table.rows.length;
|
||||
|
||||
// Delete help label and enable category buttons if it's the first category.
|
||||
if (count == 0) {
|
||||
if (count === 0) {
|
||||
document.getElementById('categoryHeader').textContent = 'Your categories:';
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ WorkspaceFactoryView.prototype.addEmptyCategoryMessage = function() {
|
||||
WorkspaceFactoryView.prototype.updateState = function(selectedIndex, selected) {
|
||||
// Disable/enable editing buttons as necessary.
|
||||
document.getElementById('button_editCategory').disabled = selectedIndex < 0 ||
|
||||
selected.type != ListElement.TYPE_CATEGORY;
|
||||
selected.type !== ListElement.TYPE_CATEGORY;
|
||||
document.getElementById('button_remove').disabled = selectedIndex < 0;
|
||||
document.getElementById('button_up').disabled = selectedIndex <= 0;
|
||||
var table = document.getElementById('categoryTable');
|
||||
@@ -135,7 +135,7 @@ WorkspaceFactoryView.prototype.setCategoryTabSelection =
|
||||
* @param {!Function} func Function to be executed on click.
|
||||
*/
|
||||
WorkspaceFactoryView.prototype.bindClick = function(el, func) {
|
||||
if (typeof el == 'string') {
|
||||
if (typeof el === 'string') {
|
||||
el = document.getElementById(el);
|
||||
}
|
||||
el.addEventListener('click', func, true);
|
||||
@@ -233,7 +233,7 @@ WorkspaceFactoryView.prototype.addSeparatorTab = function(id) {
|
||||
var table = document.getElementById('categoryTable');
|
||||
var count = table.rows.length;
|
||||
|
||||
if (count == 0) {
|
||||
if (count === 0) {
|
||||
document.getElementById('categoryHeader').textContent = 'Your categories:';
|
||||
}
|
||||
// Create separator.
|
||||
@@ -271,9 +271,9 @@ WorkspaceFactoryView.prototype.disableWorkspace = function(disable) {
|
||||
* @return {boolean} True if the workspace should be disabled, false otherwise.
|
||||
*/
|
||||
WorkspaceFactoryView.prototype.shouldDisableWorkspace = function(category) {
|
||||
return category != null && category.type != ListElement.TYPE_FLYOUT &&
|
||||
(category.type == ListElement.TYPE_SEPARATOR ||
|
||||
category.custom == 'VARIABLE' || category.custom == 'PROCEDURE');
|
||||
return category !== null && category.type !== ListElement.TYPE_FLYOUT &&
|
||||
(category.type === ListElement.TYPE_SEPARATOR ||
|
||||
category.custom === 'VARIABLE' || category.custom === 'PROCEDURE');
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -340,13 +340,13 @@ WorkspaceFactoryView.prototype.unmarkShadowBlock = function(block) {
|
||||
* (WorkspaceFactoryController.MODE_TOOLBOX or WorkspaceFactoryController.MODE_PRELOAD).
|
||||
*/
|
||||
WorkspaceFactoryView.prototype.setModeSelection = function(mode) {
|
||||
document.getElementById('tab_preload').className = mode ==
|
||||
document.getElementById('tab_preload').className = mode ===
|
||||
WorkspaceFactoryController.MODE_PRELOAD ? 'tabon' : 'taboff';
|
||||
document.getElementById('preload_div').style.display = mode ==
|
||||
document.getElementById('preload_div').style.display = mode ===
|
||||
WorkspaceFactoryController.MODE_PRELOAD ? 'block' : 'none';
|
||||
document.getElementById('tab_toolbox').className = mode ==
|
||||
document.getElementById('tab_toolbox').className = mode ===
|
||||
WorkspaceFactoryController.MODE_TOOLBOX ? 'tabon' : 'taboff';
|
||||
document.getElementById('toolbox_div').style.display = mode ==
|
||||
document.getElementById('toolbox_div').style.display = mode ===
|
||||
WorkspaceFactoryController.MODE_TOOLBOX ? 'block' : 'none';
|
||||
};
|
||||
|
||||
@@ -356,7 +356,7 @@ WorkspaceFactoryView.prototype.setModeSelection = function(mode) {
|
||||
* WorkspaceFactoryController.MODE_PRELOAD).
|
||||
*/
|
||||
WorkspaceFactoryView.prototype.updateHelpText = function(mode) {
|
||||
if (mode == WorkspaceFactoryController.MODE_TOOLBOX) {
|
||||
if (mode === WorkspaceFactoryController.MODE_TOOLBOX) {
|
||||
var helpText = 'Drag blocks into the workspace to configure the toolbox ' +
|
||||
'in your custom workspace.';
|
||||
} else {
|
||||
|
||||
@@ -87,21 +87,21 @@ Blockly.Blocks['factory_base'] = {
|
||||
var outputExists = this.getInput('OUTPUTTYPE');
|
||||
var topExists = this.getInput('TOPTYPE');
|
||||
var bottomExists = this.getInput('BOTTOMTYPE');
|
||||
if (option == 'LEFT') {
|
||||
if (option === 'LEFT') {
|
||||
if (!outputExists) {
|
||||
this.addTypeInput_('OUTPUTTYPE', 'output type');
|
||||
}
|
||||
} else if (outputExists) {
|
||||
this.removeInput('OUTPUTTYPE');
|
||||
}
|
||||
if (option == 'TOP' || option == 'BOTH') {
|
||||
if (option === 'TOP' || option === 'BOTH') {
|
||||
if (!topExists) {
|
||||
this.addTypeInput_('TOPTYPE', 'top type');
|
||||
}
|
||||
} else if (topExists) {
|
||||
this.removeInput('TOPTYPE');
|
||||
}
|
||||
if (option == 'BOTTOM' || option == 'BOTH') {
|
||||
if (option === 'BOTTOM' || option === 'BOTH') {
|
||||
if (!bottomExists) {
|
||||
this.addTypeInput_('BOTTOMTYPE', 'bottom type');
|
||||
}
|
||||
@@ -530,7 +530,7 @@ Blockly.Blocks['type_group'] = {
|
||||
for (var i = 0; i < this.typeCount_; i++) {
|
||||
var input = this.appendValueInput('TYPE' + i)
|
||||
.setCheck('Type');
|
||||
if (i == 0) {
|
||||
if (i === 0) {
|
||||
input.appendField('any of');
|
||||
}
|
||||
}
|
||||
@@ -561,7 +561,7 @@ Blockly.Blocks['type_group'] = {
|
||||
// Disconnect any children that don't belong.
|
||||
for (var i = 0; i < this.typeCount_; i++) {
|
||||
var connection = this.getInput('TYPE' + i).connection.targetConnection;
|
||||
if (connection && connections.indexOf(connection) == -1) {
|
||||
if (connection && connections.indexOf(connection) === -1) {
|
||||
connection.disconnect();
|
||||
}
|
||||
}
|
||||
@@ -590,7 +590,7 @@ Blockly.Blocks['type_group'] = {
|
||||
for (var i = 0; i < this.typeCount_; i++) {
|
||||
if (!this.getInput('TYPE' + i)) {
|
||||
var input = this.appendValueInput('TYPE' + i);
|
||||
if (i == 0) {
|
||||
if (i === 0) {
|
||||
input.appendField('any of');
|
||||
}
|
||||
}
|
||||
@@ -760,7 +760,7 @@ function fieldNameCheck(referenceBlock) {
|
||||
for (var i = 0, block; block = blocks[i]; i++) {
|
||||
var otherName = block.getFieldValue('FIELDNAME');
|
||||
if (!block.disabled && !block.getInheritedDisabled() &&
|
||||
otherName && otherName.toLowerCase() == name) {
|
||||
otherName && otherName.toLowerCase() === name) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
@@ -785,7 +785,7 @@ function inputNameCheck(referenceBlock) {
|
||||
for (var i = 0, block; block = blocks[i]; i++) {
|
||||
var otherName = block.getFieldValue('INPUTNAME');
|
||||
if (!block.disabled && !block.getInheritedDisabled() &&
|
||||
otherName && otherName.toLowerCase() == name) {
|
||||
otherName && otherName.toLowerCase() === name) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ function formatChange() {
|
||||
var mask = document.getElementById('blocklyMask');
|
||||
var languagePre = document.getElementById('languagePre');
|
||||
var languageTA = document.getElementById('languageTA');
|
||||
if (document.getElementById('format').value == 'Manual') {
|
||||
if (document.getElementById('format').value === 'Manual') {
|
||||
Blockly.common.getMainWorkspace().hideChaff();
|
||||
mask.style.display = 'block';
|
||||
languagePre.style.display = 'none';
|
||||
@@ -97,7 +97,7 @@ function formatJson_(blockType, rootBlock) {
|
||||
if (!contentsBlock.disabled && !contentsBlock.getInheritedDisabled()) {
|
||||
var fields = getFieldsJson_(contentsBlock.getInputTargetBlock('FIELDS'));
|
||||
for (var i = 0; i < fields.length; i++) {
|
||||
if (typeof fields[i] == 'string') {
|
||||
if (typeof fields[i] === 'string') {
|
||||
message.push(fields[i].replace(/%/g, '%%'));
|
||||
} else {
|
||||
args.push(fields[i]);
|
||||
@@ -107,7 +107,7 @@ function formatJson_(blockType, rootBlock) {
|
||||
|
||||
var input = {type: contentsBlock.type};
|
||||
// Dummy inputs don't have names. Other inputs do.
|
||||
if (contentsBlock.type != 'input_dummy') {
|
||||
if (contentsBlock.type !== 'input_dummy') {
|
||||
input.name = contentsBlock.getFieldValue('INPUTNAME');
|
||||
}
|
||||
var check = JSON.parse(getOptTypesFrom(contentsBlock, 'TYPE') || 'null');
|
||||
@@ -115,7 +115,7 @@ function formatJson_(blockType, rootBlock) {
|
||||
input.check = check;
|
||||
}
|
||||
var align = contentsBlock.getFieldValue('ALIGN');
|
||||
if (align != 'LEFT') {
|
||||
if (align !== 'LEFT') {
|
||||
input.align = align;
|
||||
}
|
||||
args.push(input);
|
||||
@@ -126,11 +126,11 @@ function formatJson_(blockType, rootBlock) {
|
||||
contentsBlock.nextConnection.targetBlock();
|
||||
}
|
||||
// Remove last input if dummy and not empty.
|
||||
if (lastInput && lastInput.type == 'input_dummy') {
|
||||
if (lastInput && lastInput.type === 'input_dummy') {
|
||||
var fields = lastInput.getInputTargetBlock('FIELDS');
|
||||
if (fields && getFieldsJson_(fields).join('').trim() != '') {
|
||||
if (fields && getFieldsJson_(fields).join('').trim() !== '') {
|
||||
var align = lastInput.getFieldValue('ALIGN');
|
||||
if (align != 'LEFT') {
|
||||
if (align !== 'LEFT') {
|
||||
JS.lastDummyAlign0 = align;
|
||||
}
|
||||
args.pop();
|
||||
@@ -142,9 +142,9 @@ function formatJson_(blockType, rootBlock) {
|
||||
JS.args0 = args;
|
||||
}
|
||||
// Generate inline/external switch.
|
||||
if (rootBlock.getFieldValue('INLINE') == 'EXT') {
|
||||
if (rootBlock.getFieldValue('INLINE') === 'EXT') {
|
||||
JS.inputsInline = false;
|
||||
} else if (rootBlock.getFieldValue('INLINE') == 'INT') {
|
||||
} else if (rootBlock.getFieldValue('INLINE') === 'INT') {
|
||||
JS.inputsInline = true;
|
||||
}
|
||||
// Generate output, or next/previous connections.
|
||||
@@ -199,7 +199,7 @@ function formatJavaScript_(blockType, rootBlock) {
|
||||
if (!contentsBlock.disabled && !contentsBlock.getInheritedDisabled()) {
|
||||
var name = '';
|
||||
// Dummy inputs don't have names. Other inputs do.
|
||||
if (contentsBlock.type != 'input_dummy') {
|
||||
if (contentsBlock.type !== 'input_dummy') {
|
||||
name = escapeString(contentsBlock.getFieldValue('INPUTNAME'));
|
||||
}
|
||||
code.push(' this.' + TYPES[contentsBlock.type] + '(' + name + ')');
|
||||
@@ -208,7 +208,7 @@ function formatJavaScript_(blockType, rootBlock) {
|
||||
code.push(' .setCheck(' + check + ')');
|
||||
}
|
||||
var align = contentsBlock.getFieldValue('ALIGN');
|
||||
if (align != 'LEFT') {
|
||||
if (align !== 'LEFT') {
|
||||
code.push(' .setAlign(Blockly.ALIGN_' + align + ')');
|
||||
}
|
||||
var fields = getFieldsJs_(contentsBlock.getInputTargetBlock('FIELDS'));
|
||||
@@ -222,9 +222,9 @@ function formatJavaScript_(blockType, rootBlock) {
|
||||
contentsBlock.nextConnection.targetBlock();
|
||||
}
|
||||
// Generate inline/external switch.
|
||||
if (rootBlock.getFieldValue('INLINE') == 'EXT') {
|
||||
if (rootBlock.getFieldValue('INLINE') === 'EXT') {
|
||||
code.push(' this.setInputsInline(false);');
|
||||
} else if (rootBlock.getFieldValue('INLINE') == 'INT') {
|
||||
} else if (rootBlock.getFieldValue('INLINE') === 'INT') {
|
||||
code.push(' this.setInputsInline(true);');
|
||||
}
|
||||
// Generate output, or next/previous connections.
|
||||
@@ -305,11 +305,11 @@ function getFieldsJs_(block) {
|
||||
Number(block.getFieldValue('PRECISION'))
|
||||
];
|
||||
// Remove any trailing arguments that aren't needed.
|
||||
if (args[3] == 0) {
|
||||
if (args[3] === 0) {
|
||||
args.pop();
|
||||
if (args[2] == Infinity) {
|
||||
if (args[2] === Infinity) {
|
||||
args.pop();
|
||||
if (args[1] == -Infinity) {
|
||||
if (args[1] === -Infinity) {
|
||||
args.pop();
|
||||
}
|
||||
}
|
||||
@@ -424,7 +424,7 @@ function getFieldsJson_(block) {
|
||||
fields.push({
|
||||
type: block.type,
|
||||
name: block.getFieldValue('FIELDNAME'),
|
||||
checked: block.getFieldValue('CHECKED') == 'TRUE'
|
||||
checked: block.getFieldValue('CHECKED') === 'TRUE'
|
||||
});
|
||||
break;
|
||||
case 'field_colour':
|
||||
@@ -489,11 +489,11 @@ function escapeString(string) {
|
||||
*/
|
||||
function getOptTypesFrom(block, name) {
|
||||
var types = getTypesFrom_(block, name);
|
||||
if (types.length == 0) {
|
||||
if (types.length === 0) {
|
||||
return undefined;
|
||||
} else if (types.indexOf('null') != -1) {
|
||||
} else if (types.indexOf('null') !== -1) {
|
||||
return 'null';
|
||||
} else if (types.length == 1) {
|
||||
} else if (types.length === 1) {
|
||||
return types[0];
|
||||
} else {
|
||||
return '[' + types.join(', ') + ']';
|
||||
@@ -512,9 +512,9 @@ function getTypesFrom_(block, name) {
|
||||
var types;
|
||||
if (!typeBlock || typeBlock.disabled) {
|
||||
types = [];
|
||||
} else if (typeBlock.type == 'type_other') {
|
||||
} else if (typeBlock.type === 'type_other') {
|
||||
types = [escapeString(typeBlock.getFieldValue('TYPE'))];
|
||||
} else if (typeBlock.type == 'type_group') {
|
||||
} else if (typeBlock.type === 'type_group') {
|
||||
types = [];
|
||||
for (var i = 0; i < typeBlock.typeCount_; i++) {
|
||||
types = types.concat(getTypesFrom_(typeBlock, 'TYPE' + i));
|
||||
@@ -569,7 +569,7 @@ function updateGenerator(block) {
|
||||
" = block.getFieldValue('" + name + "');");
|
||||
} else if (field instanceof Blockly.FieldCheckbox) {
|
||||
code.push(makeVar('checkbox', name) +
|
||||
" = block.getFieldValue('" + name + "') == 'TRUE';");
|
||||
" = block.getFieldValue('" + name + "') === 'TRUE';");
|
||||
} else if (field instanceof Blockly.FieldDropdown) {
|
||||
code.push(makeVar('dropdown', name) +
|
||||
" = block.getFieldValue('" + name + "');");
|
||||
@@ -583,11 +583,11 @@ function updateGenerator(block) {
|
||||
}
|
||||
var name = input.name;
|
||||
if (name) {
|
||||
if (input.type == Blockly.INPUT_VALUE) {
|
||||
if (input.type === Blockly.INPUT_VALUE) {
|
||||
code.push(makeVar('value', name) +
|
||||
" = Blockly." + language + ".valueToCode(block, '" + name +
|
||||
"', Blockly." + language + ".ORDER_ATOMIC);");
|
||||
} else if (input.type == Blockly.NEXT_STATEMENT) {
|
||||
} else if (input.type === Blockly.NEXT_STATEMENT) {
|
||||
code.push(makeVar('statements', name) +
|
||||
" = Blockly." + language + ".statementToCode(block, '" +
|
||||
name + "');");
|
||||
@@ -626,11 +626,11 @@ var oldDir = null;
|
||||
function updatePreview() {
|
||||
// Toggle between LTR/RTL if needed (also used in first display).
|
||||
var newDir = document.getElementById('direction').value;
|
||||
if (oldDir != newDir) {
|
||||
if (oldDir !== newDir) {
|
||||
if (previewWorkspace) {
|
||||
previewWorkspace.dispose();
|
||||
}
|
||||
var rtl = newDir == 'rtl';
|
||||
var rtl = newDir === 'rtl';
|
||||
previewWorkspace = Blockly.inject('preview',
|
||||
{rtl: rtl,
|
||||
media: '../../media/',
|
||||
@@ -641,7 +641,7 @@ function updatePreview() {
|
||||
|
||||
// Fetch the code and determine its format (JSON or JavaScript).
|
||||
var format = document.getElementById('format').value;
|
||||
if (format == 'Manual') {
|
||||
if (format === 'Manual') {
|
||||
var code = document.getElementById('languageTA').value;
|
||||
// If the code is JSON, it will parse, otherwise treat as JS.
|
||||
try {
|
||||
@@ -668,14 +668,14 @@ function updatePreview() {
|
||||
Blockly.Blocks[prop] = backupBlocks[prop];
|
||||
}
|
||||
|
||||
if (format == 'JSON') {
|
||||
if (format === 'JSON') {
|
||||
var json = JSON.parse(code);
|
||||
Blockly.Blocks[json.type || UNNAMED] = {
|
||||
init: function() {
|
||||
this.jsonInit(json);
|
||||
}
|
||||
};
|
||||
} else if (format == 'JavaScript') {
|
||||
} else if (format === 'JavaScript') {
|
||||
eval(code);
|
||||
} else {
|
||||
throw 'Unknown format: ' + format;
|
||||
@@ -684,8 +684,8 @@ function updatePreview() {
|
||||
// Look for a block on Blockly.Blocks that does not match the backup.
|
||||
var blockType = null;
|
||||
for (var type in Blockly.Blocks) {
|
||||
if (typeof Blockly.Blocks[type].init == 'function' &&
|
||||
Blockly.Blocks[type] != backupBlocks[type]) {
|
||||
if (typeof Blockly.Blocks[type].init === 'function' &&
|
||||
Blockly.Blocks[type] !== backupBlocks[type]) {
|
||||
blockType = type;
|
||||
break;
|
||||
}
|
||||
@@ -730,7 +730,7 @@ function injectCode(code, id) {
|
||||
function getRootBlock() {
|
||||
var blocks = mainWorkspace.getTopBlocks(false);
|
||||
for (var i = 0, block; block = blocks[i]; i++) {
|
||||
if (block.type == 'factory_base') {
|
||||
if (block.type === 'factory_base') {
|
||||
return block;
|
||||
}
|
||||
}
|
||||
@@ -742,7 +742,7 @@ function getRootBlock() {
|
||||
*/
|
||||
function disableEnableLink() {
|
||||
var linkButton = document.getElementById('linkButton');
|
||||
linkButton.disabled = document.getElementById('format').value == 'Manual';
|
||||
linkButton.disabled = document.getElementById('format').value === 'Manual';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -107,7 +107,7 @@ Code.getLang = function() {
|
||||
* @return {boolean} True if RTL, false if LTR.
|
||||
*/
|
||||
Code.isRtl = function() {
|
||||
return Code.LANGUAGE_RTL.indexOf(Code.LANG) != -1;
|
||||
return Code.LANGUAGE_RTL.indexOf(Code.LANG) !== -1;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -185,7 +185,7 @@ Code.changeCodingLanguage = function() {
|
||||
* @param {!Function} func Event handler to bind.
|
||||
*/
|
||||
Code.bindClick = function(el, func) {
|
||||
if (typeof el == 'string') {
|
||||
if (typeof el === 'string') {
|
||||
el = document.getElementById(el);
|
||||
}
|
||||
el.addEventListener('click', func, true);
|
||||
@@ -322,7 +322,7 @@ Code.tabClick = function(clickedName) {
|
||||
Code.renderContent();
|
||||
// The code menu tab is on if the blocks tab is off.
|
||||
var codeMenuTab = document.getElementById('tab_code');
|
||||
if (clickedName == 'blocks') {
|
||||
if (clickedName === 'blocks') {
|
||||
Code.workspace.setVisible(true);
|
||||
codeMenuTab.className = 'taboff';
|
||||
} else {
|
||||
@@ -331,7 +331,7 @@ Code.tabClick = function(clickedName) {
|
||||
// Sync the menu's value with the clicked tab value if needed.
|
||||
var codeMenu = document.getElementById('code_menu');
|
||||
for (var i = 0; i < codeMenu.options.length; i++) {
|
||||
if (codeMenu.options[i].value == clickedName) {
|
||||
if (codeMenu.options[i].value === clickedName) {
|
||||
codeMenu.selectedIndex = i;
|
||||
break;
|
||||
}
|
||||
@@ -345,29 +345,29 @@ Code.tabClick = function(clickedName) {
|
||||
Code.renderContent = function() {
|
||||
var content = document.getElementById('content_' + Code.selected);
|
||||
// Initialize the pane.
|
||||
if (content.id == 'content_xml') {
|
||||
if (content.id === 'content_xml') {
|
||||
var xmlTextarea = document.getElementById('content_xml');
|
||||
var xmlDom = Blockly.Xml.workspaceToDom(Code.workspace);
|
||||
var xmlText = Blockly.Xml.domToPrettyText(xmlDom);
|
||||
xmlTextarea.value = xmlText;
|
||||
xmlTextarea.focus();
|
||||
} else if (content.id == 'content_json') {
|
||||
} else if (content.id === 'content_json') {
|
||||
var jsonTextarea = document.getElementById('content_json');
|
||||
jsonTextarea.value = JSON.stringify(
|
||||
Blockly.serialization.workspaces.save(Code.workspace), null, 2);
|
||||
jsonTextarea.focus();
|
||||
} else if (content.id == 'content_javascript') {
|
||||
} else if (content.id === 'content_javascript') {
|
||||
Code.attemptCodeGeneration(Blockly.JavaScript);
|
||||
} else if (content.id == 'content_python') {
|
||||
} else if (content.id === 'content_python') {
|
||||
Code.attemptCodeGeneration(Blockly.Python);
|
||||
} else if (content.id == 'content_php') {
|
||||
} else if (content.id === 'content_php') {
|
||||
Code.attemptCodeGeneration(Blockly.PHP);
|
||||
} else if (content.id == 'content_dart') {
|
||||
} else if (content.id === 'content_dart') {
|
||||
Code.attemptCodeGeneration(Blockly.Dart);
|
||||
} else if (content.id == 'content_lua') {
|
||||
} else if (content.id === 'content_lua') {
|
||||
Code.attemptCodeGeneration(Blockly.Lua);
|
||||
}
|
||||
if (typeof PR == 'object') {
|
||||
if (typeof PR === 'object') {
|
||||
PR.prettyPrint();
|
||||
}
|
||||
};
|
||||
@@ -397,13 +397,13 @@ Code.checkAllGeneratorFunctionsDefined = function(generator) {
|
||||
for (var i = 0; i < blocks.length; i++) {
|
||||
var blockType = blocks[i].type;
|
||||
if (!generator[blockType]) {
|
||||
if (missingBlockGenerators.indexOf(blockType) == -1) {
|
||||
if (missingBlockGenerators.indexOf(blockType) === -1) {
|
||||
missingBlockGenerators.push(blockType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var valid = missingBlockGenerators.length == 0;
|
||||
var valid = missingBlockGenerators.length === 0;
|
||||
if (!valid) {
|
||||
var msg = 'The generator code for the following blocks not specified for ' +
|
||||
generator.name_ + ':\n - ' + missingBlockGenerators.join('\n - ');
|
||||
@@ -451,7 +451,7 @@ Code.init = function() {
|
||||
// TODO: Clean up the message files so this is done explicitly instead of
|
||||
// through this for-loop.
|
||||
for (var messageKey in MSG) {
|
||||
if (messageKey.indexOf('cat') == 0) {
|
||||
if (messageKey.indexOf('cat') === 0) {
|
||||
Blockly.Msg[messageKey.toUpperCase()] = MSG[messageKey];
|
||||
}
|
||||
}
|
||||
@@ -553,7 +553,7 @@ Code.initLanguage = function() {
|
||||
var tuple = languages[i];
|
||||
var lang = tuple[tuple.length - 1];
|
||||
var option = new Option(tuple[0], lang);
|
||||
if (lang == Code.LANG) {
|
||||
if (lang === Code.LANG) {
|
||||
option.selected = true;
|
||||
}
|
||||
languageMenu.options.add(option);
|
||||
@@ -585,7 +585,7 @@ Code.initLanguage = function() {
|
||||
*/
|
||||
Code.runJS = function(event) {
|
||||
// Prevent code from being executed twice on touchscreens.
|
||||
if (event.type == 'touchend') {
|
||||
if (event.type === 'touchend') {
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
|
||||
@@ -133,11 +133,11 @@ CustomDialog.show = function(title, message, options) {
|
||||
dialogInput.focus();
|
||||
|
||||
dialogInput.onkeyup = function(event) {
|
||||
if (event.keyCode == 13) {
|
||||
if (event.keyCode === 13) {
|
||||
// Process as OK when user hits enter.
|
||||
onOkay();
|
||||
return false;
|
||||
} else if (event.keyCode == 27) {
|
||||
} else if (event.keyCode === 27) {
|
||||
// Process as cancel when user hits esc.
|
||||
onCancel();
|
||||
return false;
|
||||
|
||||
@@ -42,12 +42,12 @@ Blockly.Blocks['turtle_nullifier'] = {
|
||||
pattern: newValue.pattern,
|
||||
hat: newValue.hat,
|
||||
};
|
||||
if ((newValue.turtleName == 'Leonardo' && newValue.hat == 'Mask') ||
|
||||
(newValue.turtleName == 'Yertle' && newValue.hat == 'Crown') ||
|
||||
(newValue.turtleName == 'Franklin') && newValue.hat == 'Propeller') {
|
||||
if ((newValue.turtleName === 'Leonardo' && newValue.hat === 'Mask') ||
|
||||
(newValue.turtleName === 'Yertle' && newValue.hat === 'Crown') ||
|
||||
(newValue.turtleName === 'Franklin') && newValue.hat === 'Propeller') {
|
||||
|
||||
var currentValue = this.getValue();
|
||||
if (newValue.turtleName != currentValue.turtleName) {
|
||||
if (newValue.turtleName !== currentValue.turtleName) {
|
||||
// Turtle name changed.
|
||||
this.cachedValidatedValue_.turtleName = null;
|
||||
} else {
|
||||
|
||||
@@ -129,7 +129,7 @@ CustomFields.FieldTurtle.prototype.updateEditable = function() {
|
||||
// Gets the text to display when the block is collapsed
|
||||
CustomFields.FieldTurtle.prototype.getText = function() {
|
||||
var text = this.value_.turtleName + ' wearing a ' + this.value_.hat;
|
||||
if (this.value_.hat == 'Stovepipe' || this.value_.hat == 'Propeller') {
|
||||
if (this.value_.hat === 'Stovepipe' || this.value_.hat === 'Propeller') {
|
||||
text += ' hat';
|
||||
}
|
||||
return text;
|
||||
@@ -143,23 +143,23 @@ CustomFields.FieldTurtle.prototype.doClassValidation_ = function(newValue) {
|
||||
// Undefined signals that we want the value to remain unchanged. This is a
|
||||
// special feature of turtle fields, but could be useful for other
|
||||
// multi-part fields.
|
||||
if (newValue.pattern == undefined) {
|
||||
if (newValue.pattern === undefined) {
|
||||
newValue.pattern = this.displayValue_ && this.displayValue_.pattern;
|
||||
// We only want to allow patterns that are part of our pattern list.
|
||||
// Anything else is invalid, so we return null.
|
||||
} else if (CustomFields.FieldTurtle.PATTERNS.indexOf(newValue.pattern) == -1) {
|
||||
} else if (CustomFields.FieldTurtle.PATTERNS.indexOf(newValue.pattern) === -1) {
|
||||
newValue.pattern = null;
|
||||
}
|
||||
|
||||
if (newValue.hat == undefined) {
|
||||
if (newValue.hat === undefined) {
|
||||
newValue.hat = this.displayValue_ && this.displayValue_.hat;
|
||||
} else if (CustomFields.FieldTurtle.HATS.indexOf(newValue.hat) == -1) {
|
||||
} else if (CustomFields.FieldTurtle.HATS.indexOf(newValue.hat) === -1) {
|
||||
newValue.hat = null;
|
||||
}
|
||||
|
||||
if (newValue.turtleName == undefined) {
|
||||
if (newValue.turtleName === undefined) {
|
||||
newValue.turtleName = this.displayValue_ && this.displayValue_.turtleName;
|
||||
} else if (CustomFields.FieldTurtle.NAMES.indexOf(newValue.turtleName) == -1) {
|
||||
} else if (CustomFields.FieldTurtle.NAMES.indexOf(newValue.turtleName) === -1) {
|
||||
newValue.turtleName = null;
|
||||
}
|
||||
|
||||
@@ -483,13 +483,13 @@ CustomFields.FieldTurtle.prototype.applyColour = function() {
|
||||
var child = this.turtleGroup_.firstChild;
|
||||
while(child) {
|
||||
// If it is a text node, continue.
|
||||
if (child.nodeType == 3) {
|
||||
if (child.nodeType === 3) {
|
||||
child = child.nextSibling;
|
||||
continue;
|
||||
}
|
||||
// Or if it is a non-turtle node, continue.
|
||||
var className = child.getAttribute('class');
|
||||
if (!className || className.indexOf('turtleBody') == -1) {
|
||||
if (!className || className.indexOf('turtleBody') === -1) {
|
||||
child = child.nextSibling;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@
|
||||
// Generate JavaScript code and run it.
|
||||
window.LoopTrap = 1000;
|
||||
Blockly.JavaScript.INFINITE_LOOP_TRAP =
|
||||
'if (--window.LoopTrap == 0) throw "Infinite loop.";\n';
|
||||
'if (--window.LoopTrap === 0) throw "Infinite loop.";\n';
|
||||
var code = Blockly.JavaScript.workspaceToCode(demoWorkspace);
|
||||
Blockly.JavaScript.INFINITE_LOOP_TRAP = null;
|
||||
try {
|
||||
|
||||
@@ -196,7 +196,7 @@
|
||||
|
||||
<script>
|
||||
// Load the Google Chart Tools Visualization API and the chart package.
|
||||
if (typeof google == 'object') {
|
||||
if (typeof google === 'object') {
|
||||
google.load('visualization', '1', {packages: ['corechart']});
|
||||
} else {
|
||||
alert('Unable to load Google\'s chart API.\n' +
|
||||
|
||||
@@ -168,7 +168,7 @@ Minimap.setDraggerHeight = function() {
|
||||
var draggerHeight = (workspaceMetrics.viewHeight / Minimap.workspace.scale) *
|
||||
Minimap.minimap.scale;
|
||||
// It's zero when first block is placed.
|
||||
if (draggerHeight == 0) {
|
||||
if (draggerHeight === 0) {
|
||||
return;
|
||||
}
|
||||
Minimap.mapDragger.setAttribute('height', draggerHeight);
|
||||
@@ -182,7 +182,7 @@ Minimap.setDraggerWidth = function() {
|
||||
var draggerWidth = (workspaceMetrics.viewWidth / Minimap.workspace.scale) *
|
||||
Minimap.minimap.scale;
|
||||
// It's zero when first block is placed.
|
||||
if (draggerWidth == 0) {
|
||||
if (draggerWidth === 0) {
|
||||
return;
|
||||
}
|
||||
Minimap.mapDragger.setAttribute('width', draggerWidth);
|
||||
|
||||
@@ -111,7 +111,7 @@ Plane.getLang = function() {
|
||||
* @return {boolean} True if RTL, false if LTR.
|
||||
*/
|
||||
Plane.isRtl = function() {
|
||||
return Plane.LANGUAGE_RTL.indexOf(Plane.LANG) != -1;
|
||||
return Plane.LANGUAGE_RTL.indexOf(Plane.LANG) !== -1;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -147,7 +147,7 @@ Plane.changeLanguage = function() {
|
||||
// This should be skipped for the index page, which has no blocks and does
|
||||
// not load Blockly.
|
||||
// MSIE 11 does not support sessionStorage on file:// URLs.
|
||||
if (typeof Blockly != 'undefined' && window.sessionStorage) {
|
||||
if (typeof Blockly !== 'undefined' && window.sessionStorage) {
|
||||
var xml = Blockly.Xml.workspaceToDom(Plane.workspace);
|
||||
var text = Blockly.Xml.domToText(xml);
|
||||
window.sessionStorage.loadOnceBlocks = text;
|
||||
@@ -315,7 +315,7 @@ Plane.initLanguage = function() {
|
||||
var tuple = languages[i];
|
||||
var lang = tuple[tuple.length - 1];
|
||||
var option = new Option(tuple[0], lang);
|
||||
if (lang == Plane.LANG) {
|
||||
if (lang === Plane.LANG) {
|
||||
option.selected = true;
|
||||
}
|
||||
languageMenu.options.add(option);
|
||||
@@ -332,7 +332,7 @@ Plane.recalculate = function() {
|
||||
var rootBlock = null;
|
||||
var blocks = Plane.workspace.getTopBlocks(false);
|
||||
for (var i = 0, block; block = blocks[i]; i++) {
|
||||
if (block.type == 'plane_set_seats') {
|
||||
if (block.type === 'plane_set_seats') {
|
||||
rootBlock = block;
|
||||
}
|
||||
}
|
||||
@@ -347,7 +347,7 @@ Plane.recalculate = function() {
|
||||
Plane.setText('seatText',
|
||||
Plane.getMsg('Plane_seats').replace(
|
||||
'%1', isNaN(seats) ? '?' : seats));
|
||||
Plane.setCorrect(isNaN(seats) ? null : (Plane.answer() == seats));
|
||||
Plane.setCorrect(isNaN(seats) ? null : (Plane.answer() === seats));
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -355,11 +355,11 @@ Plane.recalculate = function() {
|
||||
* @return {number} Number of seats.
|
||||
*/
|
||||
Plane.answer = function() {
|
||||
if (Plane.LEVEL == 1) {
|
||||
if (Plane.LEVEL === 1) {
|
||||
return Plane.rows1st * 4;
|
||||
} else if (Plane.LEVEL == 2) {
|
||||
} else if (Plane.LEVEL === 2) {
|
||||
return 2 + (Plane.rows1st * 4);
|
||||
} else if (Plane.LEVEL == 3) {
|
||||
} else if (Plane.LEVEL === 3) {
|
||||
return 2 + (Plane.rows1st * 4) + (Plane.rows2nd * 5);
|
||||
}
|
||||
throw 'Unknown level.';
|
||||
@@ -373,7 +373,7 @@ Plane.redraw = function(newRows) {
|
||||
var rows1st = Plane.rows1st;
|
||||
var rows2nd = Plane.rows2nd;
|
||||
var svg = document.getElementById('plane');
|
||||
if (newRows != rows1st) {
|
||||
if (newRows !== rows1st) {
|
||||
while (newRows < rows1st) {
|
||||
var row = document.getElementById('row1st' + rows1st);
|
||||
row.parentNode.removeChild(row);
|
||||
@@ -390,7 +390,7 @@ Plane.redraw = function(newRows) {
|
||||
svg.appendChild(row);
|
||||
}
|
||||
|
||||
if (Plane.LEVEL == 3) {
|
||||
if (Plane.LEVEL === 3) {
|
||||
newRows = Math.floor((21 - newRows) * 1.11);
|
||||
while (newRows < rows2nd) {
|
||||
var row = document.getElementById('row2nd' + rows2nd);
|
||||
|
||||
@@ -71,7 +71,7 @@ var Slider = function(x, y, width, svgParent, opt_changeFunc) {
|
||||
this.setValue(0.5);
|
||||
|
||||
// Find the root SVG object.
|
||||
while (svgParent && svgParent.nodeName.toLowerCase() != 'svg') {
|
||||
while (svgParent && svgParent.nodeName.toLowerCase() !== 'svg') {
|
||||
svgParent = svgParent.parentNode;
|
||||
}
|
||||
this.SVG_ = svgParent;
|
||||
@@ -100,8 +100,8 @@ Slider.startKnobX_ = 0;
|
||||
* @private
|
||||
*/
|
||||
Slider.prototype.knobMouseDown_ = function(e) {
|
||||
if (e.type == 'touchstart') {
|
||||
if (e.changedTouches.length != 1) {
|
||||
if (e.type === 'touchstart') {
|
||||
if (e.changedTouches.length !== 1) {
|
||||
return;
|
||||
}
|
||||
Slider.touchToMouse_(e)
|
||||
@@ -142,7 +142,7 @@ Slider.mouseOver_ = function(e) {
|
||||
var node = e.target;
|
||||
// Find the root SVG object.
|
||||
do {
|
||||
if (node == Slider.activeSlider_.SVG_) {
|
||||
if (node === Slider.activeSlider_.SVG_) {
|
||||
return;
|
||||
}
|
||||
} while (node = node.parentNode);
|
||||
@@ -159,8 +159,8 @@ Slider.knobMouseMove_ = function(e) {
|
||||
if (!thisSlider) {
|
||||
return;
|
||||
}
|
||||
if (e.type == 'touchmove') {
|
||||
if (e.changedTouches.length != 1) {
|
||||
if (e.type === 'touchmove') {
|
||||
if (e.changedTouches.length !== 1) {
|
||||
return;
|
||||
}
|
||||
Slider.touchToMouse_(e)
|
||||
@@ -177,8 +177,8 @@ Slider.knobMouseMove_ = function(e) {
|
||||
* @private
|
||||
*/
|
||||
Slider.prototype.rectMouseDown_ = function(e) {
|
||||
if (e.type == 'touchstart') {
|
||||
if (e.changedTouches.length != 1) {
|
||||
if (e.type === 'touchstart') {
|
||||
if (e.changedTouches.length !== 1) {
|
||||
return;
|
||||
}
|
||||
Slider.touchToMouse_(e)
|
||||
|
||||
Reference in New Issue
Block a user