2 * MediaWiki Widgets - NamespacesMultiselectWidget class.
4 * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
10 * Creates an mw.widgets.NamespacesMultiselectWidget object
12 * TODO: A lot of this is duplicated in mw.widgets.UsersMultiselectWidget
13 * and mw.widgets.TitlesMultiselectWidget. These classes should be
17 * @extends OO.ui.MenuTagMultiselectWidget
20 * @param {Object} [config] Configuration options
22 mw
.widgets
.NamespacesMultiselectWidget
= function MwWidgetsNamespacesMultiselectWidget( config
) {
25 options
= mw
.widgets
.NamespaceInputWidget
.static.getNamespaceDropdownOptions( {} );
27 for ( i
= 0, ilen
= options
.length
; i
< ilen
; i
++ ) {
28 option
= options
[ i
];
29 namespaces
[ option
.data
] = option
.label
;
32 config
= $.extend( true, {
33 options
: mw
.widgets
.NamespaceInputWidget
.static.getNamespaceDropdownOptions( {} )
37 mw
.widgets
.NamespacesMultiselectWidget
.parent
.call( this, $.extend( true,
39 clearInputOnChoose
: true,
40 inputPosition
: 'inline',
45 selected
: config
&& config
.selected
? config
.selected
.map( function ( id
) {
48 label
: namespaces
[ id
]
56 .addClass( 'mw-widgets-namespacesMultiselectWidget' );
58 if ( 'name' in config
) {
59 // Use this instead of <input type="hidden">, because hidden inputs do not have separate
60 // 'value' and 'defaultValue' properties. The script on Special:Preferences
61 // (mw.special.preferences.confirmClose) checks this property to see if a field was changed.
62 this.hiddenInput
= $( '<textarea>' )
63 .addClass( 'oo-ui-element-hidden' )
64 .attr( 'name', config
.name
)
65 .appendTo( this.$element
);
66 // Update with preset values
67 // Set the default value (it might be different from just being empty)
68 this.hiddenInput
.prop( 'defaultValue', this.getItems().map( function ( item
) {
69 return item
.getData();
71 this.on( 'change', function ( items
) {
72 this.hiddenInput
.val( items
.map( function ( item
) {
73 return item
.getData();
75 // Trigger a 'change' event as if a user edited the text
76 // (it is not triggered when changing the value from JS code).
77 this.hiddenInput
.trigger( 'change' );
84 OO
.inheritClass( mw
.widgets
.NamespacesMultiselectWidget
, OO
.ui
.MenuTagMultiselectWidget
);
85 OO
.mixinClass( mw
.widgets
.NamespacesMultiselectWidget
, OO
.ui
.mixin
.PendingElement
);