Fix namespace handling for uncategorized-categories-exceptionlist
[mediawiki.git] / resources / src / mediawiki.rcfilters / ui / mw.rcfilters.ui.FilterCapsuleMultiselectWidget.js
blobdf6cf8b7d5576cde7d23c7303f8c04468cdc5ef2
1 ( function ( mw, $ ) {
2         /**
3          * Filter-specific CapsuleMultiselectWidget
4          *
5          * @extends OO.ui.CapsuleMultiselectWidget
6          *
7          * @constructor
8          * @param {OO.ui.InputWidget} filterInput A filter input that focuses the capsule widget
9          * @param {Object} config Configuration object
10          */
11         mw.rcfilters.ui.FilterCapsuleMultiselectWidget = function MwRcfiltersUiFilterCapsuleMultiselectWidget( filterInput, config ) {
12                 // Parent
13                 mw.rcfilters.ui.FilterCapsuleMultiselectWidget.parent.call( this, $.extend( {
14                         $autoCloseIgnore: filterInput.$element
15                 }, config ) );
17                 this.filterInput = filterInput;
19                 this.$content.prepend(
20                         $( '<div>' )
21                                 .addClass( 'mw-rcfilters-ui-filterCapsuleMultiselectWidget-content-title' )
22                                 .text( mw.msg( 'rcfilters-activefilters' ) )
23                 );
25                 // Events
26                 // Add the filterInput as trigger
27                 this.filterInput.$input
28                         .on( 'focus', this.onFocusForPopup.bind( this ) );
30                 this.$element
31                         .addClass( 'mw-rcfilters-ui-filterCapsuleMultiselectWidget' );
32         };
34         /* Initialization */
36         OO.inheritClass( mw.rcfilters.ui.FilterCapsuleMultiselectWidget, OO.ui.CapsuleMultiselectWidget );
38         /* Events */
40         /**
41          * @event remove
42          * @param {string[]} filters Array of names of removed filters
43          *
44          * Filters were removed
45          */
47         /* Methods */
49         /**
50          * @inheritdoc
51          */
52         mw.rcfilters.ui.FilterCapsuleMultiselectWidget.prototype.onFocusForPopup = function () {
53                 // Override this method; we don't want to focus on the popup, and we
54                 // don't want to bind the size to the handle.
55                 if ( !this.isDisabled() ) {
56                         this.popup.toggle( true );
57                 }
58         };
60         /**
61          * @inheritdoc
62          */
63         mw.rcfilters.ui.FilterCapsuleMultiselectWidget.prototype.removeItems = function ( items ) {
64                 // Parent
65                 mw.rcfilters.ui.FilterCapsuleMultiselectWidget.parent.prototype.removeItems.call( this, items );
67                 this.emit( 'remove', items.map( function ( item ) { return item.getData(); } ) );
68         };
70         /**
71          * @inheritdoc
72          */
73         mw.rcfilters.ui.FilterCapsuleMultiselectWidget.prototype.onKeyDown = function () {};
75         /**
76          * @inheritdoc
77          */
78         mw.rcfilters.ui.FilterCapsuleMultiselectWidget.prototype.onPopupFocusOut = function () {};
80         /**
81          * @inheritdoc
82          */
83         mw.rcfilters.ui.FilterCapsuleMultiselectWidget.prototype.clearInput = function () {
84                 if ( this.filterInput ) {
85                         this.filterInput.setValue( '' );
86                 }
87                 this.menu.toggle( false );
88                 this.menu.selectItem();
89                 this.menu.highlightItem();
90         };
91 }( mediaWiki, jQuery ) );