MediaSearchWidget: Only resize new results
authorThalia <thalia.e.chan@googlemail.com>
Wed, 17 May 2017 17:13:17 +0000 (19:13 +0200)
committerThalia <thalia.e.chan@googlemail.com>
Fri, 19 May 2017 15:44:19 +0000 (17:44 +0200)
When repositioning images based on the "change" event,
ignore images that have already been assigned to a row.

Bug: T163727
Change-Id: Ida7556d8848f98d97d82aef9caf5c1d43bb47d7b

resources/src/mediawiki.widgets/MediaSearch/mw.widgets.MediaSearchWidget.js

index 5cbd2ec..1cc168a 100644 (file)
        };
 
        /**
-        * Respond to add results event in the results widget.
+        * Respond to change results event in the results widget.
         * Override the way SelectWidget and GroupElement append the items
         * into the group so we can append them in groups of rows.
         *
                        // Go over the added items
                        row = search.getAvailableRow();
                        for ( i = 0, ilen = items.length; i < ilen; i++ ) {
+
+                               // Check item has just been added
+                               if ( items[ i ].row !== null ) {
+                                       continue;
+                               }
+
                                itemWidth = items[ i ].$element.outerWidth( true );
 
                                // Add items to row until it is full
 
                                // Append the item
                                search.rows[ row ].$element.append( items[ i ].$element );
+
                        }
 
                        // If we have less than 4 rows, call for more images