Merge pull request from wdr-data/fix/category-item-ids

Add class to category menu item based on id
This commit is contained in:
picklesrus 2019-01-28 10:53:43 -05:00 committed by GitHub
commit e8f5776f85
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -686,13 +686,31 @@ Blockly.Toolbox.Category.prototype.dispose = function() {
this.contents_ = null;
};
/**
* Used to determine the css classes for the menu item for this category
* based on its current state.
* @private
* @param {boolean=} selected Indication whether the category is currently selected.
* @return {string} The css class names to be applied, space-separated.
*/
Blockly.Toolbox.Category.prototype.getMenuItemClassName_ = function(selected) {
var classNames = [
'scratchCategoryMenuItem',
'scratchCategoryId-' + this.id_,
];
if (selected) {
classNames.push('categorySelected');
}
return classNames.join(' ');
};
/**
* Create the DOM for a category in the toolbox.
*/
Blockly.Toolbox.Category.prototype.createDom = function() {
var toolbox = this.parent_.parent_;
this.item_ = goog.dom.createDom('div',
{'class': 'scratchCategoryMenuItem'});
{'class': this.getMenuItemClassName_()});
this.label_ = goog.dom.createDom('div',
{'class': 'scratchCategoryMenuItemLabel'},
Blockly.utils.replaceMessageReferences(this.name_));
@ -718,11 +736,7 @@ Blockly.Toolbox.Category.prototype.createDom = function() {
* @param {boolean} selected Whether this category is selected.
*/
Blockly.Toolbox.Category.prototype.setSelected = function(selected) {
if (selected) {
this.item_.className = 'scratchCategoryMenuItem categorySelected';
} else {
this.item_.className = 'scratchCategoryMenuItem';
}
this.item_.className = this.getMenuItemClassName_(selected);
};
/**