Merge "phpunit: Avoid use of deprecated getMock for PHPUnit 5 compat"
[lhc/web/wiklou.git] / resources / src / mediawiki.rcfilters / ui / mw.rcfilters.ui.FilterWrapperWidget.js
index 7da97a1..c81b685 100644 (file)
@@ -56,7 +56,8 @@
                                $content: this.filterPopup.$element,
                                $footer: $footer,
                                classes: [ 'mw-rcfilters-ui-filterWrapperWidget-popup' ],
-                               width: 650
+                               width: 650,
+                               hideWhenOutOfView: false
                        }
                } );
 
                        enter: 'onTextInputEnter'
                } );
                this.capsule.connect( this, { capsuleItemClick: 'onCapsuleItemClick' } );
-               this.capsule.popup.connect( this, { toggle: 'onCapsulePopupToggle' } );
+               this.capsule.popup.connect( this, {
+                       toggle: 'onCapsulePopupToggle',
+                       ready: 'onCapsulePopupReady'
+               } );
 
                // Initialize
                this.$element
                        .addClass( 'mw-rcfilters-ui-filterWrapperWidget' )
-                       .addClass( 'mw-rcfilters-ui-ready' )
                        .append( this.capsule.$element, this.textInput.$element );
        };
 
                this.filterPopup.select( filterName );
                this.capsule.select( item );
 
+               this.capsule.popup.toggle( true );
                this.scrollToTop( filterWidget.$element );
        };
 
+       /**
+        * Respond to capsule popup ready event, fired after the popup is visible, positioned and clipped
+        */
+       mw.rcfilters.ui.FilterWrapperWidget.prototype.onCapsulePopupReady = function () {
+               mw.hook( 'RcFilters.popup.open' ).fire( this.filterPopup.getSelectedFilter() );
+
+               this.scrollToTop( this.capsule.$element, 10 );
+               if ( !this.filterPopup.getSelectedFilter() ) {
+                       // No selection, scroll the popup list to top
+                       setTimeout( function () { this.capsule.popup.$body.scrollTop( 0 ); }.bind( this ), 0 );
+               }
+       };
+
        /**
         * Respond to popup toggle event. Reset selection in the list when the popup is closed.
         *
         * @param {boolean} isVisible Popup is visible
         */
        mw.rcfilters.ui.FilterWrapperWidget.prototype.onCapsulePopupToggle = function ( isVisible ) {
-               if ( !isVisible ) {
-                       if ( !this.textInput.getValue() ) {
-                               // Only reset selection if we are not filtering
-                               this.filterPopup.resetSelection();
-                               this.capsule.resetSelection();
-                       }
-               } else {
-                       this.scrollToTop( this.capsule.$element, 10 );
+               if ( !isVisible && !this.textInput.getValue() ) {
+                       // Only reset selection if we are not filtering
+                       this.filterPopup.resetSelection();
+                       this.capsule.resetSelection();
                }
        };
 
         */
        mw.rcfilters.ui.FilterWrapperWidget.prototype.scrollToTop = function ( $element, marginFromTop ) {
                var container = OO.ui.Element.static.getClosestScrollableContainer( $element[ 0 ], 'y' ),
-                       pos = OO.ui.Element.static.getRelativePosition( $element, $( container ) );
+                       pos = OO.ui.Element.static.getRelativePosition( $element, $( container ) ),
+                       containerScrollTop = $( container ).is( 'body, html' ) ? 0 : $( container ).scrollTop();
 
                // Scroll to item
                $( container ).animate( {
-                       scrollTop: $( container ).scrollTop() + pos.top + ( marginFromTop || 0 )
+                       scrollTop: containerScrollTop + pos.top - ( marginFromTop || 0 )
                } );
        };
 }( mediaWiki ) );