| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
( function () { |
| 8 |
|
| 9 |
const trimByteLength = require( 'mediawiki.String' ).trimByteLength; |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
mw.widgets.TitleInputWidget = function MwWidgetsTitleInputWidget( config ) { |
| 26 |
config = config || {}; |
| 27 |
|
| 28 |
|
| 29 |
mw.widgets.TitleInputWidget.super.call( this, Object.assign( {}, config, { |
| 30 |
validate: config.validate !== undefined ? config.validate : this.isQueryValid.bind( this ), |
| 31 |
autocomplete: false |
| 32 |
} ) ); |
| 33 |
|
| 34 |
|
| 35 |
mw.widgets.TitleWidget.call( this, config ); |
| 36 |
OO.ui.mixin.LookupElement.call( this, config ); |
| 37 |
|
| 38 |
|
| 39 |
this.suggestions = config.suggestions !== undefined ? config.suggestions : true; |
| 40 |
|
| 41 |
|
| 42 |
this.$element.addClass( 'mw-widget-titleInputWidget' ); |
| 43 |
this.lookupMenu.$element.addClass( 'mw-widget-titleWidget-menu' ); |
| 44 |
if ( this.showImages ) { |
| 45 |
this.lookupMenu.$element.addClass( 'mw-widget-titleWidget-menu-withImages' ); |
| 46 |
} |
| 47 |
if ( this.showDescriptions ) { |
| 48 |
this.lookupMenu.$element.addClass( 'mw-widget-titleWidget-menu-withDescriptions' ); |
| 49 |
} |
| 50 |
this.setLookupsDisabled( !this.suggestions ); |
| 51 |
}; |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
OO.inheritClass( mw.widgets.TitleInputWidget, OO.ui.TextInputWidget ); |
| 56 |
OO.mixinClass( mw.widgets.TitleInputWidget, mw.widgets.TitleWidget ); |
| 57 |
OO.mixinClass( mw.widgets.TitleInputWidget, OO.ui.mixin.LookupElement ); |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
mw.widgets.TitleInputWidget.prototype.getQueryValue = function () { |
| 65 |
return this.getValue(); |
| 66 |
}; |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
mw.widgets.TitleInputWidget.prototype.setNamespace = function ( namespace ) { |
| 72 |
|
| 73 |
mw.widgets.TitleWidget.prototype.setNamespace.call( this, namespace ); |
| 74 |
|
| 75 |
this.lookupCache = {}; |
| 76 |
this.closeLookupMenu(); |
| 77 |
}; |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
mw.widgets.TitleInputWidget.prototype.getLookupRequest = function () { |
| 83 |
return this.getSuggestionsPromise(); |
| 84 |
}; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
mw.widgets.TitleInputWidget.prototype.getLookupCacheDataFromResponse = function ( response ) { |
| 90 |
return response.query || {}; |
| 91 |
}; |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
mw.widgets.TitleInputWidget.prototype.getLookupMenuOptionsFromData = function ( response ) { |
| 97 |
return this.getOptionsFromData( response ); |
| 98 |
}; |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
mw.widgets.TitleInputWidget.prototype.onLookupMenuChoose = function ( item ) { |
| 108 |
this.closeLookupMenu(); |
| 109 |
this.setLookupsDisabled( true ); |
| 110 |
this.setValue( item.getData() ); |
| 111 |
this.setLookupsDisabled( !this.suggestions ); |
| 112 |
}; |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
mw.widgets.TitleInputWidget.prototype.focus = function () { |
| 118 |
|
| 119 |
this.setLookupsDisabled( true ); |
| 120 |
|
| 121 |
|
| 122 |
const retval = mw.widgets.TitleInputWidget.super.prototype.focus.apply( this, arguments ); |
| 123 |
|
| 124 |
this.setLookupsDisabled( !this.suggestions ); |
| 125 |
|
| 126 |
return retval; |
| 127 |
}; |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
mw.widgets.TitleInputWidget.prototype.cleanUpValue = function ( value ) { |
| 133 |
|
| 134 |
value = mw.widgets.TitleInputWidget.super.prototype.cleanUpValue.call( this, value ); |
| 135 |
|
| 136 |
return trimByteLength( this.value, value, this.maxLength, ( val ) => { |
| 137 |
const title = this.getMWTitle( val ); |
| 138 |
return title ? title.getMain() : val; |
| 139 |
} ).newVal; |
| 140 |
}; |
| 141 |
|
| 142 |
}() ); |