mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-25 06:46:26 +00:00
Remove singular adding for ve.ui.GroupElement
By making the API for adding/removing/clearing always plural, it greatly simplifies the interfaces and reduces function call overhead in most situations. Change-Id: Ia8f23a373a01a8f6d5081587a591563e4f25ea42
This commit is contained in:
parent
e9346fdb60
commit
52529d790b
|
@ -41,29 +41,20 @@ ve.ui.GroupElement.prototype.getItems = function () {
|
|||
* @chainable
|
||||
*/
|
||||
ve.ui.GroupElement.prototype.addItems = function ( items ) {
|
||||
var i, len;
|
||||
for ( i = 0, len = items.length; i < len; i++ ) {
|
||||
this.addItem( items[i] );
|
||||
}
|
||||
return this;
|
||||
};
|
||||
var i, len, item;
|
||||
|
||||
/**
|
||||
* Add item.
|
||||
*
|
||||
* @method
|
||||
* @param {ve.ui.Widget} item Item
|
||||
* @chainable
|
||||
*/
|
||||
ve.ui.GroupElement.prototype.addItem = function ( item ) {
|
||||
// Check if item exists then remove it first, effectively "moving" it
|
||||
if ( this.items.indexOf( item ) !== -1 ) {
|
||||
this.removeItems( [item] );
|
||||
for ( i = 0, len = items.length; i < len; i++ ) {
|
||||
item = items[i];
|
||||
|
||||
// Check if item exists then remove it first, effectively "moving" it
|
||||
if ( this.items.indexOf( item ) !== -1 ) {
|
||||
this.removeItems( [item] );
|
||||
}
|
||||
// Add the item
|
||||
this.items.push( item );
|
||||
this.$.append( item.$ );
|
||||
this.$items = this.$items.add( item.$ );
|
||||
}
|
||||
// Add the item
|
||||
this.items.push( item );
|
||||
this.$.append( item.$ );
|
||||
this.$items = this.$items.add( item.$ );
|
||||
|
||||
return this;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue