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
49 .addClass( 'mw-rcfilters-ui-filterFloatingMenuSelectWidget' )
52 .append( header
.$element
, this.$group
)
58 .addClass( 'mw-rcfilters-ui-filterFloatingMenuSelectWidget-footer' )
65 OO
.inheritClass( mw
.rcfilters
.ui
.FilterFloatingMenuSelectWidget
, OO
.ui
.FloatingMenuSelectWidget
);
70 * @event itemVisibilityChange
72 * Item visibility has changed
78 * @fires itemVisibilityChange
81 mw
.rcfilters
.ui
.FilterFloatingMenuSelectWidget
.prototype.updateItemVisibility = function () {
83 itemWasHighlighted
= false,
84 inputVal
= this.$input
.val(),
85 items
= this.getItems();
87 // Since the method hides/shows items, we don't want to
88 // call it unless the input actually changed
89 if ( this.inputValue
!== inputVal
) {
91 mw
.rcfilters
.ui
.FilterFloatingMenuSelectWidget
.parent
.prototype.updateItemVisibility
.call( this );
93 if ( inputVal
!== '' ) {
94 // Highlight the first item in the list
95 for ( i
= 0; i
< items
.length
; i
++ ) {
97 !( items
[ i
] instanceof OO
.ui
.MenuSectionOptionWidget
) &&
98 items
[ i
].isVisible()
100 itemWasHighlighted
= true;
101 this.highlightItem( items
[ i
] );
107 if ( !itemWasHighlighted
) {
108 this.highlightItem( null );
112 this.inputValue
= inputVal
;
114 this.emit( 'itemVisibilityChange' );
119 * Override the item matcher to use the model's match process
123 mw
.rcfilters
.ui
.FilterFloatingMenuSelectWidget
.prototype.getItemMatcher = function ( s
) {
124 var results
= this.model
.findMatches( s
, true );
126 return function ( item
) {
127 return results
.indexOf( item
.getModel() ) > -1;
132 * Scroll to the top of the menu
134 mw
.rcfilters
.ui
.FilterFloatingMenuSelectWidget
.prototype.scrollToTop = function () {
135 this.$body
.scrollTop( 0 );