diff --git a/core/bubble.js b/core/bubble.js index 4e139bdc3..1e9829e58 100644 --- a/core/bubble.js +++ b/core/bubble.js @@ -51,6 +51,34 @@ Blockly.Bubble = function(workspace, content, shape, anchorXY, this.content_ = content; this.shape_ = shape; + /** + * Method to call on resize of bubble. + * @type {?function()} + * @private + */ + this.resizeCallback_ = null; + + /** + * Method to call on move of bubble. + * @type {?function()} + * @private + */ + this.moveCallback_ = null; + + /** + * Mouse down on bubbleBack_ event data. + * @type {?Blockly.EventData} + * @private + */ + this.onMouseDownBubbleWrapper_ = null; + + /** + * Mouse down on resizeGroup_ event data. + * @type {?Blockly.EventData} + * @private + */ + this.onMouseDownResizeWrapper_ = null; + var angle = Blockly.Bubble.ARROW_ANGLE; if (this.workspace_.RTL) { angle = -angle; @@ -72,29 +100,6 @@ Blockly.Bubble = function(workspace, content, shape, anchorXY, this.positionBubble_(); this.renderArrow_(); this.rendered_ = true; - - if (!workspace.options.readOnly) { - Blockly.bindEventWithChecks_( - this.bubbleBack_, 'mousedown', this, this.bubbleMouseDown_); - if (this.resizeGroup_) { - Blockly.bindEventWithChecks_( - this.resizeGroup_, 'mousedown', this, this.resizeMouseDown_); - } - } - - /** - * Method to call on resize of bubble. - * @type {?function()} - * @private - */ - this.resizeCallback_ = null; - - /** - * Method to call on move of bubble. - * @type {?function()} - * @private - */ - this.moveCallback_ = null; }; /** @@ -124,15 +129,15 @@ Blockly.Bubble.ARROW_BEND = 4; Blockly.Bubble.ANCHOR_RADIUS = 8; /** - * Wrapper function called when a mouseUp occurs during a drag operation. - * @type {Array.} + * Mouse up event data. + * @type {?Blockly.EventData} * @private */ Blockly.Bubble.onMouseUpWrapper_ = null; /** - * Wrapper function called when a mouseMove occurs during a drag operation. - * @type {Array.} + * Mouse move event data. + * @type {?Blockly.EventData} * @private */ Blockly.Bubble.onMouseMoveWrapper_ = null; @@ -278,6 +283,15 @@ Blockly.Bubble.prototype.createDom_ = function(content, hasResize) { } else { this.resizeGroup_ = null; } + + if (!this.workspace_.options.readOnly) { + this.onMouseDownBubbleWrapper_ = Blockly.bindEventWithChecks_( + this.bubbleBack_, 'mousedown', this, this.bubbleMouseDown_); + if (this.resizeGroup_) { + this.onMouseDownResizeWrapper_ = Blockly.bindEventWithChecks_( + this.resizeGroup_, 'mousedown', this, this.resizeMouseDown_); + } + } this.bubbleGroup_.appendChild(content); return this.bubbleGroup_; }; @@ -785,6 +799,14 @@ Blockly.Bubble.prototype.dispose = function() { Blockly.Bubble.unbindDragEvents_(); // Dispose of and unlink the bubble. Blockly.utils.dom.removeNode(this.bubbleGroup_); + if (this.onMouseDownBubbleWrapper_) { + Blockly.unbindEvent_(this.onMouseDownBubbleWrapper_); + this.onMouseDownBubbleWrapper_ = null; + } + if (this.onMouseDownResizeWrapper_) { + Blockly.unbindEvent_(this.onMouseDownResizeWrapper_); + this.onMouseDownResizeWrapper_ = null; + } this.bubbleGroup_ = null; this.bubbleArrow_ = null; this.bubbleBack_ = null; diff --git a/core/comment.js b/core/comment.js index 680b6ca95..ce4dbf2bc 100644 --- a/core/comment.js +++ b/core/comment.js @@ -61,6 +61,34 @@ Blockly.Comment = function(block) { */ this.cachedText_ = ''; + /** + * Mouse up event data. + * @type {?Blockly.EventData} + * @private + */ + this.onMouseUpWrapper_ = null; + + /** + * Wheel event data. + * @type {?Blockly.EventData} + * @private + */ + this.onWheelWrapper_ = null; + + /** + * Change event data. + * @type {?Blockly.EventData} + * @private + */ + this.onChangeWrapper_ = null; + + /** + * Input event data. + * @type {?Blockly.EventData} + * @private + */ + this.onInputWrapper_ = null; + this.createIcon(); }; Blockly.utils.object.inherits(Blockly.Comment, Blockly.Icon); @@ -137,21 +165,24 @@ Blockly.Comment.prototype.createEditor_ = function() { // Ideally this would be hooked to the focus event for the comment. // However doing so in Firefox swallows the cursor for unknown reasons. // So this is hooked to mouseup instead. No big deal. - Blockly.bindEventWithChecks_(textarea, 'mouseup', this, this.startEdit_, - true, true); + this.onMouseUpWrapper_ = Blockly.bindEventWithChecks_( + textarea, 'mouseup', this, this.startEdit_, true, true); // Don't zoom with mousewheel. - Blockly.bindEventWithChecks_(textarea, 'wheel', this, function(e) { - e.stopPropagation(); - }); - Blockly.bindEventWithChecks_(textarea, 'change', this, function(_e) { - if (this.cachedText_ != this.model_.text) { - Blockly.Events.fire(new Blockly.Events.BlockChange( - this.block_, 'comment', null, this.cachedText_, this.model_.text)); - } - }); - Blockly.bindEventWithChecks_(textarea, 'input', this, function(_e) { - this.model_.text = textarea.value; - }); + this.onWheelWrapper_ = Blockly.bindEventWithChecks_( + textarea, 'wheel', this, function(e) { + e.stopPropagation(); + }); + this.onChangeWrapper_ = Blockly.bindEventWithChecks_( + textarea, 'change', this, function(_e) { + if (this.cachedText_ != this.model_.text) { + Blockly.Events.fire(new Blockly.Events.BlockChange( + this.block_, 'comment', null, this.cachedText_, this.model_.text)); + } + }); + this.onInputWrapper_ = Blockly.bindEventWithChecks_( + textarea, 'input', this, function(_e) { + this.model_.text = textarea.value; + }); setTimeout(textarea.focus.bind(textarea), 0); @@ -271,7 +302,22 @@ Blockly.Comment.prototype.disposeBubble_ = function() { Blockly.Warning.prototype.disposeBubble.call(this); return; } - + if (this.onMouseUpWrapper_) { + Blockly.unbindEvent_(this.onMouseUpWrapper_); + this.onMouseUpWrapper_ = null; + } + if (this.onWheelWrapper_) { + Blockly.unbindEvent_(this.onWheelWrapper_); + this.onWheelWrapper_ = null; + } + if (this.onChangeWrapper_) { + Blockly.unbindEvent_(this.onChangeWrapper_); + this.onChangeWrapper_ = null; + } + if (this.onInputWrapper_) { + Blockly.unbindEvent_(this.onInputWrapper_); + this.onInputWrapper_ = null; + } this.bubble_.dispose(); this.bubble_ = null; this.textarea_ = null;