Merge "apisandbox.js: Use findFirstSelectableitem instead of getFirstSelectableItem"
[lhc/web/wiklou.git] / resources / src / mediawiki.rcfilters / ui / mw.rcfilters.ui.MenuSelectWidget.js
index c12e10e..5ba42e7 100644 (file)
                this.views = {};
                this.userSelecting = false;
 
+               this.menuInitialized = false;
                this.inputValue = '';
                this.$overlay = config.$overlay || this.$element;
-               this.$body = $( '<div>' )
-                               .addClass( 'mw-rcfilters-ui-menuSelectWidget-body' );
+               this.$body = $( '<div>' ).addClass( 'mw-rcfilters-ui-menuSelectWidget-body' );
                this.footers = [];
 
                // Parent
                                        views: footerData.views
                                };
 
-                       this.footers.push( adjustedData );
+                       if ( !footerData.disabled ) {
+                               this.footers.push( adjustedData );
 
-                       if ( isSticky ) {
-                               this.$element.append( adjustedData.$element );
-                       } else {
-                               this.$body.append( adjustedData.$element );
+                               if ( isSticky ) {
+                                       this.$element.append( adjustedData.$element );
+                               } else {
+                                       this.$body.append( adjustedData.$element );
+                               }
                        }
                }.bind( this ) );
 
        };
 
        /**
-        * Respond to model initialize event. Populate the menu from the model
+        * @inheritdoc
         */
-       mw.rcfilters.ui.MenuSelectWidget.prototype.onModelInitialize = function () {
+       mw.rcfilters.ui.MenuSelectWidget.prototype.toggle = function ( show ) {
+               this.lazyMenuCreation();
+               mw.rcfilters.ui.MenuSelectWidget.parent.prototype.toggle.call( this, show );
+       };
+
+       /**
+        * lazy creation of the menu
+        */
+       mw.rcfilters.ui.MenuSelectWidget.prototype.lazyMenuCreation = function () {
                var widget = this,
                        viewGroupCount = {},
                        groups = this.model.getFilterGroups();
 
+               if ( this.menuInitialized ) {
+                       return;
+               }
+
+               this.menuInitialized = true;
                // Reset
                this.clearItems();
 
                this.switchView( this.model.getCurrentView() );
        };
 
+       /**
+        * Respond to model initialize event. Populate the menu from the model
+        */
+       mw.rcfilters.ui.MenuSelectWidget.prototype.onModelInitialize = function () {
+               this.menuInitialized = false;
+       };
+
        /**
         * Switch view
         *
                                .addClass( 'mw-rcfilters-ui-menuSelectWidget-view-' + viewName );
 
                        this.currentView = viewName;
+                       this.scrollToTop();
                        this.clip();
                }
        };
 
                        this.emit( 'itemVisibilityChange' );
                }
+
+               this.noResults.toggle( !this.getItems().some( function ( item ) {
+                       return item.isVisible();
+               } ) );
        };
 
        /**
         * @return {mw.rcfilters.ui.ItemMenuOptionWidget} Option widget
         */
        mw.rcfilters.ui.MenuSelectWidget.prototype.getItemFromModel = function ( model ) {
+               this.lazyMenuCreation();
                return this.views[ model.getGroupModel().getView() ].filter( function ( item ) {
                        return item.getName() === model.getName();
                } )[ 0 ];