mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-25 23:05:35 +00:00
7b8eed957f
Parameter config is optional (both in the parent class and here), this subclass forgot to add the fallback. Though in a plain subclass the local fallback isn't needed (parent class takes cares of it), in this case it is needed since the constructor directly accesses config.multiline etc. Change-Id: I3f9b73efb6c40a29efa221e1654b1247baaca281
131 lines
2.8 KiB
JavaScript
131 lines
2.8 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
|
|
* @cfg {boolean} [multiline=false] Allow multiple lines of text
|
|
*/
|
|
ve.ui.TextInputWidget = function VeUiTextInputWidget( config ) {
|
|
config = config || {};
|
|
|
|
// Parent constructor
|
|
ve.ui.InputWidget.call( this, config );
|
|
|
|
// Properties
|
|
this.pending = 0;
|
|
this.multiline = !!config.multiline;
|
|
|
|
// Events
|
|
this.$input.on( 'keypress', ve.bind( this.onKeyPress, this ) );
|
|
|
|
// 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 );
|
|
|
|
/* Events */
|
|
|
|
/**
|
|
* User presses enter inside the text box.
|
|
*
|
|
* Not called if input is multiline.
|
|
*
|
|
* @event enter
|
|
*/
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Handles key press events.
|
|
*
|
|
* @param {jQuery.Event} e Key press event
|
|
* @emits enter If enter key is pressed and input is not multiline
|
|
*/
|
|
ve.ui.TextInputWidget.prototype.onKeyPress = function ( e ) {
|
|
if ( e.which === ve.Keys.ENTER && !this.multiline ) {
|
|
this.emit( 'enter' );
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Get input element.
|
|
*
|
|
* @method
|
|
* @param {Object} [config] Config options
|
|
* @returns {jQuery} Input element
|
|
*/
|
|
ve.ui.TextInputWidget.prototype.getInputElement = function ( config ) {
|
|
return config.multiline ? this.$$( '<textarea>' ) : this.$$( '<input>' ).attr( 'type', 'text' );
|
|
};
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Checks if input is pending.
|
|
*
|
|
* @method
|
|
* @returns {boolean} Input is pending
|
|
*/
|
|
ve.ui.TextInputWidget.prototype.isPending = function () {
|
|
return !!this.pending;
|
|
};
|
|
|
|
/**
|
|
* 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;
|
|
};
|