Skip to content

Commit

Permalink
Back-port field_pitch changes from Blockly demos
Browse files Browse the repository at this point in the history
Mostly changes to events.  Can't see any functional changes.
  • Loading branch information
NeilFraser committed Nov 7, 2021
1 parent f404b1d commit 3106769
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions appengine/music/js/field_pitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ var CustomFields = CustomFields || {};
*/
CustomFields.FieldPitch = function(text) {
CustomFields.FieldPitch.superClass_.constructor.call(this, text);

/**
* Click event data.
* @type {?Blockly.browserEvents.Data}
* @private
*/
this.clickWrapper_ = null;

/**
* Move event data.
* @type {?Blockly.browserEvents.Data}
* @private
*/
this.moveWrapper_ = null;
};
Blockly.utils.object.inherits(CustomFields.FieldPitch, Blockly.FieldTextInput);

Expand All @@ -48,7 +62,7 @@ CustomFields.FieldPitch.NOTES = 'C3 D3 E3 F3 G3 A3 B3 C4 D4 E4 F4 G4 A4'.split(/

/**
* Show the inline free-text editor on top of the text and the note picker.
* @private
* @protected
*/
CustomFields.FieldPitch.prototype.showEditor_ = function() {
CustomFields.FieldPitch.superClass_.showEditor_.call(this);
Expand All @@ -62,7 +76,7 @@ CustomFields.FieldPitch.prototype.showEditor_ = function() {
var editor = this.dropdownCreate_();
Blockly.DropDownDiv.getContentDiv().appendChild(editor);

Blockly.DropDownDiv.setColour(this.sourceBlock_.getColour(),
Blockly.DropDownDiv.setColour(this.sourceBlock_.style.colourPrimary,
this.sourceBlock_.style.colourTertiary);

Blockly.DropDownDiv.showPositionedByField(
Expand All @@ -73,11 +87,9 @@ CustomFields.FieldPitch.prototype.showEditor_ = function() {
// change this behaviour. For now, using bindEvent_ instead of
// bindEventWithChecks_ allows it to work without a mousedown/touchstart.
this.clickWrapper_ =
Blockly.bindEvent_(this.imageElement_, 'click', this,
this.hide_);
this.moveWrapper_ =
Blockly.bindEvent_(this.imageElement_, 'mousemove', this,
this.onMouseMove);
Blockly.browserEvents.bind(this.imageElement_, 'click', this, this.hide_);
this.moveWrapper_ = Blockly.browserEvents.bind(
this.imageElement_, 'mousemove', this, this.onMouseMove);

this.updateGraph_();
};
Expand All @@ -99,8 +111,15 @@ CustomFields.FieldPitch.prototype.dropdownCreate_ = function() {
* @private
*/
CustomFields.FieldPitch.prototype.dropdownDispose_ = function() {
Blockly.unbindEvent_(this.clickWrapper_);
Blockly.unbindEvent_(this.moveWrapper_);
if (this.clickWrapper_) {
Blockly.browserEvents.unbind(this.clickWrapper_);
this.clickWrapper_ = null;
}
if (this.moveWrapper_) {
Blockly.browserEvents.unbind(this.moveWrapper_);
this.moveWrapper_ = null;
}
this.imageElement_ = null;
};

/**
Expand Down

0 comments on commit 3106769

Please sign in to comment.