mediawiki-extensions-Visual.../modules/ve/ui/elements/ve.ui.GroupElement.js
Trevor Parscal a2e59f7c86 Stack panel, element mixins, cleanup
*.php
* Updated links to files

ve.ui.MetaDialog
* Added stack panel that now contains category and language editor panels
* Attached outline widget to stack panel

ve.ui.FlaggableWidget -> ve.ui.FlaggableElement
* Moved to elements

ve.ui.GroupWidget -> ve.ui.GroupElement
* Moved to elements
* Removed invalid event documentation

ve.ui.LabledWidget -> ve.ui.LabledElement
* Moved to elements

ve.ui.StackPanelLayout.js
* New class, mutually exclusive panel container

ve.ui.TitledPanelLayout
* Remvoed, using labeled element instead

ve.ui.Element.css
* Added for elements
* Moved label style here, from widget styles

*.css, ve.ui.ButtonWidget.js, ve.ui.InputLabelWidget, ve.ui.OptionWidget, ve.ui.SelectWidget
* Adjusted class names to reflect widget -> element migration

Change-Id: I32f504c844dba7aae1b286eef06ca046627bdc8d
2013-03-28 12:40:01 -07:00

102 lines
1.9 KiB
JavaScript

/*!
* VisualEditor UserInterface GroupElement class.
*
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* Group element.
*
* @class
* @abstract
*
* @constructor
* @param {jQuery} $group Group element
*/
ve.ui.GroupElement = function VeUiGroupElement( $group ) {
// Properties
this.$group = $group;
this.items = [];
this.$items = this.$$( [] );
};
/* Methods */
/**
* Get items.
*
* @method
* @returns {ve.ui.Element[]} Items
*/
ve.ui.GroupElement.prototype.getItems = function () {
return this.items.slice( 0 );
};
/**
* Add items.
*
* @method
* @param {ve.ui.Element[]} items Item
* @chainable
*/
ve.ui.GroupElement.prototype.addItems = function ( items ) {
var i, len, 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.$group.append( item.$ );
this.$items = this.$items.add( item.$ );
}
return this;
};
/**
* Remove items.
*
* Items will be detached, not removed, so they can be used later.
*
* @method
* @param {ve.ui.Element[]} items Items to remove
* @chainable
*/
ve.ui.GroupElement.prototype.removeItems = function ( items ) {
var i, len, item, index;
// Remove specific items
for ( i = 0, len = items.length; i < len; i++ ) {
item = items[i];
index = this.items.indexOf( item );
if ( index !== -1 ) {
this.items.splice( index, 1 );
item.$.detach();
this.$items = this.$items.not( item.$ );
}
}
return this;
};
/**
* Clear all items.
*
* Items will be detached, not removed, so they can be used later.
*
* @method
* @chainable
*/
ve.ui.GroupElement.prototype.clearItems = function () {
this.items = [];
this.$items.detach();
return this;
};