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 * @param {Object} [config] Configuration options
19 * @cfg {boolean} [suggestions=true] Display search suggestions
20 * @cfg {RegExp|Function|string} [validate] Perform title validation
22 mw
.widgets
.TitleInputWidget
= function MwWidgetsTitleInputWidget( config
) {
23 config
= config
|| {};
26 mw
.widgets
.TitleInputWidget
.parent
.call( this, $.extend( {}, config
, {
27 validate
: config
.validate
!== undefined ? config
.validate
: this.isQueryValid
.bind( this ),
32 mw
.widgets
.TitleWidget
.call( this, config
);
33 OO
.ui
.mixin
.LookupElement
.call( this, config
);
36 this.suggestions
= config
.suggestions
!== undefined ? config
.suggestions
: true;
39 this.$element
.addClass( 'mw-widget-titleInputWidget' );
40 this.lookupMenu
.$element
.addClass( 'mw-widget-titleWidget-menu' );
41 if ( this.showImages
) {
42 this.lookupMenu
.$element
.addClass( 'mw-widget-titleWidget-menu-withImages' );
44 if ( this.showDescriptions
) {
45 this.lookupMenu
.$element
.addClass( 'mw-widget-titleWidget-menu-withDescriptions' );
47 this.setLookupsDisabled( !this.suggestions
);
52 OO
.inheritClass( mw
.widgets
.TitleInputWidget
, OO
.ui
.TextInputWidget
);
53 OO
.mixinClass( mw
.widgets
.TitleInputWidget
, mw
.widgets
.TitleWidget
);
54 OO
.mixinClass( mw
.widgets
.TitleInputWidget
, OO
.ui
.mixin
.LookupElement
);
59 * @inheritdoc mw.widgets.TitleWidget
61 mw
.widgets
.TitleInputWidget
.prototype.getQueryValue = function () {
62 return this.getValue();
66 * @inheritdoc mw.widgets.TitleWidget
68 mw
.widgets
.TitleInputWidget
.prototype.setNamespace = function ( namespace ) {
70 mw
.widgets
.TitleWidget
.prototype.setNamespace
.call( this, namespace );
72 this.lookupCache
= {};
73 this.closeLookupMenu();
79 mw
.widgets
.TitleInputWidget
.prototype.getLookupRequest = function () {
80 return this.getSuggestionsPromise();
84 * @inheritdoc OO.ui.mixin.LookupElement
86 mw
.widgets
.TitleInputWidget
.prototype.getLookupCacheDataFromResponse = function ( response
) {
87 return response
.query
|| {};
91 * @inheritdoc OO.ui.mixin.LookupElement
93 mw
.widgets
.TitleInputWidget
.prototype.getLookupMenuOptionsFromData = function ( response
) {
94 return this.getOptionsFromData( response
);
100 mw
.widgets
.TitleInputWidget
.prototype.onLookupMenuItemChoose = function ( item
) {
101 this.closeLookupMenu();
102 this.setLookupsDisabled( true );
103 this.setValue( item
.getData() );
104 this.setLookupsDisabled( !this.suggestions
);
110 mw
.widgets
.TitleInputWidget
.prototype.focus = function () {
113 // Prevent programmatic focus from opening the menu
114 this.setLookupsDisabled( true );
117 retval
= mw
.widgets
.TitleInputWidget
.parent
.prototype.focus
.apply( this, arguments
);
119 this.setLookupsDisabled( !this.suggestions
);
127 mw
.widgets
.TitleInputWidget
.prototype.cleanUpValue = function ( value
) {
131 value
= mw
.widgets
.TitleInputWidget
.parent
.prototype.cleanUpValue
.call( this, value
);
133 return $.trimByteLength( this.value
, value
, this.maxLength
, function ( value
) {
134 var title
= widget
.getTitle( value
);
135 return title
? title
.getMain() : value
;
139 }( jQuery
, mediaWiki
) );