| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
( function () { |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
mw.widgets.TitleSearchWidget = function MwWidgetsTitleSearchWidget( config ) { |
| 22 |
config = config || {}; |
| 23 |
|
| 24 |
|
| 25 |
mw.widgets.TitleSearchWidget.super.call( this, config ); |
| 26 |
|
| 27 |
|
| 28 |
mw.widgets.TitleWidget.call( this, config ); |
| 29 |
OO.ui.mixin.RequestManager.call( this, config ); |
| 30 |
|
| 31 |
this.query.setValidation( this.isQueryValid.bind( this ) ); |
| 32 |
|
| 33 |
|
| 34 |
this.results.connect( this, { choose: 'onTitleSearchResultsChoose' } ); |
| 35 |
|
| 36 |
|
| 37 |
this.$element.addClass( 'mw-widget-titleSearchWidget' ); |
| 38 |
this.results.$element.addClass( 'mw-widget-titleWidget-menu' ); |
| 39 |
if ( this.showImages ) { |
| 40 |
this.results.$element.addClass( 'mw-widget-titleWidget-menu-withImages' ); |
| 41 |
} |
| 42 |
if ( this.showDescriptions ) { |
| 43 |
this.results.$element.addClass( 'mw-widget-titleWidget-menu-withDescriptions' ); |
| 44 |
} |
| 45 |
if ( this.maxLength !== undefined ) { |
| 46 |
this.getQuery().$input.attr( 'maxlength', this.maxLength ); |
| 47 |
} |
| 48 |
}; |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
OO.inheritClass( mw.widgets.TitleSearchWidget, OO.ui.SearchWidget ); |
| 53 |
OO.mixinClass( mw.widgets.TitleSearchWidget, OO.ui.mixin.RequestManager ); |
| 54 |
OO.mixinClass( mw.widgets.TitleSearchWidget, mw.widgets.TitleWidget ); |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
mw.widgets.TitleSearchWidget.prototype.getQueryValue = function () { |
| 62 |
return this.getQuery().getValue(); |
| 63 |
}; |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
mw.widgets.TitleSearchWidget.prototype.onTitleSearchResultsChoose = function ( item ) { |
| 71 |
this.getQuery().setValue( item.getData() ); |
| 72 |
}; |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
mw.widgets.TitleSearchWidget.prototype.onQueryChange = function () { |
| 78 |
this.getRequestData().done( ( data ) => { |
| 79 |
if ( this.query.isReadOnly() ) { |
| 80 |
|
| 81 |
|
| 82 |
return; |
| 83 |
} |
| 84 |
|
| 85 |
mw.widgets.TitleSearchWidget.super.prototype.onQueryChange.call( this ); |
| 86 |
this.results.addItems( this.getOptionsFromData( data ) ); |
| 87 |
} ); |
| 88 |
}; |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
mw.widgets.TitleSearchWidget.prototype.getRequestQuery = function () { |
| 94 |
return this.getQueryValue(); |
| 95 |
}; |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
mw.widgets.TitleSearchWidget.prototype.getRequest = function () { |
| 100 |
return this.getSuggestionsPromise(); |
| 101 |
}; |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
mw.widgets.TitleSearchWidget.prototype.getRequestCacheDataFromResponse = function ( response ) { |
| 106 |
return response.query || {}; |
| 107 |
}; |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
mw.widgets.TitleSearchWidget.prototype.isReadOnly = function () { |
| 115 |
return this.query.isReadOnly(); |
| 116 |
}; |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
mw.widgets.TitleSearchWidget.prototype.setReadOnly = function ( readOnly ) { |
| 126 |
this.query.setReadOnly( readOnly ); |
| 127 |
if ( readOnly ) { |
| 128 |
|
| 129 |
this.results.clearItems(); |
| 130 |
} |
| 131 |
return this; |
| 132 |
}; |
| 133 |
|
| 134 |
}() ); |