mediawiki-extensions-Visual.../modules/ve/ui/widgets/ve.ui.TextInputWidget.js
Trevor Parscal 8a8a337ce5 Pending input refactor
Objective:

* Make all text inputs have the ability to be "pending", not just ones
  with a special mixin

Changes:

* Delete pending input widget
* Move pending input widget implementation to text input widget
* Update all uses of pending input widget
* Make pending image a reusable "texture"
* Update styles of text input widget for pending state
* Get rid of checking for mixin since all text inputs can be pending now

Bonus:

* Get rid of unused images, including .psd and .ai files
* Add transparency texture
* Fix input widget not using documented config value
* Fix documentation in select widget (lies!)

Change-Id: Ib46ab01dc39d706e5c25fd473dee0edce51b7e44
2013-06-06 21:17:35 +00:00

92 lines
2 KiB
JavaScript

/*!
* VisualEditor UserInterface TextInputWidget class.
*
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* Creates an ve.ui.TextInputWidget object.
*
* @class
* @extends ve.ui.InputWidget
*
* @constructor
* @param {Object} [config] Config options
* @cfg {string} [placeholder] Placeholder text
* @cfg {string} [icon] Symbolic name of icon
*/
ve.ui.TextInputWidget = function VeUiTextInputWidget( config ) {
// Parent constructor
ve.ui.InputWidget.call( this, config );
// Properties
this.pending = 0;
// Initialization
this.$.addClass( 've-ui-textInputWidget' );
if ( config.icon ) {
this.$.addClass( 've-ui-textInputWidget-decorated' );
this.$.append(
$( '<span>' )
.addClass( 've-ui-textInputWidget-icon ve-ui-icon-' + config.icon )
.mousedown( ve.bind( function () {
this.$input.focus();
return false;
}, this ) )
);
}
if ( config.placeholder ) {
this.$input.attr( 'placeholder', config.placeholder );
}
};
/* Inheritance */
ve.inheritClass( ve.ui.TextInputWidget, ve.ui.InputWidget );
/* Methods */
/**
* Get input element.
*
* @method
* @param {Object} [config] Config options
* @return {jQuery} Input element
*/
ve.ui.TextInputWidget.prototype.getInputElement = function ( config ) {
return config.multiline ? this.$$( '<textarea>' ) : this.$$( '<input>' ).attr( 'type', 'text' );
};
/* Methods */
/**
* Increases the pending stack.
*
* @method
* @chainable
*/
ve.ui.TextInputWidget.prototype.pushPending = function () {
this.pending++;
this.$.addClass( 've-ui-textInputWidget-pending' );
this.$input.addClass( 've-ui-texture-pending' );
return this;
};
/**
* Reduces the pending stack.
*
* Clamped at zero.
*
* @method
* @chainable
*/
ve.ui.TextInputWidget.prototype.popPending = function () {
this.pending = Math.max( 0, this.pending - 1 );
if ( !this.pending ) {
this.$.removeClass( 've-ui-textInputWidget-pending' );
this.$input.removeClass( 've-ui-texture-pending' );
}
return this;
};