# all files / src/widgets/ SearchInputWidget.js

73.08% Statements 19/26
28.57% Branches 2/7
57.14% Functions 4/7
73.08% Lines 19/26

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94

    1×
    2516×

    2516×

    2516×

    2516×
    2516×

    1×

    1×
    5032×

    1×

    1×
    5032×
    5032×

    1×

    1×

    1×
    2516×
    2516×
    2516×

     /**
     * @class
     * @extends OO.ui.TextInputWidget
     *
     * @constructor
     * @param {Object} [config] Configuration options
     */
    OO.ui.SearchInputWidget = function OoUiSearchInputWidget( config ) {
    	config = $.extend( {
    		icon: 'search'
    	}, config );

    	// Parent constructor
    	OO.ui.SearchInputWidget.parent.call( this, config );

    	// Events
    	this.connect( this, {
    		change: 'onChange'
    	} );

    	// Initialization
    	this.updateSearchIndicator();
    	this.connect( this, {
    		disable: 'onDisable'
    	} );
    };

    /* Setup */

    OO.inheritClass( OO.ui.SearchInputWidget, OO.ui.TextInputWidget );

    /* Methods */

    /**
     * @inheritdoc
     * @protected
     */
    OO.ui.SearchInputWidget.prototype.getSaneType = function () {
    	return 'search';
    };

    /**
     * @inheritdoc
     */
    OO.ui.SearchInputWidget.prototype.onIndicatorMouseDown = function ( e ) {
    	if ( e.which === OO.ui.MouseButtons.LEFT ) {
    		// Clear the text field
    		this.setValue( '' );
    		this.focus();
    		return false;
    	}
    };

    /**
     * Update the 'clear' indicator displayed on type: 'search' text
     * fields, hiding it when the field is already empty or when it's not
     * editable.
     */
    OO.ui.SearchInputWidget.prototype.updateSearchIndicator = function () {
    	Eif ( this.getValue() === '' || this.isDisabled() || this.isReadOnly() ) {
    		this.setIndicator( null );
    	} else {
    		this.setIndicator( 'clear' );
    	}
    };

    /**
     * Handle change events.
     *
     * @private
     */
    OO.ui.SearchInputWidget.prototype.onChange = function () {
    	this.updateSearchIndicator();
    };

    /**
     * Handle disable events.
     *
     * @param {boolean} disabled Element is disabled
     * @private
     */
    OO.ui.SearchInputWidget.prototype.onDisable = function () {
    	this.updateSearchIndicator();
    };

    /**
     * @inheritdoc
     */
    OO.ui.SearchInputWidget.prototype.setReadOnly = function ( state ) {
    	OO.ui.SearchInputWidget.parent.prototype.setReadOnly.call( this, state );
    	this.updateSearchIndicator();
    	return this;
    };