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
.FloatingMenuSelectWidget
= function MwRcfiltersUiFloatingMenuSelectWidget( 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-floatingMenuSelectWidget-body' );
29 mw
.rcfilters
.ui
.FloatingMenuSelectWidget
.parent
.call( this, $.extend( {
30 $autoCloseIgnore
: this.$overlay
,
35 .addClass( 'mw-rcfilters-ui-floatingMenuSelectWidget-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-floatingMenuSelectWidget-noresults' ]
54 .addClass( 'mw-rcfilters-ui-floatingMenuSelectWidget' )
55 .append( header
.$element
)
58 .append( this.$group
, this.noResults
.$element
)
64 .addClass( 'mw-rcfilters-ui-floatingMenuSelectWidget-footer' )
71 OO
.inheritClass( mw
.rcfilters
.ui
.FloatingMenuSelectWidget
, OO
.ui
.FloatingMenuSelectWidget
);
76 * @event itemVisibilityChange
78 * Item visibility has changed
84 * @fires itemVisibilityChange
87 mw
.rcfilters
.ui
.FloatingMenuSelectWidget
.prototype.updateItemVisibility = function () {
89 itemWasHighlighted
= false,
90 inputVal
= this.$input
.val(),
91 items
= this.getItems();
93 // Since the method hides/shows items, we don't want to
94 // call it unless the input actually changed
95 if ( this.inputValue
!== inputVal
) {
97 mw
.rcfilters
.ui
.FloatingMenuSelectWidget
.parent
.prototype.updateItemVisibility
.call( this );
99 if ( inputVal
!== '' ) {
100 // Highlight the first item in the list
101 for ( i
= 0; i
< items
.length
; i
++ ) {
103 !( items
[ i
] instanceof OO
.ui
.MenuSectionOptionWidget
) &&
104 items
[ i
].isVisible()
106 itemWasHighlighted
= true;
107 this.highlightItem( items
[ i
] );
113 if ( !itemWasHighlighted
) {
114 this.highlightItem( null );
118 this.inputValue
= inputVal
;
120 this.emit( 'itemVisibilityChange' );
125 * Override the item matcher to use the model's match process
129 mw
.rcfilters
.ui
.FloatingMenuSelectWidget
.prototype.getItemMatcher = function ( s
) {
130 var results
= this.model
.findMatches( s
, true );
132 return function ( item
) {
133 return results
.indexOf( item
.getModel() ) > -1;
138 * Scroll to the top of the menu
140 mw
.rcfilters
.ui
.FloatingMenuSelectWidget
.prototype.scrollToTop = function () {
141 this.$body
.scrollTop( 0 );