RCFilters: Don't emit wikipage.content on first load
authorMoriel Schottlender <moriel@gmail.com>
Mon, 17 Jul 2017 21:38:58 +0000 (14:38 -0700)
committerRoan Kattouw <roan.kattouw@gmail.com>
Tue, 18 Jul 2017 23:08:45 +0000 (16:08 -0700)
If the first load uses existing DOM elements, don't emit that
hook. Only emit if we're pulling from the server for new results.

Bug: T165350
Change-Id: Ib17fdd16a908808f99fe8506c50c61d90ad4addc

resources/src/mediawiki.rcfilters/dm/mw.rcfilters.dm.ChangesListViewModel.js
resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js
resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.ChangesListWrapperWidget.js
resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.FormWrapperWidget.js

index c839a13..49c0b82 100644 (file)
         *
         * @param {jQuery|string} changesListContent
         * @param {jQuery} $fieldset
+        * @param {boolean} [isInitialDOM] Using the initial (already attached) DOM elements
         */
-       mw.rcfilters.dm.ChangesListViewModel.prototype.update = function ( changesListContent, $fieldset ) {
+       mw.rcfilters.dm.ChangesListViewModel.prototype.update = function ( changesListContent, $fieldset, isInitialDOM ) {
                this.valid = true;
-               this.emit( 'update', changesListContent, $fieldset );
+               this.emit( 'update', changesListContent, $fieldset, isInitialDOM );
        };
 
 }( mediaWiki ) );
index 5858566..0abfb34 100644 (file)
                        // so it gets processed
                        this.changesListModel.update(
                                $changesList.length ? $changesList : 'NO_RESULTS',
-                               $( 'fieldset.rcoptions' ).first()
+                               $( 'fieldset.rcoptions' ).first(),
+                               true // We're using existing DOM elements
                        );
                }
 
index 843acce..6512f04 100644 (file)
         * Respond to changes list model update
         *
         * @param {jQuery|string} $changesListContent The content of the updated changes list
+        * @param {jQuery} $fieldset The content of the updated fieldset
+        * @param {boolean} isInitialDOM Whether $changesListContent is the existing (already attached) DOM
         */
-       mw.rcfilters.ui.ChangesListWrapperWidget.prototype.onModelUpdate = function ( $changesListContent ) {
+       mw.rcfilters.ui.ChangesListWrapperWidget.prototype.onModelUpdate = function ( $changesListContent, $fieldset, isInitialDOM ) {
                var conflictItem,
                        $message = $( '<div>' )
                                .addClass( 'mw-rcfilters-ui-changesListWrapperWidget-results' ),
                        // Apply highlight
                        this.applyHighlight();
 
-                       // Make sure enhanced RC re-initializes correctly
-                       mw.hook( 'wikipage.content' ).fire( this.$element );
+                       if ( !isInitialDOM ) {
+                               // Make sure enhanced RC re-initializes correctly
+                               mw.hook( 'wikipage.content' ).fire( this.$element );
+                       }
                }
                this.popPending();
        };
index dbee65c..9c82451 100644 (file)
         *
         * @param {jQuery|string} $changesList Updated changes list
         * @param {jQuery} $fieldset Updated fieldset
+        * @param {boolean} isInitialDOM Whether $changesListContent is the existing (already attached) DOM
         */
-       mw.rcfilters.ui.FormWrapperWidget.prototype.onChangesModelUpdate = function ( $changesList, $fieldset ) {
+       mw.rcfilters.ui.FormWrapperWidget.prototype.onChangesModelUpdate = function ( $changesList, $fieldset, isInitialDOM ) {
                this.$submitButton.prop( 'disabled', false );
 
                // Replace the entire fieldset
                this.$element.empty().append( $fieldset.contents() );
-               // Make sure enhanced RC re-initializes correctly
-               mw.hook( 'wikipage.content' ).fire( this.$element );
+
+               if ( !isInitialDOM ) {
+                       // Make sure enhanced RC re-initializes correctly
+                       mw.hook( 'wikipage.content' ).fire( this.$element );
+               }
 
                this.cleanUpFieldset();