MDL-71669 editor_atto: Fire custom event when toggling button highlight

This commit is contained in:
Jun Pataleta 2021-06-01 12:46:18 +08:00
parent 45906644be
commit 2dcede1b0b
4 changed files with 58 additions and 1 deletions

View File

@ -1035,16 +1035,35 @@ EditorPluginButtons.prototype = {
if (button) {
if (this.buttons[button]) {
this.buttons[button][method](HIGHLIGHT);
this._buttonHighlightToggled(button, highlight);
}
} else {
Y.Object.each(this.buttons, function(button) {
button[method](HIGHLIGHT);
this._buttonHighlightToggled(button, highlight);
}, this);
}
return this;
},
/**
* Fires a custom event that notifies listeners that a button's highlight has been toggled.
*
* @param {String} buttonName The button name.
* @param {Boolean} highlight True when the button was highlighted. False, otherwise.
* @private
*/
_buttonHighlightToggled: function(buttonName, highlight) {
var toggledButton = this.buttons[buttonName];
if (toggledButton) {
// Fire an event that the button highlight was toggled.
require(['editor_atto/events'], function(attoEvents) {
attoEvents.notifyButtonHighlightToggled(toggledButton.getDOMNode(), buttonName, highlight);
});
}
},
/**
* Get the default meta key to use with keyboard events.
*

File diff suppressed because one or more lines are too long

View File

@ -1031,16 +1031,35 @@ EditorPluginButtons.prototype = {
if (button) {
if (this.buttons[button]) {
this.buttons[button][method](HIGHLIGHT);
this._buttonHighlightToggled(button, highlight);
}
} else {
Y.Object.each(this.buttons, function(button) {
button[method](HIGHLIGHT);
this._buttonHighlightToggled(button, highlight);
}, this);
}
return this;
},
/**
* Fires a custom event that notifies listeners that a button's highlight has been toggled.
*
* @param {String} buttonName The button name.
* @param {Boolean} highlight True when the button was highlighted. False, otherwise.
* @private
*/
_buttonHighlightToggled: function(buttonName, highlight) {
var toggledButton = this.buttons[buttonName];
if (toggledButton) {
// Fire an event that the button highlight was toggled.
require(['editor_atto/events'], function(attoEvents) {
attoEvents.notifyButtonHighlightToggled(toggledButton.getDOMNode(), buttonName, highlight);
});
}
},
/**
* Get the default meta key to use with keyboard events.
*

View File

@ -885,16 +885,35 @@ EditorPluginButtons.prototype = {
if (button) {
if (this.buttons[button]) {
this.buttons[button][method](HIGHLIGHT);
this._buttonHighlightToggled(button, highlight);
}
} else {
Y.Object.each(this.buttons, function(button) {
button[method](HIGHLIGHT);
this._buttonHighlightToggled(button, highlight);
}, this);
}
return this;
},
/**
* Fires a custom event that notifies listeners that a button's highlight has been toggled.
*
* @param {String} buttonName The button name.
* @param {Boolean} highlight True when the button was highlighted. False, otherwise.
* @private
*/
_buttonHighlightToggled: function(buttonName, highlight) {
var toggledButton = this.buttons[buttonName];
if (toggledButton) {
// Fire an event that the button highlight was toggled.
require(['editor_atto/events'], function(attoEvents) {
attoEvents.notifyButtonHighlightToggled(toggledButton.getDOMNode(), buttonName, highlight);
});
}
},
/**
* Get the default meta key to use with keyboard events.
*