2 * MediaWiki Widgets - TitleInputWidget 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.TitleInputWidget object.
13 * @extends OO.ui.TextInputWidget
14 * @mixins mw.widgets.TitleWidget
15 * @mixins OO.ui.mixin.LookupElement
18 * @cfg {boolean} [suggestions=true] Display search suggestions
20 mw
.widgets
.TitleInputWidget
= function MwWidgetsTitleInputWidget( config
) {
21 config
= config
|| {};
24 mw
.widgets
.TitleInputWidget
.parent
.call( this, $.extend( {}, config
, {
25 validate
: this.isQueryValid
.bind( this ),
30 mw
.widgets
.TitleWidget
.call( this, config
);
31 OO
.ui
.mixin
.LookupElement
.call( this, config
);
34 this.suggestions
= config
.suggestions
!== undefined ? config
.suggestions
: true;
37 this.$element
.addClass( 'mw-widget-titleInputWidget' );
38 this.lookupMenu
.$element
.addClass( 'mw-widget-titleWidget-menu' );
39 if ( this.showImages
) {
40 this.lookupMenu
.$element
.addClass( 'mw-widget-titleWidget-menu-withImages' );
42 if ( this.showDescriptions
) {
43 this.lookupMenu
.$element
.addClass( 'mw-widget-titleWidget-menu-withDescriptions' );
45 this.setLookupsDisabled( !this.suggestions
);
50 OO
.inheritClass( mw
.widgets
.TitleInputWidget
, OO
.ui
.TextInputWidget
);
51 OO
.mixinClass( mw
.widgets
.TitleInputWidget
, mw
.widgets
.TitleWidget
);
52 OO
.mixinClass( mw
.widgets
.TitleInputWidget
, OO
.ui
.mixin
.LookupElement
);
57 * @inheritdoc mw.widgets.TitleWidget
59 mw
.widgets
.TitleInputWidget
.prototype.getQueryValue = function () {
60 return this.getValue();
64 * @inheritdoc mw.widgets.TitleWidget
66 mw
.widgets
.TitleInputWidget
.prototype.setNamespace = function ( namespace ) {
68 mw
.widgets
.TitleWidget
.prototype.setNamespace
.call( this, namespace );
70 this.lookupCache
= {};
71 this.closeLookupMenu();
77 mw
.widgets
.TitleInputWidget
.prototype.getLookupRequest = function () {
78 return this.getSuggestionsPromise();
82 * @inheritdoc OO.ui.mixin.LookupElement
84 mw
.widgets
.TitleInputWidget
.prototype.getLookupCacheDataFromResponse = function ( response
) {
85 return response
.query
|| {};
89 * @inheritdoc OO.ui.mixin.LookupElement
91 mw
.widgets
.TitleInputWidget
.prototype.getLookupMenuOptionsFromData = function ( response
) {
92 return this.getOptionsFromData( response
);
98 mw
.widgets
.TitleInputWidget
.prototype.onLookupMenuItemChoose = function ( item
) {
99 this.closeLookupMenu();
100 this.setLookupsDisabled( true );
101 this.setValue( item
.getData() );
102 this.setLookupsDisabled( !this.suggestions
);
108 mw
.widgets
.TitleInputWidget
.prototype.focus = function () {
111 // Prevent programmatic focus from opening the menu
112 this.setLookupsDisabled( true );
115 retval
= mw
.widgets
.TitleInputWidget
.parent
.prototype.focus
.apply( this, arguments
);
117 this.setLookupsDisabled( !this.suggestions
);
125 mw
.widgets
.TitleInputWidget
.prototype.cleanUpValue = function ( value
) {
129 value
= mw
.widgets
.TitleInputWidget
.parent
.prototype.cleanUpValue
.call( this, value
);
131 return $.trimByteLength( this.value
, value
, this.maxLength
, function ( value
) {
132 var title
= widget
.getTitle( value
);
133 return title
? title
.getMain() : value
;
137 }( jQuery
, mediaWiki
) );