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
19 * @cfg {RegExp|Function|string} [validate] Perform title validation
21 mw
.widgets
.TitleInputWidget
= function MwWidgetsTitleInputWidget( config
) {
22 config
= config
|| {};
25 mw
.widgets
.TitleInputWidget
.parent
.call( this, $.extend( {}, config
, {
26 validate
: config
.validate
!== undefined ? config
.validate
: this.isQueryValid
.bind( this ),
31 mw
.widgets
.TitleWidget
.call( this, config
);
32 OO
.ui
.mixin
.LookupElement
.call( this, config
);
35 this.suggestions
= config
.suggestions
!== undefined ? config
.suggestions
: true;
38 this.$element
.addClass( 'mw-widget-titleInputWidget' );
39 this.lookupMenu
.$element
.addClass( 'mw-widget-titleWidget-menu' );
40 if ( this.showImages
) {
41 this.lookupMenu
.$element
.addClass( 'mw-widget-titleWidget-menu-withImages' );
43 if ( this.showDescriptions
) {
44 this.lookupMenu
.$element
.addClass( 'mw-widget-titleWidget-menu-withDescriptions' );
46 this.setLookupsDisabled( !this.suggestions
);
51 OO
.inheritClass( mw
.widgets
.TitleInputWidget
, OO
.ui
.TextInputWidget
);
52 OO
.mixinClass( mw
.widgets
.TitleInputWidget
, mw
.widgets
.TitleWidget
);
53 OO
.mixinClass( mw
.widgets
.TitleInputWidget
, OO
.ui
.mixin
.LookupElement
);
58 * @inheritdoc mw.widgets.TitleWidget
60 mw
.widgets
.TitleInputWidget
.prototype.getQueryValue = function () {
61 return this.getValue();
65 * @inheritdoc mw.widgets.TitleWidget
67 mw
.widgets
.TitleInputWidget
.prototype.setNamespace = function ( namespace ) {
69 mw
.widgets
.TitleWidget
.prototype.setNamespace
.call( this, namespace );
71 this.lookupCache
= {};
72 this.closeLookupMenu();
78 mw
.widgets
.TitleInputWidget
.prototype.getLookupRequest = function () {
79 return this.getSuggestionsPromise();
83 * @inheritdoc OO.ui.mixin.LookupElement
85 mw
.widgets
.TitleInputWidget
.prototype.getLookupCacheDataFromResponse = function ( response
) {
86 return response
.query
|| {};
90 * @inheritdoc OO.ui.mixin.LookupElement
92 mw
.widgets
.TitleInputWidget
.prototype.getLookupMenuOptionsFromData = function ( response
) {
93 return this.getOptionsFromData( response
);
99 mw
.widgets
.TitleInputWidget
.prototype.onLookupMenuItemChoose = function ( item
) {
100 this.closeLookupMenu();
101 this.setLookupsDisabled( true );
102 this.setValue( item
.getData() );
103 this.setLookupsDisabled( !this.suggestions
);
109 mw
.widgets
.TitleInputWidget
.prototype.focus = function () {
112 // Prevent programmatic focus from opening the menu
113 this.setLookupsDisabled( true );
116 retval
= mw
.widgets
.TitleInputWidget
.parent
.prototype.focus
.apply( this, arguments
);
118 this.setLookupsDisabled( !this.suggestions
);
126 mw
.widgets
.TitleInputWidget
.prototype.cleanUpValue = function ( value
) {
130 value
= mw
.widgets
.TitleInputWidget
.parent
.prototype.cleanUpValue
.call( this, value
);
132 return $.trimByteLength( this.value
, value
, this.maxLength
, function ( value
) {
133 var title
= widget
.getTitle( value
);
134 return title
? title
.getMain() : value
;
138 }( jQuery
, mediaWiki
) );