Merge "Add parameter to API modules to apply change tags to log entries"
[lhc/web/wiklou.git] / resources / src / mediawiki.rcfilters / ui / mw.rcfilters.ui.FilterCapsuleMultiselectWidget.js
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 ) );
16
17 this.filterInput = filterInput;
18
19 this.$content.prepend(
20 $( '<div>' )
21 .addClass( 'mw-rcfilters-ui-filterCapsuleMultiselectWidget-content-title' )
22 .text( mw.msg( 'rcfilters-activefilters' ) )
23 );
24
25 // Events
26 // Add the filterInput as trigger
27 this.filterInput.$input
28 .on( 'focus', this.onFocusForPopup.bind( this ) );
29
30 this.$element
31 .addClass( 'mw-rcfilters-ui-filterCapsuleMultiselectWidget' );
32 };
33
34 /* Initialization */
35
36 OO.inheritClass( mw.rcfilters.ui.FilterCapsuleMultiselectWidget, OO.ui.CapsuleMultiselectWidget );
37
38 /* Events */
39
40 /**
41 * @event remove
42 * @param {string[]} filters Array of names of removed filters
43 *
44 * Filters were removed
45 */
46
47 /* Methods */
48
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 };
59
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 );
66
67 this.emit( 'remove', items.map( function ( item ) { return item.getData(); } ) );
68 };
69
70 /**
71 * @inheritdoc
72 */
73 mw.rcfilters.ui.FilterCapsuleMultiselectWidget.prototype.onKeyDown = function () {};
74
75 /**
76 * @inheritdoc
77 */
78 mw.rcfilters.ui.FilterCapsuleMultiselectWidget.prototype.onPopupFocusOut = function () {};
79
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 ) );