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
19 mw
.widgets
.TitleSearchWidget
= function MwWidgetsTitleSearchWidget( config
) {
20 config
= config
|| {};
23 mw
.widgets
.TitleSearchWidget
.parent
.call( this, config
);
26 mw
.widgets
.TitleWidget
.call( this, config
);
27 OO
.ui
.mixin
.RequestManager
.call( this, config
);
29 this.query
.setValidation( this.isQueryValid
.bind( this ) );
32 this.results
.connect( this, { choose
: 'onTitleSearchResultsChoose' } );
35 this.$element
.addClass( 'mw-widget-titleSearchWidget' );
36 this.results
.$element
.addClass( 'mw-widget-titleWidget-menu' );
37 if ( this.showImages
) {
38 this.results
.$element
.addClass( 'mw-widget-titleWidget-menu-withImages' );
40 if ( this.showDescriptions
) {
41 this.results
.$element
.addClass( 'mw-widget-titleWidget-menu-withDescriptions' );
43 if ( this.maxLength
!== undefined ) {
44 this.getQuery().$input
.attr( 'maxlength', this.maxLength
);
50 OO
.inheritClass( mw
.widgets
.TitleSearchWidget
, OO
.ui
.SearchWidget
);
51 OO
.mixinClass( mw
.widgets
.TitleSearchWidget
, OO
.ui
.mixin
.RequestManager
);
52 OO
.mixinClass( mw
.widgets
.TitleSearchWidget
, mw
.widgets
.TitleWidget
);
57 * @inheritdoc mw.widgets.TitleWidget
59 mw
.widgets
.TitleSearchWidget
.prototype.getQueryValue = function () {
60 return this.getQuery().getValue();
64 * Handle choose events from the result widget
66 * @param {OO.ui.OptionWidget} item Chosen item
68 mw
.widgets
.TitleSearchWidget
.prototype.onTitleSearchResultsChoose = function ( item
) {
69 this.getQuery().setValue( item
.getData() );
75 mw
.widgets
.TitleSearchWidget
.prototype.onQueryChange = function () {
78 this.getRequestData().done( function ( data
) {
80 mw
.widgets
.TitleSearchWidget
.parent
.prototype.onQueryChange
.call( widget
);
81 widget
.results
.addItems( widget
.getOptionsFromData( data
) );
86 * @inheritdoc OO.ui.mixin.RequestManager
88 mw
.widgets
.TitleSearchWidget
.prototype.getRequestQuery = function () {
89 return this.getQueryValue();
92 * @inheritdoc OO.ui.mixin.RequestManager
94 mw
.widgets
.TitleSearchWidget
.prototype.getRequest = function () {
95 return this.getSuggestionsPromise();
98 * @inheritdoc OO.ui.mixin.RequestManager
100 mw
.widgets
.TitleSearchWidget
.prototype.getRequestCacheDataFromResponse = function ( response
) {
101 return response
.query
|| {};
104 }( jQuery
, mediaWiki
) );