blob: 527d790d6c1af70e009dbb0b65d550920f007dd5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
( function ( mw ) {
/**
* Widget to select and display target page on Special:RecentChangesLinked (AKA Related Changes)
*
* @extends OO.ui.Widget
*
* @constructor
* @param {mw.rcfilters.Controller} controller
* @param {mw.rcfilters.dm.FilterItem} targetPageModel
* @param {Object} [config] Configuration object
*/
mw.rcfilters.ui.RclTargetPageWidget = function MwRcfiltersUiRclTargetPageWidget(
controller, targetPageModel, config
) {
config = config || {};
// Parent
mw.rcfilters.ui.RclTargetPageWidget.parent.call( this, config );
this.controller = controller;
this.model = targetPageModel;
this.titleSearch = new mw.widgets.TitleInputWidget( {
validate: false,
placeholder: mw.msg( 'rcfilters-target-page-placeholder' ),
showImages: true,
showDescriptions: true,
addQueryInput: false
} );
// Events
this.model.connect( this, { update: 'updateUiBasedOnModel' } );
this.titleSearch.$input.on( {
blur: this.onLookupInputBlur.bind( this )
} );
this.titleSearch.lookupMenu.connect( this, {
choose: 'onLookupMenuItemChoose'
} );
// Initialize
this.$element
.addClass( 'mw-rcfilters-ui-rclTargetPageWidget' )
.append( this.titleSearch.$element );
this.updateUiBasedOnModel();
};
/* Initialization */
OO.inheritClass( mw.rcfilters.ui.RclTargetPageWidget, OO.ui.Widget );
/* Methods */
/**
* Respond to the user choosing a title
*/
mw.rcfilters.ui.RclTargetPageWidget.prototype.onLookupMenuItemChoose = function () {
this.titleSearch.$input.blur();
};
/**
* Respond to titleSearch $input blur
*/
mw.rcfilters.ui.RclTargetPageWidget.prototype.onLookupInputBlur = function () {
this.controller.setTargetPage( this.titleSearch.getQueryValue() );
};
/**
* Respond to the model being updated
*/
mw.rcfilters.ui.RclTargetPageWidget.prototype.updateUiBasedOnModel = function () {
var title = mw.Title.newFromText( this.model.getValue() ),
text = title ? title.toText() : this.model.getValue();
this.titleSearch.setValue( text );
this.titleSearch.setTitle( text );
};
}( mediaWiki ) );
|