Skip to content

Commit

Permalink
Add block svg to end drag event
Browse files Browse the repository at this point in the history
  • Loading branch information
fsih committed Feb 15, 2018
1 parent 77b9634 commit 29a6322
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions core/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,21 @@ Blockly.Events.EndDrag = function(block, isOutside) {
// If drag ends outside the blocks workspace, send the block XML
if (isOutside) {
this.xml = Blockly.Xml.blockToDom(block, true /* opt_noId */);
this.svg = block.svgGroup_.parentElement.parentElement.cloneNode(true /* deep */);
const getOffset = function ( el ) {
var _x = 0;
var _y = 0;
while( el && !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop ) ) {
_x += el.offsetLeft - el.scrollLeft;
_y += el.offsetTop - el.scrollTop;
el = el.offsetParent;
}
return { top: _y, left: _x };
};
const position = getOffset(block.svgGroup_.parentElement.parentElement.parentElement);
this.svg.style.top = position.top;
this.svg.style.left = position.left;
document.body.appendChild(this.svg);
}
};
goog.inherits(Blockly.Events.EndDrag, Blockly.Events.Abstract);
Expand Down Expand Up @@ -980,6 +995,9 @@ Blockly.Events.EndDrag.prototype.toJson = function() {
if (this.xml) {
json['xml'] = this.xml;
}
if (this.svg) {
json['svg'] = this.svg;
}
return json;
};

Expand All @@ -991,6 +1009,7 @@ Blockly.Events.EndDrag.prototype.fromJson = function(json) {
Blockly.Events.EndDrag.superClass_.fromJson.call(this, json);
this.isOutside = json['isOutside'];
this.xml = json['xml'];
this.svg = json['svg'];
};

/**
Expand Down

0 comments on commit 29a6322

Please sign in to comment.