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',
43 filterMode
: 'substring'
48 selected
: config
&& config
.selected
? config
.selected
.map( function ( id
) {
51 label
: namespaces
[ id
]
59 .addClass( 'mw-widgets-namespacesMultiselectWidget' );
61 if ( 'name' in config
) {
62 // Use this instead of <input type="hidden">, because hidden inputs do not have separate
63 // 'value' and 'defaultValue' properties. The script on Special:Preferences
64 // (mw.special.preferences.confirmClose) checks this property to see if a field was changed.
65 this.hiddenInput
= $( '<textarea>' )
66 .addClass( 'oo-ui-element-hidden' )
67 .attr( 'name', config
.name
)
68 .appendTo( this.$element
);
69 // Update with preset values
70 // Set the default value (it might be different from just being empty)
71 this.hiddenInput
.prop( 'defaultValue', this.getItems().map( function ( item
) {
72 return item
.getData();
74 this.on( 'change', function ( items
) {
75 this.hiddenInput
.val( items
.map( function ( item
) {
76 return item
.getData();
78 // Trigger a 'change' event as if a user edited the text
79 // (it is not triggered when changing the value from JS code).
80 this.hiddenInput
.trigger( 'change' );
87 OO
.inheritClass( mw
.widgets
.NamespacesMultiselectWidget
, OO
.ui
.MenuTagMultiselectWidget
);
88 OO
.mixinClass( mw
.widgets
.NamespacesMultiselectWidget
, OO
.ui
.mixin
.PendingElement
);
95 mw
.widgets
.NamespacesMultiselectWidget
.prototype.createMenuOptionWidget = function ( data
, label
, icon
) {
96 return new mw
.widgets
.NamespacesMenuOptionWidget( {