Merge "resourceloader: Simplify StringSet fallback"
[lhc/web/wiklou.git] / resources / src / mediawiki.widgets / mw.widgets.SizeFilterWidget.js
1 /*!
2 * MediaWiki Widgets - SizeFilterWidget class.
3 *
4 * @copyright 2011-2018 MediaWiki Widgets Team and others; see AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
6 */
7 ( function () {
8
9 /**
10 * RadioSelectInputWidget and a TextInputWidget to set minimum or maximum byte size
11 *
12 * mw.loader.using( 'mediawiki.widgets.SizeFilterWidget', function () {
13 * var sf = new mw.widgets.SizeFilterWidget();
14 * $( 'body' ).append( sf.$element );
15 * } );
16 *
17 * @class mw.widgets.SizeFilterWidget
18 * @extends OO.ui.Widget
19 * @uses OO.ui.RadioSelectInputWidget
20 * @uses OO.ui.TextInputWidget
21 *
22 * @constructor
23 * @param {Object} [config] Configuration options
24 * @cfg {Object} [radioselectinput] Config for the radio select input
25 * @cfg {Object} [textinput] Config for the text input
26 * @cfg {boolean} [selectMin=true] Whether to select 'min', false would select 'max'
27 */
28 mw.widgets.SizeFilterWidget = function MwWidgetsSizeFilterWidget( config ) {
29 // Config initialization
30 config = $.extend( { selectMin: true }, config );
31 config.textinput = $.extend( {
32 type: 'number'
33 }, config.textinput );
34 config.radioselectinput = $.extend( {
35 options: [
36 { data: 'min', label: mw.msg( 'minimum-size' ) },
37 { data: 'max', label: mw.msg( 'maximum-size' ) }
38 ]
39 }, config.radioselectinput );
40
41 // Properties
42 this.radioselectinput = new OO.ui.RadioSelectInputWidget( config.radioselectinput );
43 this.textinput = new OO.ui.TextInputWidget( config.textinput );
44 this.label = new OO.ui.LabelWidget( { label: mw.msg( 'pagesize' ) } );
45
46 // Parent constructor
47 mw.widgets.SizeFilterWidget.parent.call( this, config );
48
49 // Initialization
50 this.radioselectinput.setValue( config.selectMin ? 'min' : 'max' );
51 this.$element
52 .addClass( 'mw-widget-sizeFilterWidget' )
53 .append(
54 this.radioselectinput.$element,
55 this.textinput.$element,
56 this.label.$element
57 );
58 };
59
60 /* Setup */
61 OO.inheritClass( mw.widgets.SizeFilterWidget, OO.ui.Widget );
62
63 /* Static Methods */
64
65 /**
66 * @inheritdoc
67 */
68 mw.widgets.SizeFilterWidget.static.reusePreInfuseDOM = function ( node, config ) {
69 config = mw.widgets.SizeFilterWidget.parent.static.reusePreInfuseDOM( node, config );
70 config.radioselectinput = OO.ui.RadioSelectInputWidget.static.reusePreInfuseDOM(
71 $( node ).find( '.oo-ui-radioSelectInputWidget' ),
72 config.radioselectinput
73 );
74 config.textinput = OO.ui.TextInputWidget.static.reusePreInfuseDOM(
75 $( node ).find( '.oo-ui-textInputWidget' ),
76 config.textinput
77 );
78 return config;
79 };
80
81 /**
82 * @inheritdoc
83 */
84 mw.widgets.SizeFilterWidget.static.gatherPreInfuseState = function ( node, config ) {
85 var state = mw.widgets.SizeFilterWidget.parent.static.gatherPreInfuseState( node, config );
86 state.radioselectinput = OO.ui.RadioSelectInputWidget.static.gatherPreInfuseState(
87 $( node ).find( '.oo-ui-radioSelectInputWidget' ),
88 config.radioselectinput
89 );
90 state.textinput = OO.ui.TextInputWidget.static.gatherPreInfuseState(
91 $( node ).find( '.oo-ui-textInputWidget' ),
92 config.textinput
93 );
94 return state;
95 };
96
97 /* Methods */
98
99 /**
100 * @inheritdoc
101 */
102 mw.widgets.SizeFilterWidget.prototype.restorePreInfuseState = function ( state ) {
103 mw.widgets.SizeFilterWidget.parent.prototype.restorePreInfuseState.call( this, state );
104 this.radioselectinput.restorePreInfuseState( state.radioselectinput );
105 this.textinput.restorePreInfuseState( state.textinput );
106 };
107
108 }() );