mirror of
https://github.com/scratchfoundation/scratch-blocks.git
synced 2025-08-28 22:10:31 -04:00
Use direct call to comment's resize rather than event.
This commit is contained in:
parent
8242e715c2
commit
554fe18ab9
4 changed files with 38 additions and 26 deletions
|
@ -123,6 +123,12 @@ Blockly.Bubble.onMouseUpWrapper_ = null;
|
|||
*/
|
||||
Blockly.Bubble.onMouseMoveWrapper_ = null;
|
||||
|
||||
/**
|
||||
* Function to call on resize of bubble.
|
||||
* @type {Function}
|
||||
*/
|
||||
Blockly.Bubble.prototype.resizeCallback_ = null;
|
||||
|
||||
/**
|
||||
* Stop binding to the global mouseup and mousemove events.
|
||||
* @private
|
||||
|
@ -336,11 +342,10 @@ Blockly.Bubble.prototype.resizeMouseMove_ = function(e) {
|
|||
|
||||
/**
|
||||
* Register a function as a callback event for when the bubble is resized.
|
||||
* @param {Object} thisObject The value of 'this' in the callback.
|
||||
* @param {!Function} callback The function to call on resize.
|
||||
*/
|
||||
Blockly.Bubble.prototype.registerResizeEvent = function(thisObject, callback) {
|
||||
Blockly.bindEvent_(this.bubbleGroup_, 'resize', thisObject, callback);
|
||||
Blockly.Bubble.prototype.registerResizeEvent = function(callback) {
|
||||
this.resizeCallback_ = callback;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -467,8 +472,10 @@ Blockly.Bubble.prototype.setBubbleSize = function(width, height) {
|
|||
this.positionBubble_();
|
||||
this.renderArrow_();
|
||||
}
|
||||
// Fire an event to allow the contents to resize.
|
||||
Blockly.fireUiEvent(this.bubbleGroup_, 'resize');
|
||||
// Allow the contents to resize.
|
||||
if (this.resizeCallback_) {
|
||||
this.resizeCallback_();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -106,24 +106,27 @@ Blockly.Comment.prototype.createEditor_ = function() {
|
|||
var body = document.createElementNS(Blockly.HTML_NS, 'body');
|
||||
body.setAttribute('xmlns', Blockly.HTML_NS);
|
||||
body.className = 'blocklyMinimalBody';
|
||||
this.textarea_ = document.createElementNS(Blockly.HTML_NS, 'textarea');
|
||||
this.textarea_.className = 'blocklyCommentTextarea';
|
||||
this.textarea_.setAttribute('dir', this.block_.RTL ? 'RTL' : 'LTR');
|
||||
body.appendChild(this.textarea_);
|
||||
var textarea = document.createElementNS(Blockly.HTML_NS, 'textarea');
|
||||
textarea.className = 'blocklyCommentTextarea';
|
||||
textarea.setAttribute('dir', this.block_.RTL ? 'RTL' : 'LTR');
|
||||
body.appendChild(textarea);
|
||||
this.textarea_ = textarea;
|
||||
this.foreignObject_.appendChild(body);
|
||||
Blockly.bindEvent_(this.textarea_, 'mouseup', this, this.textareaFocus_);
|
||||
Blockly.bindEvent_(textarea, 'mouseup', this, this.textareaFocus_);
|
||||
// Don't zoom with mousewheel.
|
||||
Blockly.bindEvent_(this.textarea_, 'wheel', this, function(e) {
|
||||
Blockly.bindEvent_(textarea, 'wheel', this, function(e) {
|
||||
e.stopPropagation();
|
||||
});
|
||||
Blockly.bindEvent_(this.textarea_, 'change', this, function(e) {
|
||||
if (this.text_ != this.textarea_.value) {
|
||||
Blockly.bindEvent_(textarea, 'change', this, function(e) {
|
||||
if (this.text_ != textarea.value) {
|
||||
Blockly.Events.fire(new Blockly.Events.Change(
|
||||
this.block_, 'comment', null, this.text_, this.textarea_.value));
|
||||
this.text_ = this.textarea_.value;
|
||||
this.block_, 'comment', null, this.text_, textarea.value));
|
||||
this.text_ = textarea.value;
|
||||
}
|
||||
});
|
||||
|
||||
setTimeout(function() {
|
||||
textarea.focus();
|
||||
}, 0);
|
||||
return this.foreignObject_;
|
||||
};
|
||||
|
||||
|
@ -147,12 +150,14 @@ Blockly.Comment.prototype.updateEditable = function() {
|
|||
* @private
|
||||
*/
|
||||
Blockly.Comment.prototype.resizeBubble_ = function() {
|
||||
var size = this.bubble_.getBubbleSize();
|
||||
var doubleBorderWidth = 2 * Blockly.Bubble.BORDER_WIDTH;
|
||||
this.foreignObject_.setAttribute('width', size.width - doubleBorderWidth);
|
||||
this.foreignObject_.setAttribute('height', size.height - doubleBorderWidth);
|
||||
this.textarea_.style.width = (size.width - doubleBorderWidth - 4) + 'px';
|
||||
this.textarea_.style.height = (size.height - doubleBorderWidth - 4) + 'px';
|
||||
if (this.isVisible()) {
|
||||
var size = this.bubble_.getBubbleSize();
|
||||
var doubleBorderWidth = 2 * Blockly.Bubble.BORDER_WIDTH;
|
||||
this.foreignObject_.setAttribute('width', size.width - doubleBorderWidth);
|
||||
this.foreignObject_.setAttribute('height', size.height - doubleBorderWidth);
|
||||
this.textarea_.style.width = (size.width - doubleBorderWidth - 4) + 'px';
|
||||
this.textarea_.style.height = (size.height - doubleBorderWidth - 4) + 'px';
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -183,7 +188,7 @@ Blockly.Comment.prototype.setVisible = function(visible) {
|
|||
/** @type {!Blockly.WorkspaceSvg} */ (this.block_.workspace),
|
||||
this.createEditor_(), this.block_.svgPath_,
|
||||
this.iconXY_, this.width_, this.height_);
|
||||
this.bubble_.registerResizeEvent(this, this.resizeBubble_);
|
||||
this.bubble_.registerResizeEvent(this.resizeBubble_.bind(this));
|
||||
this.updateColour();
|
||||
} else {
|
||||
// Dispose of the bubble.
|
||||
|
|
|
@ -102,7 +102,7 @@ Blockly.Toolbox.prototype.init = function() {
|
|||
this.HtmlDiv.setAttribute('dir', workspace.RTL ? 'RTL' : 'LTR');
|
||||
document.body.appendChild(this.HtmlDiv);
|
||||
|
||||
// Clicking on toolbar closes popups.
|
||||
// Clicking on toolbox closes popups.
|
||||
Blockly.bindEvent_(this.HtmlDiv, 'mousedown', this,
|
||||
function(e) {
|
||||
if (Blockly.isRightButton(e) || e.target == this.HtmlDiv) {
|
||||
|
@ -305,7 +305,7 @@ Blockly.Toolbox.prototype.clearSelection = function() {
|
|||
};
|
||||
|
||||
/**
|
||||
* Return the deletion rectangle for this toolbar.
|
||||
* Return the deletion rectangle for this toolbox.
|
||||
* @return {goog.math.Rect} Rectangle in which to delete.
|
||||
*/
|
||||
Blockly.Toolbox.prototype.getClientRect = function() {
|
||||
|
|
|
@ -532,7 +532,7 @@ Blockly.WorkspaceSvg.prototype.recordDeleteAreas = function() {
|
|||
};
|
||||
|
||||
/**
|
||||
* Is the mouse event over a delete area (toolbar or non-closing flyout)?
|
||||
* Is the mouse event over a delete area (toolbox or non-closing flyout)?
|
||||
* Opens or closes the trashcan and sets the cursor as a side effect.
|
||||
* @param {!Event} e Mouse move event.
|
||||
* @return {boolean} True if event is in a delete area.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue