2 * MediaWiki Widgets - TitleSearchWidget class.
4 * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
10 * Creates an mw.widgets.TitleSearchWidget object.
13 * @extends OO.ui.SearchWidget
14 * @mixins OO.ui.mixin.RequestManager
15 * @mixins mw.widgets.TitleWidget
18 * @param {Object} [config] Configuration options
20 mw
.widgets
.TitleSearchWidget
= function MwWidgetsTitleSearchWidget( config
) {
21 config
= config
|| {};
24 mw
.widgets
.TitleSearchWidget
.parent
.call( this, config
);
27 mw
.widgets
.TitleWidget
.call( this, config
);
28 OO
.ui
.mixin
.RequestManager
.call( this, config
);
30 this.query
.setValidation( this.isQueryValid
.bind( this ) );
33 this.results
.connect( this, { choose
: 'onTitleSearchResultsChoose' } );
36 this.$element
.addClass( 'mw-widget-titleSearchWidget' );
37 this.results
.$element
.addClass( 'mw-widget-titleWidget-menu' );
38 if ( this.showImages
) {
39 this.results
.$element
.addClass( 'mw-widget-titleWidget-menu-withImages' );
41 if ( this.showDescriptions
) {
42 this.results
.$element
.addClass( 'mw-widget-titleWidget-menu-withDescriptions' );
44 if ( this.maxLength
!== undefined ) {
45 this.getQuery().$input
.attr( 'maxlength', this.maxLength
);
51 OO
.inheritClass( mw
.widgets
.TitleSearchWidget
, OO
.ui
.SearchWidget
);
52 OO
.mixinClass( mw
.widgets
.TitleSearchWidget
, OO
.ui
.mixin
.RequestManager
);
53 OO
.mixinClass( mw
.widgets
.TitleSearchWidget
, mw
.widgets
.TitleWidget
);
58 * @inheritdoc mw.widgets.TitleWidget
60 mw
.widgets
.TitleSearchWidget
.prototype.getQueryValue = function () {
61 return this.getQuery().getValue();
65 * Handle choose events from the result widget
67 * @param {OO.ui.OptionWidget} item Chosen item
69 mw
.widgets
.TitleSearchWidget
.prototype.onTitleSearchResultsChoose = function ( item
) {
70 this.getQuery().setValue( item
.getData() );
76 mw
.widgets
.TitleSearchWidget
.prototype.onQueryChange = function () {
79 this.getRequestData().done( function ( data
) {
81 mw
.widgets
.TitleSearchWidget
.parent
.prototype.onQueryChange
.call( widget
);
82 widget
.results
.addItems( widget
.getOptionsFromData( data
) );
87 * @inheritdoc OO.ui.mixin.RequestManager
89 mw
.widgets
.TitleSearchWidget
.prototype.getRequestQuery = function () {
90 return this.getQueryValue();
93 * @inheritdoc OO.ui.mixin.RequestManager
95 mw
.widgets
.TitleSearchWidget
.prototype.getRequest = function () {
96 return this.getSuggestionsPromise();
99 * @inheritdoc OO.ui.mixin.RequestManager
101 mw
.widgets
.TitleSearchWidget
.prototype.getRequestCacheDataFromResponse = function ( response
) {
102 return response
.query
|| {};
105 }( jQuery
, mediaWiki
) );