mirror of
https://github.com/google/blockly.git
synced 2026-03-10 15:20:16 +01:00
Add mutation events.
This commit is contained in:
@@ -95,7 +95,7 @@ Blockly.Events.fireNow_ = function() {
|
||||
for (var i = 0, detail; detail = queue[i]; i++) {
|
||||
console.log(detail);
|
||||
var workspace = Blockly.Workspace.getById(detail.workspaceId);
|
||||
if (workspace.rendered) {
|
||||
if (workspace && workspace.rendered) {
|
||||
// Create a custom event in a browser-compatible way.
|
||||
if (typeof CustomEvent == 'function') {
|
||||
// W3
|
||||
@@ -124,11 +124,21 @@ Blockly.Events.filter_ = function(queueIn) {
|
||||
if (event1.type == Blockly.Events.MOVE &&
|
||||
event2.type == Blockly.Events.MOVE &&
|
||||
event1.blockId == event2.blockId) {
|
||||
// Merge move events.
|
||||
event1.newParentId = event2.newParentId;
|
||||
event1.newInputName = event2.newInputName;
|
||||
event1.newCoordinate = event2.newCoordinate;
|
||||
queue.splice(j, 1);
|
||||
j--;
|
||||
} else if (event1.type == Blockly.Events.CHANGE &&
|
||||
event2.type == Blockly.Events.CHANGE &&
|
||||
event1.blockId == event2.blockId &&
|
||||
event1.element == event2.element &&
|
||||
event1.name == event2.name) {
|
||||
// Merge change events.
|
||||
event1.newValue = event2.newValue;
|
||||
queue.splice(j, 1);
|
||||
j--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,6 +283,7 @@ Blockly.Mutator.prototype.workspaceChanged_ = function() {
|
||||
|
||||
// When the mutator's workspace changes, update the source block.
|
||||
if (this.rootBlock_.workspace == this.workspace_) {
|
||||
var oldMutation = this.block_.mutationToDom();
|
||||
// Switch off rendering while the source block is rebuilt.
|
||||
var savedRendered = this.block_.rendered;
|
||||
this.block_.rendered = false;
|
||||
@@ -292,12 +293,18 @@ Blockly.Mutator.prototype.workspaceChanged_ = function() {
|
||||
this.block_.rendered = savedRendered;
|
||||
// Mutation may have added some elements that need initalizing.
|
||||
this.block_.initSvg();
|
||||
var newMutation = this.block_.mutationToDom();
|
||||
if (Blockly.Xml.domToText(oldMutation) !=
|
||||
Blockly.Xml.domToText(newMutation)) {
|
||||
Blockly.Events.fire(new Blockly.Events.Change(
|
||||
this.block_, 'mutation', null, oldMutation, newMutation));
|
||||
goog.Timer.callOnce(
|
||||
this.block_.bumpNeighbours_, Blockly.BUMP_DELAY, this.block_);
|
||||
}
|
||||
if (this.block_.rendered) {
|
||||
this.block_.render();
|
||||
}
|
||||
this.resizeBubble_();
|
||||
goog.Timer.callOnce(
|
||||
this.block_.bumpNeighbours_, Blockly.BUMP_DELAY, this.block_);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user