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 mw.widgets.TitleWidget
18 mw.widgets.TitleSearchWidget = function MwWidgetsTitleSearchWidget( config ) {
19 config = config || {};
22 mw.widgets.TitleSearchWidget.parent.call( this, config );
25 mw.widgets.TitleWidget.call( this, config );
27 this.query.setValidation( this.isQueryValid.bind( this ) );
30 this.results.connect( this, { choose: 'onTitleSearchResultsChoose' } );
33 this.$element.addClass( 'mw-widget-titleSearchWidget' );
34 this.results.$element.addClass( 'mw-widget-titleWidget-menu' );
35 if ( this.showImages ) {
36 this.results.$element.addClass( 'mw-widget-titleWidget-menu-withImages' );
38 if ( this.showDescriptions ) {
39 this.results.$element.addClass( 'mw-widget-titleWidget-menu-withDescriptions' );
41 if ( this.maxLength !== undefined ) {
42 this.getQuery().$input.attr( 'maxlength', this.maxLength );
48 OO.inheritClass( mw.widgets.TitleSearchWidget, OO.ui.SearchWidget );
49 OO.mixinClass( mw.widgets.TitleSearchWidget, mw.widgets.TitleWidget );
54 * @inheritdoc mw.widgets.TitleWidget
56 mw.widgets.TitleSearchWidget.prototype.getQueryValue = function () {
57 return this.getQuery().getValue();
61 * Handle choose events from the result widget
63 * @param {OO.ui.OptionWidget} item Chosen item
65 mw.widgets.TitleSearchWidget.prototype.onTitleSearchResultsChoose = function ( item ) {
66 // TOOD: Pressing enter can incorrectly trigger 'choose' with null.
67 // Remove this check when oojs-ui 0.12.10 lands.
69 this.getQuery().setValue( item.getData() );
76 mw.widgets.TitleSearchWidget.prototype.onQueryChange = function () {
79 this.getSuggestionsPromise().done( function ( response ) {
81 mw.widgets.TitleSearchWidget.parent.prototype.onQueryChange.call( widget );
83 widget.results.addItems( widget.getOptionsFromData( response.query || {} ) );
87 }( jQuery, mediaWiki ) );