SearchInputWidget: Pass through description data
authorEd Sanders <esanders@wikimedia.org>
Mon, 9 Oct 2017 08:54:29 +0000 (09:54 +0100)
committerEd Sanders <esanders@wikimedia.org>
Mon, 9 Oct 2017 08:54:29 +0000 (09:54 +0100)
Also make result-parsing code clearer.

Change-Id: Ibf90ba3fc330f442606f243855721182701f7c02

resources/src/mediawiki.widgets/mw.widgets.SearchInputWidget.js

index 8707bfa..e73f347 100644 (file)
         */
        mw.widgets.SearchInputWidget.prototype.getOptionsFromData = function ( data ) {
                var items = [],
+                       titles = data.data[ 1 ],
+                       descriptions = data.data[ 2 ],
+                       urls = data.data[ 3 ],
                        self = this;
 
-               $.each( data.data[ 1 ], function ( i, result ) {
+               $.each( titles, function ( i, result ) {
                        items.push( new mw.widgets.TitleOptionWidget(
                                self.getOptionWidgetData(
                                        result,
                                        // the parent's API query.
                                        {
                                                data: result,
-                                               // data[ 3 ][ i ] is the link for this result
-                                               url: data.data[ 3 ][ i ],
-                                               imageUrl: null,
-                                               description: null,
+                                               url: urls[ i ],
+                                               imageUrl: null, // The JSON 'opensearch' API doesn't have images
+                                               description: descriptions[ i ],
                                                missing: false,
                                                redirect: false,
                                                disambiguation: false