- /**
- * A text input with a clickable indicator
- *
- * @class
- * @private
- * @constructor
- * @param {Object} [config] Configuration options
- */
- function TextInputWithIndicatorWidget( config ) {
- var k;
-
- config = config || {};
- TextInputWithIndicatorWidget[ 'super' ].call( this, config );
-
- this.$indicator = $( '<span>' ).addClass( 'mw-apisandbox-clickable-indicator' );
- OO.ui.mixin.TabIndexedElement.call(
- this, $.extend( {}, config, { $tabIndexed: this.$indicator } )
- );
-
- this.input = new OO.ui.TextInputWidget( $.extend( {
- $indicator: this.$indicator,
- disabled: this.isDisabled()
- }, config.input ) );
-
- // Forward most methods for convenience
- for ( k in this.input ) {
- if ( $.isFunction( this.input[ k ] ) && !this[ k ] ) {
- this[ k ] = this.input[ k ].bind( this.input );
- }
- }
-
- this.$indicator.on( {
- click: this.onIndicatorClick.bind( this ),
- keypress: this.onIndicatorKeyPress.bind( this )
- } );
-
- this.$element.append( this.input.$element );
- }
- OO.inheritClass( TextInputWithIndicatorWidget, OO.ui.Widget );
- OO.mixinClass( TextInputWithIndicatorWidget, OO.ui.mixin.TabIndexedElement );
- TextInputWithIndicatorWidget.prototype.onIndicatorClick = function ( e ) {
- if ( !this.isDisabled() && e.which === 1 ) {
- this.emit( 'indicator' );
- }
- return false;
- };
- TextInputWithIndicatorWidget.prototype.onIndicatorKeyPress = function ( e ) {
- if ( !this.isDisabled() && ( e.which === OO.ui.Keys.SPACE || e.which === OO.ui.Keys.ENTER ) ) {
- this.emit( 'indicator' );
- return false;
- }
- };
- TextInputWithIndicatorWidget.prototype.setDisabled = function ( disabled ) {
- TextInputWithIndicatorWidget[ 'super' ].prototype.setDisabled.call( this, disabled );
- if ( this.input ) {
- this.input.setDisabled( this.isDisabled() );
- }
- return this;
- };
-