Skip to content

Commit

Permalink
Add hook for clicking on trashcan.
Browse files Browse the repository at this point in the history
  • Loading branch information
NeilFraser committed Oct 26, 2015
1 parent b10ef6d commit 11ef9f2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions core/trashcan.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ Blockly.Trashcan.prototype.createDom = function() {
this.svgLid_.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href',
this.workspace_.options.pathToMedia + Blockly.SPRITE.url);

Blockly.bindEvent_(this.svgGroup_, 'mouseup', this, this.click);
this.animateLid_();
return this.svgGroup_;
};
Expand Down Expand Up @@ -282,3 +283,15 @@ Blockly.Trashcan.prototype.animateLid_ = function() {
Blockly.Trashcan.prototype.close = function() {
this.setOpen_(false);
};

/**
* Inspect the contents of the trash.
*/
Blockly.Trashcan.prototype.click = function() {
var dx = this.workspace_.startScrollX - this.workspace_.scrollX;
var dy = this.workspace_.startScrollY - this.workspace_.scrollY;
if (Math.sqrt(dx * dx + dy * dy) > Blockly.DRAG_RADIUS) {
return;
}
console.log('TODO: Inspect trash.');
};
12 changes: 12 additions & 0 deletions core/workspace_svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ Blockly.WorkspaceSvg.prototype.scrollX = 0;
*/
Blockly.WorkspaceSvg.prototype.scrollY = 0;

/**
* Horizontal scroll value when scrolling started.
* @type {number}
*/
Blockly.WorkspaceSvg.prototype.startScrollX = 0;

/**
* Vertical scroll value when scrolling started.
* @type {number}
*/
Blockly.WorkspaceSvg.prototype.startScrollY = 0;

/**
* Horizontal distance from mouse to object being dragged.
* @type {number}
Expand Down

0 comments on commit 11ef9f2

Please sign in to comment.