mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-30 00:55:00 +00:00
db9f941fa6
Objectives: * Rename this.$ to this.$element * Rename this.$$ to this.$ * Get rid of the need to use this.frame.$$ * Rename OO.ui.Element.get$$ to OO.ui.Element.getJQuery Changes: (using Sublime Text regex patterns) * Replace "get$$" with "getJQuery" * Replace "\.(\$)([^\$a-zA-Z])" with ".$element$2" * Replace "\.(\$\$)" with ".$" * Replace "'$$'" with "'$'" * Set this.$ to null in constructor of OO.ui.Window * Set this.$ to this.frame.$ in initialize method of OO.ui.Window * Replace "\.(frame.\$)([^\$a-zA-Z])" with ".\$$2" Bonus: * Use this.$() in a bunch of places where $() was erroneously used Change-Id: If3d870124ab8d10f8223532cda95c2b2b075db94
121 lines
2.6 KiB
JavaScript
121 lines
2.6 KiB
JavaScript
/*!
|
|
* ObjectOriented UserInterface StackPanelLayout class.
|
|
*
|
|
* @copyright 2011-2013 OOJS Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* Layout containing a series of mutually exclusive pages.
|
|
*
|
|
* @class
|
|
* @extends OO.ui.PanelLayout
|
|
* @mixins OO.ui.GroupElement
|
|
*
|
|
* @constructor
|
|
* @param {Object} [config] Configuration options
|
|
* @cfg {string} [icon=''] Symbolic icon name
|
|
*/
|
|
OO.ui.StackPanelLayout = function OoUiStackPanelLayout( config ) {
|
|
// Config initialization
|
|
config = $.extend( { 'scrollable': true }, config );
|
|
|
|
// Parent constructor
|
|
OO.ui.PanelLayout.call( this, config );
|
|
|
|
// Mixin constructors
|
|
OO.ui.GroupElement.call( this, this.$element, config );
|
|
|
|
// Properties
|
|
this.currentItem = null;
|
|
|
|
// Initialization
|
|
this.$element.addClass( 'oo-ui-stackPanelLayout' );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
OO.inheritClass( OO.ui.StackPanelLayout, OO.ui.PanelLayout );
|
|
|
|
OO.mixinClass( OO.ui.StackPanelLayout, OO.ui.GroupElement );
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Add items.
|
|
*
|
|
* Adding an existing item (by value) will move it.
|
|
*
|
|
* @method
|
|
* @param {OO.ui.PanelLayout[]} items Items to add
|
|
* @param {number} [index] Index to insert items after
|
|
* @chainable
|
|
*/
|
|
OO.ui.StackPanelLayout.prototype.addItems = function ( items, index ) {
|
|
var i, len;
|
|
|
|
for ( i = 0, len = items.length; i < len; i++ ) {
|
|
if ( !this.currentItem ) {
|
|
this.showItem( items[i] );
|
|
} else {
|
|
items[i].$element.hide();
|
|
}
|
|
}
|
|
OO.ui.GroupElement.prototype.addItems.call( this, items, index );
|
|
|
|
return this;
|
|
};
|
|
|
|
/**
|
|
* Remove items.
|
|
*
|
|
* Items will be detached, not removed, so they can be used later.
|
|
*
|
|
* @method
|
|
* @param {OO.ui.PanelLayout[]} items Items to remove
|
|
* @chainable
|
|
*/
|
|
OO.ui.StackPanelLayout.prototype.removeItems = function ( items ) {
|
|
OO.ui.GroupElement.prototype.removeItems.call( this, items );
|
|
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
|
|
*/
|
|
OO.ui.StackPanelLayout.prototype.clearItems = function () {
|
|
this.currentItem = null;
|
|
OO.ui.GroupElement.prototype.clearItems.call( this );
|
|
|
|
return this;
|
|
};
|
|
|
|
/**
|
|
* Show item.
|
|
*
|
|
* Any currently shown item will be hidden.
|
|
*
|
|
* @method
|
|
* @param {OO.ui.PanelLayout} item Item to show
|
|
* @chainable
|
|
*/
|
|
OO.ui.StackPanelLayout.prototype.showItem = function ( item ) {
|
|
this.$items.hide();
|
|
item.$element.show();
|
|
this.currentItem = item;
|
|
|
|
return this;
|
|
};
|