Skip to content

Commit

Permalink
Support multiple Blockly instances.
Browse files Browse the repository at this point in the history
  • Loading branch information
NeilFraser committed Apr 28, 2015
1 parent 6714028 commit 17961f7
Show file tree
Hide file tree
Showing 43 changed files with 1,411 additions and 1,402 deletions.
7 changes: 4 additions & 3 deletions appengine/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,18 @@ BlocklyStorage.handleRequest_ = function() {
* @private
*/
BlocklyStorage.monitorChanges_ = function() {
var startXmlDom = Blockly.Xml.workspaceToDom(Blockly.getMainWorkspace());
var workspace = Blockly.getMainWorkspace();
var startXmlDom = Blockly.Xml.workspaceToDom(workspace);
var startXmlText = Blockly.Xml.domToText(startXmlDom);
function change() {
var xmlDom = Blockly.Xml.workspaceToDom(Blockly.getMainWorkspace());
var xmlDom = Blockly.Xml.workspaceToDom(workspace);
var xmlText = Blockly.Xml.domToText(xmlDom);
if (startXmlText != xmlText) {
window.location.hash = '';
Blockly.removeChangeListener(bindData);
}
}
var bindData = Blockly.addChangeListener(change);
var bindData = workspace.addChangeListener(change);
};

/**
Expand Down
608 changes: 304 additions & 304 deletions blockly_compressed.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions blockly_uncompressed.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion blocks/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ Blockly.Blocks['logic_compare'] = {
* @this Blockly.Block
*/
init: function() {
var OPERATORS = Blockly.RTL ? [
var OPERATORS = this.RTL ? [
['=', 'EQ'],
['\u2260', 'NEQ'],
['>', 'LT'],
Expand Down
18 changes: 9 additions & 9 deletions blocks/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,16 @@ Blockly.Blocks['text'] = {
* Create an image of an open or closed quote.
* @param {boolean} open True if open quote, false if closed.
* @return {!Blockly.FieldImage} The field image of the quote.
* @this Blockly.Block
* @private
*/
newQuote_: function(open) {
if (open == Blockly.RTL) {
var file = 'quote1.png';
if (open == this.RTL) {
var file = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAYAAACALL/6AAAA0UlEQVQY023QP0oDURSF8e8MImhlUIiCjWKhrUUK3YCIVkq6bMAF2LkCa8ENWLoNS1sLEQKprMQ/GBDks3kDM+Oc8nfPfTxuANQTYBeYAvdJLL4FnAFfwF2ST9Rz27kp5YH/kwrYp50LdaXHAU4rYNYzWAdeenx7AbgF5sAhcARsAkkyVQ+ACbAKjIGqta4+l78udXxc/LiJG+qvet0pV+q7+tHE+iJzdbGz8FhmOzVcqj/qq7rcKI7Ut1Leq70C1oCrJMMk343HB8ADMEzyVOMff72l48gwfqkAAAAASUVORK5CYII=';
} else {
var file = 'quote0.png';
var file = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAYAAACALL/6AAAAvklEQVQY022PoapCQRRF97lBVDRYhBcEQcP1BwS/QLAqr7xitZn0HzRr8Rts+htmQdCqSbQIwmMZPMIw3lVmZu0zG44UAFSBLdBVBDAFZqFo8eYKtANfBC7AE5h8ZNOHd1FrDnh4VgmDO3ADkujDHPgHfkLZ84bfaLjg/hD6RFLq9z6wBDr+rvuZB1bAEDABY76pA2mGHyWSjvqmIemc4WsCLKOp4nssIj8wD8qS/iSVJK3N7OTeJPV9n72ZbV7iDuSc2BaQBQAAAABJRU5ErkJggg==';
}
return new Blockly.FieldImage(Blockly.pathToMedia + file, 12, 12, '"');
return new Blockly.FieldImage(file, 12, 12, '"');
}
};

Expand Down Expand Up @@ -174,10 +175,8 @@ Blockly.Blocks['text_join'] = {
// Rebuild block.
if (this.itemCount_ == 0) {
this.appendDummyInput('EMPTY')
.appendField(new Blockly.FieldImage(Blockly.pathToMedia +
'quote0.png', 12, 12, '"'))
.appendField(new Blockly.FieldImage(Blockly.pathToMedia +
'quote1.png', 12, 12, '"'));
.appendField(this.newQuote_(true))
.appendField(this.newQuote_(false));
} else {
for (var i = 0; i < this.itemCount_; i++) {
var input = this.appendValueInput('ADD' + i);
Expand All @@ -186,7 +185,8 @@ Blockly.Blocks['text_join'] = {
}
}
}
}
},
newQuote_: Blockly.Blocks['text'].newQuote_
};

Blockly.Blocks['text_create_join_container'] = {
Expand Down
10 changes: 5 additions & 5 deletions blocks_compressed.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions core/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ Blockly.Block.prototype.fill = function(workspace, prototypeName) {

this.workspace = workspace;
this.isInFlyout = workspace.isFlyout;
this.RTL = workspace.RTL;

// Copy the type-specific functions and data from the prototype.
if (prototypeName) {
Expand Down Expand Up @@ -229,7 +230,7 @@ Blockly.Block.prototype.unplug = function(healStack, bump) {
}
if (bump) {
// Bump the block sideways.
var dx = Blockly.SNAP_RADIUS * (Blockly.RTL ? -1 : 1);
var dx = Blockly.SNAP_RADIUS * (this.RTL ? -1 : 1);
var dy = Blockly.SNAP_RADIUS * 2;
this.moveBy(dx, dy);
}
Expand All @@ -248,7 +249,7 @@ Blockly.Block.prototype.duplicate_ = function() {
/** @type {!Blockly.Workspace} */ (this.workspace), xmlBlock);
// Move the duplicate next to the old block.
var xy = this.getRelativeToSurfaceXY();
if (Blockly.RTL) {
if (this.RTL) {
xy.x -= Blockly.SNAP_RADIUS;
} else {
xy.x += Blockly.SNAP_RADIUS;
Expand Down Expand Up @@ -459,7 +460,8 @@ Blockly.Block.prototype.getDescendants = function() {
* @return {boolean} True if deletable.
*/
Blockly.Block.prototype.isDeletable = function() {
return this.deletable_ && !Blockly.readOnly;
return this.deletable_ &&
!(this.workspace && this.workspace.options.readOnly);
};

/**
Expand All @@ -468,15 +470,14 @@ Blockly.Block.prototype.isDeletable = function() {
*/
Blockly.Block.prototype.setDeletable = function(deletable) {
this.deletable_ = deletable;
this.svg_ && this.svg_.updateMovable();
};

/**
* Get whether this block is movable or not.
* @return {boolean} True if movable.
*/
Blockly.Block.prototype.isMovable = function() {
return this.movable_ && !Blockly.readOnly;
return this.movable_ && !(this.workspace && this.workspace.options.readOnly);
};

/**
Expand All @@ -492,7 +493,7 @@ Blockly.Block.prototype.setMovable = function(movable) {
* @return {boolean} True if editable.
*/
Blockly.Block.prototype.isEditable = function() {
return this.editable_ && !Blockly.readOnly;
return this.editable_ && !(this.workspace && this.workspace.options.readOnly);
};

/**
Expand Down Expand Up @@ -622,7 +623,7 @@ Blockly.Block.prototype.getFieldValue = function(name) {
* @deprecated December 2013
*/
Blockly.Block.prototype.getTitleValue = function(name) {
console.log('Deprecated call to getTitleValue, use getFieldValue instead.');
console.warn('Deprecated call to getTitleValue, use getFieldValue instead.');
return this.getFieldValue(name);
};

Expand All @@ -644,7 +645,7 @@ Blockly.Block.prototype.setFieldValue = function(newValue, name) {
* @deprecated December 2013
*/
Blockly.Block.prototype.setTitleValue = function(newValue, name) {
console.log('Deprecated call to setTitleValue, use setFieldValue instead.');
console.warn('Deprecated call to setTitleValue, use setFieldValue instead.');
this.setFieldValue(newValue, name);
};

Expand Down
Loading

0 comments on commit 17961f7

Please sign in to comment.