mediawiki-extensions-Visual.../modules/ve/ui/layouts/ve.ui.StackPanelLayout.js

121 lines
2.5 KiB
JavaScript
Raw Normal View History

/*!
* VisualEditor UserInterface StackPanelLayout class.
*
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* Stack panel layout.
*
* @class
* @extends ve.ui.PanelLayout
* @mixins ve.ui.GroupElement
*
* @constructor
* @param {Object} [config] Config options
* @cfg {string} [icon=''] Symbolic icon name
*/
ve.ui.StackPanelLayout = function VeUiStackPanelLayout( config ) {
// Config initialization
config = ve.extendObject( config, { 'scrollable': true } );
// Parent constructor
ve.ui.PanelLayout.call( this, config );
// Mixin constructors
ve.ui.GroupElement.call( this, this.$, config );
// Properties
this.currentItem = null;
// Initialization
this.$.addClass( 've-ui-stackPanelLayout' );
};
/* Inheritance */
ve.inheritClass( ve.ui.StackPanelLayout, ve.ui.PanelLayout );
ve.mixinClass( ve.ui.StackPanelLayout, ve.ui.GroupElement );
/* Methods */
/**
* Add items.
*
* Adding an existing item (by value) will move it.
*
* @method
* @param {ve.ui.PanelLayout[]} items Items to add
Category UI improvements Objectives: * Ensure items don't get moved to the end when their sort-key is edited * Add placeholder text and pending styling to input * Auto-expand input to the end of the line * Make the minimum input width smaller Changes: ve.ui.MWMetaDialog.js * Added calls to fitInput on initialize * Fixed sort key update and insert handlers to maintain item position when updating ve.ui.GroupElement.js * Added index argument to addItems, allowing items to be inserted at a specific location ve.ui.PagePanelLayout.js * Fixed CSS class name ve.ui.StackPanelLayout.js, ve.ui.MenuWidget.js, ve.ui.SelectWidget.js * Passed index argument through to group element ve.ui.PanelLayout.js * Fixed overflow direction for scrolling option ve.ui.Inspector.css * Moved border-box properties to text input widget class * Set input widget within inspectors to be 100% by default ve.ui.Layout.css * Updated CSS class name * Whitespace fixes ve.ui.Widget.css * Made text input widgets's wrapper default to 20em wide and the input inside it be 100%, using border-box to ensure proper sizing * Adjusted category list item and input styles to make input appear more like a category item * Whitespace fixes ve.ui.MWCategoryInputWidget.js * Made category input widget inherit text input widget, rather than just input widget ve.ui.MWCategoryWidget.js * Replaced group functionality by mixing in group element * Added fitInput, which automatically make the input fill the rest of the line or take up the entire next line depending on how much space is left VisualEditor.i18n.php * Adjusted placeholder text for category input Change-Id: I79a18a7b849804027473084a42c36133fdacad57
2013-05-03 18:30:33 +00:00
* @param {number} [index] Index to insert items after
* @chainable
*/
Category UI improvements Objectives: * Ensure items don't get moved to the end when their sort-key is edited * Add placeholder text and pending styling to input * Auto-expand input to the end of the line * Make the minimum input width smaller Changes: ve.ui.MWMetaDialog.js * Added calls to fitInput on initialize * Fixed sort key update and insert handlers to maintain item position when updating ve.ui.GroupElement.js * Added index argument to addItems, allowing items to be inserted at a specific location ve.ui.PagePanelLayout.js * Fixed CSS class name ve.ui.StackPanelLayout.js, ve.ui.MenuWidget.js, ve.ui.SelectWidget.js * Passed index argument through to group element ve.ui.PanelLayout.js * Fixed overflow direction for scrolling option ve.ui.Inspector.css * Moved border-box properties to text input widget class * Set input widget within inspectors to be 100% by default ve.ui.Layout.css * Updated CSS class name * Whitespace fixes ve.ui.Widget.css * Made text input widgets's wrapper default to 20em wide and the input inside it be 100%, using border-box to ensure proper sizing * Adjusted category list item and input styles to make input appear more like a category item * Whitespace fixes ve.ui.MWCategoryInputWidget.js * Made category input widget inherit text input widget, rather than just input widget ve.ui.MWCategoryWidget.js * Replaced group functionality by mixing in group element * Added fitInput, which automatically make the input fill the rest of the line or take up the entire next line depending on how much space is left VisualEditor.i18n.php * Adjusted placeholder text for category input Change-Id: I79a18a7b849804027473084a42c36133fdacad57
2013-05-03 18:30:33 +00:00
ve.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].$.hide();
}
}
Category UI improvements Objectives: * Ensure items don't get moved to the end when their sort-key is edited * Add placeholder text and pending styling to input * Auto-expand input to the end of the line * Make the minimum input width smaller Changes: ve.ui.MWMetaDialog.js * Added calls to fitInput on initialize * Fixed sort key update and insert handlers to maintain item position when updating ve.ui.GroupElement.js * Added index argument to addItems, allowing items to be inserted at a specific location ve.ui.PagePanelLayout.js * Fixed CSS class name ve.ui.StackPanelLayout.js, ve.ui.MenuWidget.js, ve.ui.SelectWidget.js * Passed index argument through to group element ve.ui.PanelLayout.js * Fixed overflow direction for scrolling option ve.ui.Inspector.css * Moved border-box properties to text input widget class * Set input widget within inspectors to be 100% by default ve.ui.Layout.css * Updated CSS class name * Whitespace fixes ve.ui.Widget.css * Made text input widgets's wrapper default to 20em wide and the input inside it be 100%, using border-box to ensure proper sizing * Adjusted category list item and input styles to make input appear more like a category item * Whitespace fixes ve.ui.MWCategoryInputWidget.js * Made category input widget inherit text input widget, rather than just input widget ve.ui.MWCategoryWidget.js * Replaced group functionality by mixing in group element * Added fitInput, which automatically make the input fill the rest of the line or take up the entire next line depending on how much space is left VisualEditor.i18n.php * Adjusted placeholder text for category input Change-Id: I79a18a7b849804027473084a42c36133fdacad57
2013-05-03 18:30:33 +00:00
ve.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 {ve.ui.PanelLayout[]} items Items to remove
* @chainable
*/
ve.ui.StackPanelLayout.prototype.removeItems = function ( items ) {
ve.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
*/
ve.ui.StackPanelLayout.prototype.clearItems = function () {
this.currentItem = null;
ve.ui.GroupElement.prototype.clearItems.call( this );
return this;
};
/**
* Show item.
*
* Any currently shown item will be hidden.
*
* @method
* @param {ve.ui.PanelLayout} item Item to show
* @chainable
*/
ve.ui.StackPanelLayout.prototype.showItem = function ( item ) {
this.$items.hide();
item.$.show();
this.currentItem = item;
return this;
};