2013-03-28 01:37:34 +00:00
|
|
|
/*!
|
2013-10-09 20:09:59 +00:00
|
|
|
* ObjectOriented UserInterface StackPanelLayout class.
|
2013-03-28 01:37:34 +00:00
|
|
|
*
|
2013-10-09 20:09:59 +00:00
|
|
|
* @copyright 2011-2013 OOJS Team and others; see AUTHORS.txt
|
2013-03-28 01:37:34 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2013-10-09 20:09:59 +00:00
|
|
|
* Layout containing a series of mutually exclusive pages.
|
2013-03-28 01:37:34 +00:00
|
|
|
*
|
|
|
|
* @class
|
2013-10-09 20:09:59 +00:00
|
|
|
* @extends OO.ui.PanelLayout
|
|
|
|
* @mixins OO.ui.GroupElement
|
2013-03-28 01:37:34 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
2013-09-25 10:21:09 +00:00
|
|
|
* @param {Object} [config] Configuration options
|
2013-03-28 01:37:34 +00:00
|
|
|
* @cfg {string} [icon=''] Symbolic icon name
|
|
|
|
*/
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.ui.StackPanelLayout = function OoUiStackPanelLayout( config ) {
|
2013-03-28 01:37:34 +00:00
|
|
|
// Config initialization
|
2013-10-09 20:09:59 +00:00
|
|
|
config = OO.ui.extendObject( { 'scrollable': true }, config );
|
2013-03-28 01:37:34 +00:00
|
|
|
|
|
|
|
// Parent constructor
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.ui.PanelLayout.call( this, config );
|
2013-03-28 01:37:34 +00:00
|
|
|
|
|
|
|
// Mixin constructors
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.ui.GroupElement.call( this, this.$, config );
|
2013-03-28 01:37:34 +00:00
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.currentItem = null;
|
|
|
|
|
|
|
|
// Initialization
|
2013-10-09 20:09:59 +00:00
|
|
|
this.$.addClass( 'oo-ui-stackPanelLayout' );
|
2013-03-28 01:37:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.inheritClass( OO.ui.StackPanelLayout, OO.ui.PanelLayout );
|
2013-03-28 01:37:34 +00:00
|
|
|
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.mixinClass( OO.ui.StackPanelLayout, OO.ui.GroupElement );
|
2013-03-28 01:37:34 +00:00
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add items.
|
|
|
|
*
|
|
|
|
* Adding an existing item (by value) will move it.
|
|
|
|
*
|
|
|
|
* @method
|
2013-10-09 20:09:59 +00:00
|
|
|
* @param {OO.ui.PanelLayout[]} items Items to add
|
2013-05-03 18:30:33 +00:00
|
|
|
* @param {number} [index] Index to insert items after
|
2013-03-28 01:37:34 +00:00
|
|
|
* @chainable
|
|
|
|
*/
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.ui.StackPanelLayout.prototype.addItems = function ( items, index ) {
|
2013-03-28 01:37:34 +00:00
|
|
|
var i, len;
|
|
|
|
|
|
|
|
for ( i = 0, len = items.length; i < len; i++ ) {
|
|
|
|
if ( !this.currentItem ) {
|
2013-04-24 19:40:56 +00:00
|
|
|
this.showItem( items[i] );
|
2013-03-28 01:37:34 +00:00
|
|
|
} else {
|
|
|
|
items[i].$.hide();
|
|
|
|
}
|
|
|
|
}
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.ui.GroupElement.prototype.addItems.call( this, items, index );
|
2013-03-28 01:37:34 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove items.
|
|
|
|
*
|
|
|
|
* Items will be detached, not removed, so they can be used later.
|
|
|
|
*
|
|
|
|
* @method
|
2013-10-09 20:09:59 +00:00
|
|
|
* @param {OO.ui.PanelLayout[]} items Items to remove
|
2013-03-28 01:37:34 +00:00
|
|
|
* @chainable
|
|
|
|
*/
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.ui.StackPanelLayout.prototype.removeItems = function ( items ) {
|
|
|
|
OO.ui.GroupElement.prototype.removeItems.call( this, items );
|
2013-03-28 01:37:34 +00:00
|
|
|
if ( items.indexOf( this.currentItem ) !== -1 ) {
|
|
|
|
this.currentItem = null;
|
|
|
|
if ( !this.currentItem && this.items.length ) {
|
|
|
|
this.showItem( this.items[0] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear all items.
|
|
|
|
*
|
|
|
|
* Items will be detached, not removed, so they can be used later.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @chainable
|
|
|
|
*/
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.ui.StackPanelLayout.prototype.clearItems = function () {
|
2013-03-28 01:37:34 +00:00
|
|
|
this.currentItem = null;
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.ui.GroupElement.prototype.clearItems.call( this );
|
2013-03-28 01:37:34 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show item.
|
|
|
|
*
|
|
|
|
* Any currently shown item will be hidden.
|
|
|
|
*
|
|
|
|
* @method
|
2013-10-09 20:09:59 +00:00
|
|
|
* @param {OO.ui.PanelLayout} item Item to show
|
2013-03-28 01:37:34 +00:00
|
|
|
* @chainable
|
|
|
|
*/
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.ui.StackPanelLayout.prototype.showItem = function ( item ) {
|
2013-03-28 01:37:34 +00:00
|
|
|
this.$items.hide();
|
|
|
|
item.$.show();
|
2013-04-24 19:40:56 +00:00
|
|
|
this.currentItem = item;
|
2013-03-28 01:37:34 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|