Debian Codegraph @

resources/src/mediawiki.widgets/mw.widgets.SizeFilterWidget.js

raw symbols SCIP
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 * @classdesc Size filter widget.
11 *
12 * @example
13 * mw.loader.using( 'mediawiki.widgets.SizeFilterWidget', function () {
14 * let sf = new mw.widgets.SizeFilterWidget();
15 * $( document.body ).append( sf.$element );
16 * } );
17 *
18 * @class mw.widgets.SizeFilterWidget
19 * @extends OO.ui.Widget
20 * @uses OO.ui.RadioSelectInputWidget
21 * @uses OO.ui.TextInputWidget
22 *
23 * @constructor
24 * @description Use a RadioSelectInputWidget and a TextInputWidget to set minimum or maximum byte size.
25 * @param {Object} [config] Configuration options
26 * @param {Object} [config.radioselectinput] Config for the radio select input
27 * @param {Object} [config.textinput] Config for the text input
28 * @param {boolean} [config.selectMin=true] Whether to select 'min', false would select 'max'
29 */
30 mw.widgets.SizeFilterWidget = function MwWidgetsSizeFilterWidget( config ) {
31 // Config initialization
32 config = Object.assign( { selectMin: true }, config );
33 config.textinput = Object.assign( {
34 type: 'number'
35 }, config.textinput );
36 config.radioselectinput = Object.assign( {
37 options: [
38 { data: 'min', label: mw.msg( 'minimum-size' ) },
39 { data: 'max', label: mw.msg( 'maximum-size' ) }
40 ]
41 }, config.radioselectinput );
42
43 // Properties
44 this.radioselectinput = new OO.ui.RadioSelectInputWidget( config.radioselectinput );
45 this.textinput = new OO.ui.TextInputWidget( config.textinput );
46 this.label = new OO.ui.LabelWidget( { label: mw.msg( 'pagesize' ) } );
47
48 // Parent constructor
49 mw.widgets.SizeFilterWidget.super.call( this, config );
50
51 // Initialization
52 this.radioselectinput.setValue( config.selectMin ? 'min' : 'max' );
53 this.$element
54 .addClass( 'mw-widget-sizeFilterWidget' )
55 .append(
56 this.radioselectinput.$element,
57 this.textinput.$element,
58 this.label.$element
59 );
60 };
61
62 /* Setup */
63 OO.inheritClass( mw.widgets.SizeFilterWidget, OO.ui.Widget );
64
65 /* Static Methods */
66
67 /**
68 * @inheritdoc
69 */
70 mw.widgets.SizeFilterWidget.static.reusePreInfuseDOM = function ( node, config ) {
71 config = mw.widgets.SizeFilterWidget.super.static.reusePreInfuseDOM( node, config );
72 config.radioselectinput = OO.ui.RadioSelectInputWidget.static.reusePreInfuseDOM(
73 $( node ).find( '.oo-ui-radioSelectInputWidget' ),
74 config.radioselectinput
75 );
76 config.textinput = OO.ui.TextInputWidget.static.reusePreInfuseDOM(
77 $( node ).find( '.oo-ui-textInputWidget' ),
78 config.textinput
79 );
80 return config;
81 };
82
83 /**
84 * @inheritdoc
85 */
86 mw.widgets.SizeFilterWidget.static.gatherPreInfuseState = function ( node, config ) {
87 const state = mw.widgets.SizeFilterWidget.super.static.gatherPreInfuseState( node, config );
88 state.radioselectinput = OO.ui.RadioSelectInputWidget.static.gatherPreInfuseState(
89 $( node ).find( '.oo-ui-radioSelectInputWidget' ),
90 config.radioselectinput
91 );
92 state.textinput = OO.ui.TextInputWidget.static.gatherPreInfuseState(
93 $( node ).find( '.oo-ui-textInputWidget' ),
94 config.textinput
95 );
96 return state;
97 };
98
99 /* Methods */
100
101 /**
102 * @inheritdoc
103 */
104 mw.widgets.SizeFilterWidget.prototype.restorePreInfuseState = function ( state ) {
105 mw.widgets.SizeFilterWidget.super.prototype.restorePreInfuseState.call( this, state );
106 this.radioselectinput.restorePreInfuseState( state.radioselectinput );
107 this.textinput.restorePreInfuseState( state.textinput );
108 };
109
110 }() );