RCFilters UI: Update fieldset as in load
authorMoriel Schottlender <moriel@gmail.com>
Wed, 15 Mar 2017 21:31:23 +0000 (14:31 -0700)
committerCatrope <roan@wikimedia.org>
Thu, 16 Mar 2017 18:33:13 +0000 (18:33 +0000)
Duplicate the javascript used on load on the fieldset
to reproduce the collapse and namespace checkboxes/select
behavior.

Bug: T157594
Change-Id: I12946be6ed6cd7ef60e87fa3576fda42f7005fb6

resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.FormWrapperWidget.js

index d786025..d17ffff 100644 (file)
 
                // Replace the entire fieldset
                this.$element.empty().append( $fieldset.contents() );
+               // Make sure enhanced RC re-initializes correctly
+               mw.hook( 'wikipage.content' ).fire( this.$element );
 
                this.cleanUpFieldset();
 
         * Clean up the old-style show/hide that we have implemented in the filter list
         */
        mw.rcfilters.ui.FormWrapperWidget.prototype.cleanUpFieldset = function () {
+               var $namespaceSelect = this.$element.find( '#namespace' ),
+                       $namespaceCheckboxes = this.$element.find( '#nsassociated, #nsinvert' ),
+                       collapseCookieName = 'changeslist-state';
+
                this.$element.find( '.rcshowhideoption[data-feature-in-structured-ui=1]' ).each( function () {
                        // HACK: Remove the text node after the span.
                        // If there isn't one, we're at the end, so remove the text node before the span.
                        // Remove the span itself
                        this.parentNode.removeChild( this );
                } );
+
+               // Bind namespace select to change event
+               // see resources/src/mediawiki.special/mediawiki.special.recentchanges.js
+               $namespaceCheckboxes.prop( 'disabled', $namespaceSelect.val() === '' );
+               $namespaceSelect.on( 'change', function () {
+                       $namespaceCheckboxes.prop( 'disabled', $( this ).val() === '' );
+               } );
+
+               // Collapse legend
+               // see resources/src/mediawiki.special/mediawiki.special.changelist.legend.js
+               this.$element.find( '.mw-changeslist-legend' )
+                       .makeCollapsible( {
+                               collapsed: mw.cookie.get( collapseCookieName ) === 'collapsed'
+                       } )
+                       .on( 'beforeExpand.mw-collapsible', function () {
+                               mw.cookie.set( collapseCookieName, 'expanded' );
+                       } )
+                       .on( 'beforeCollapse.mw-collapsible', function () {
+                               mw.cookie.set( collapseCookieName, 'collapsed' );
+                       } );
+
        };
 }( mediaWiki ) );