1f526e254cc76ee1b45c9b880c0246f02cf19f4c
2 * MediaWiki Widgets - SearchInputWidget class.
4 * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
10 * Creates a mw.widgets.SearchInputWidget object.
13 * @extends mw.widgets.TitleInputWidget
16 * @cfg {boolean} [pushPending=true] Visually mark the input field as "pending", while
17 * requesting suggestions.
19 mw
.widgets
.SearchInputWidget
= function MwWidgetsSearchInputWidget( config
) {
27 mw
.widgets
.SearchInputWidget
.parent
.call( this, config
);
30 this.$element
.addClass( 'mw-widget-searchInputWidget' );
31 this.lookupMenu
.$element
.addClass( 'mw-widget-searchWidget-menu' );
32 if ( !config
.pushPending
) {
33 this.pushPending
= false;
35 this.setLookupsDisabled( !this.suggestions
);
40 OO
.inheritClass( mw
.widgets
.SearchInputWidget
, mw
.widgets
.TitleInputWidget
);
45 * @inheritdoc mw.widgets.TitleWidget
47 mw
.widgets
.SearchInputWidget
.prototype.getSuggestionsPromise = function () {
48 var api
= new mw
.Api();
50 // reuse the searchSuggest function from mw.searchSuggest
51 return mw
.searchSuggest
.request( api
, this.getQueryValue(), $.noop
, this.limit
);
55 * @inheritdoc mw.widgets.TitleInputWidget
57 mw
.widgets
.SearchInputWidget
.prototype.getLookupCacheDataFromResponse = function ( response
) {
58 // mw.widgets.TitleInputWidget uses response.query, which doesn't exist for opensearch,
59 // so return the whole response (titles only, and links)
60 return response
|| {};
64 * @inheritdoc mw.widgets.TitleWidget
66 mw
.widgets
.SearchInputWidget
.prototype.getOptionsFromData = function ( data
) {
70 // mw.widgets.TitleWidget does a lot more work here, because the TitleOptionWidgets can
71 // differ a lot, depending on the returned data from the request. With the request used here
72 // we get only the search results.
73 $.each( data
[ 1 ], function ( i
, result
) {
74 items
.push( new mw
.widgets
.TitleOptionWidget(
75 // data[ 3 ][ i ] is the link for this result
76 self
.getOptionWidgetData( result
, null, data
[ 3 ][ i
] )
80 mw
.track( 'mw.widgets.SearchInputWidget', {
81 action
: 'impression-results',
82 numberOfResults
: items
.length
,
83 resultSetType
: mw
.searchSuggest
.type
90 * @inheritdoc mw.widgets.TitleWidget
92 * @param {string} title
93 * @param {Object} data
94 * @param {string} url The Url to the result
96 mw
.widgets
.SearchInputWidget
.prototype.getOptionWidgetData = function ( title
, data
, url
) {
97 // the values used in mw.widgets-TitleWidget doesn't exist here, that's why
98 // the values are hard-coded here
106 disambiguation
: false,
107 query
: this.getQueryValue()
111 }( jQuery
, mediaWiki
) );