3 * A floating menu widget for the filter list
5 * @extends OO.ui.FloatingMenuSelectWidget
8 * @param {mw.rcfilters.Controller} controller Controller
9 * @param {mw.rcfilters.dm.FiltersViewModel} model View model
10 * @param {Object} [config] Configuration object
11 * @cfg {jQuery} [$overlay] A jQuery object serving as overlay for popups
12 * @cfg {jQuery} [$footer] An optional footer for the menu
14 mw
.rcfilters
.ui
.FilterFloatingMenuSelectWidget
= function MwRcfiltersUiFilterFloatingMenuSelectWidget( controller
, model
, config
) {
17 config
= config
|| {};
19 this.controller
= controller
;
23 this.$overlay
= config
.$overlay
|| this.$element
;
24 this.$footer
= config
.$footer
;
25 this.$body
= $( '<div>' )
26 .addClass( 'mw-rcfilters-ui-filterFloatingMenuSelectWidget-body' );
29 mw
.rcfilters
.ui
.FilterFloatingMenuSelectWidget
.parent
.call( this, $.extend( {
30 $autoCloseIgnore
: this.$overlay
,
35 .addClass( 'mw-rcfilters-ui-filterFloatingMenuSelectWidget-group' )
37 this.setClippableElement( this.$body
);
38 this.setClippableContainer( this.$element
);
40 header
= new mw
.rcfilters
.ui
.FilterMenuHeaderWidget(
44 $overlay
: this.$overlay
48 this.noResults
= new OO
.ui
.LabelWidget( {
49 label
: mw
.msg( 'rcfilters-filterlist-noresults' ),
50 classes
: [ 'mw-rcfilters-ui-filterFloatingMenuSelectWidget-noresults' ]
54 .addClass( 'mw-rcfilters-ui-filterFloatingMenuSelectWidget' )
57 .append( header
.$element
, this.$group
, this.noResults
.$element
)
63 .addClass( 'mw-rcfilters-ui-filterFloatingMenuSelectWidget-footer' )
70 OO
.inheritClass( mw
.rcfilters
.ui
.FilterFloatingMenuSelectWidget
, OO
.ui
.FloatingMenuSelectWidget
);
75 * @event itemVisibilityChange
77 * Item visibility has changed
83 * @fires itemVisibilityChange
86 mw
.rcfilters
.ui
.FilterFloatingMenuSelectWidget
.prototype.updateItemVisibility = function () {
88 itemWasHighlighted
= false,
89 inputVal
= this.$input
.val(),
90 items
= this.getItems();
92 // Since the method hides/shows items, we don't want to
93 // call it unless the input actually changed
94 if ( this.inputValue
!== inputVal
) {
96 mw
.rcfilters
.ui
.FilterFloatingMenuSelectWidget
.parent
.prototype.updateItemVisibility
.call( this );
98 if ( inputVal
!== '' ) {
99 // Highlight the first item in the list
100 for ( i
= 0; i
< items
.length
; i
++ ) {
102 !( items
[ i
] instanceof OO
.ui
.MenuSectionOptionWidget
) &&
103 items
[ i
].isVisible()
105 itemWasHighlighted
= true;
106 this.highlightItem( items
[ i
] );
112 if ( !itemWasHighlighted
) {
113 this.highlightItem( null );
117 this.inputValue
= inputVal
;
119 this.emit( 'itemVisibilityChange' );
124 * Override the item matcher to use the model's match process
128 mw
.rcfilters
.ui
.FilterFloatingMenuSelectWidget
.prototype.getItemMatcher = function ( s
) {
129 var results
= this.model
.findMatches( s
, true );
131 return function ( item
) {
132 return results
.indexOf( item
.getModel() ) > -1;
137 * Scroll to the top of the menu
139 mw
.rcfilters
.ui
.FilterFloatingMenuSelectWidget
.prototype.scrollToTop = function () {
140 this.$body
.scrollTop( 0 );