# all files / src/widgets/ ButtonOptionWidget.js

40.91% Statements 9/22
0% Branches 0/4
0% Functions 0/2
40.91% Lines 9/22

    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

    1×

    1×
    1×
    1×
    1×
    1×

    1×

    1×

    1×

     /**
     * ButtonOptionWidget is a special type of {@link OO.ui.mixin.ButtonElement button element} that
     * can be selected and configured with data. The class is
     * used with OO.ui.ButtonSelectWidget to create a selection of button options. Please see the
     * [OOUI documentation on MediaWiki] [1] for more information.
     *
     * [1]: https://www.mediawiki.org/wiki/OOUI/Widgets/Selects_and_Options#Button_selects_and_options
     *
     * @class
     * @extends OO.ui.OptionWidget
     * @mixins OO.ui.mixin.ButtonElement
     * @mixins OO.ui.mixin.IconElement
     * @mixins OO.ui.mixin.IndicatorElement
     * @mixins OO.ui.mixin.TitledElement
     *
     * @constructor
     * @param {Object} [config] Configuration options
     */
    OO.ui.ButtonOptionWidget = function OoUiButtonOptionWidget( config ) {
    	// Configuration initialization
    	config = config || {};

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

    	// Mixin constructors
    	OO.ui.mixin.ButtonElement.call( this, config );
    	OO.ui.mixin.IconElement.call( this, config );
    	OO.ui.mixin.IndicatorElement.call( this, config );
    	OO.ui.mixin.TitledElement.call( this, $.extend( {}, config, { $titled: this.$button } ) );

    	// Initialization
    	this.$element.addClass( 'oo-ui-buttonOptionWidget' );
    	this.$button.append( this.$icon, this.$label, this.$indicator );
    	this.$element.append( this.$button );
    };

    /* Setup */

    OO.inheritClass( OO.ui.ButtonOptionWidget, OO.ui.OptionWidget );
    OO.mixinClass( OO.ui.ButtonOptionWidget, OO.ui.mixin.ButtonElement );
    OO.mixinClass( OO.ui.ButtonOptionWidget, OO.ui.mixin.IconElement );
    OO.mixinClass( OO.ui.ButtonOptionWidget, OO.ui.mixin.IndicatorElement );
    OO.mixinClass( OO.ui.ButtonOptionWidget, OO.ui.mixin.TitledElement );

    /* Static Properties */

    /**
     * Allow button mouse down events to pass through so they can be handled by the parent select widget
     *
     * @static
     * @inheritdoc
     */
    OO.ui.ButtonOptionWidget.static.cancelButtonMouseDownEvents = false;

    /**
     * @static
     * @inheritdoc
     */
    OO.ui.ButtonOptionWidget.static.highlightable = false;

    /* Methods */

    /**
     * @inheritdoc
     */
    OO.ui.ButtonOptionWidget.prototype.setSelected = function ( state ) {
    	OO.ui.ButtonOptionWidget.parent.prototype.setSelected.call( this, state );

    	if ( this.constructor.static.selectable ) {
    		this.setActive( state );
    	}

    	return this;
    };