Merge "RCFilters: Use findRelativeSelectableItem instead of getRelativeSelectableitem"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 21 Sep 2017 18:21:19 +0000 (18:21 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 21 Sep 2017 18:21:19 +0000 (18:21 +0000)
1  2 
resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.MenuSelectWidget.js

@@@ -32,7 -32,6 +32,7 @@@
                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' );
        };
  
        /**
 -       * 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
         *
         * @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 ];
                                case OO.ui.Keys.UP:
                                case OO.ui.Keys.LEFT:
                                        // Get the next item
-                                       nextItem = this.getRelativeSelectableItem( currentItem, -1 );
+                                       nextItem = this.findRelativeSelectableItem( currentItem, -1 );
                                        break;
                                case OO.ui.Keys.DOWN:
                                case OO.ui.Keys.RIGHT:
                                        // Get the next item
-                                       nextItem = this.getRelativeSelectableItem( currentItem, 1 );
+                                       nextItem = this.findRelativeSelectableItem( currentItem, 1 );
                                        break;
                        }