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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
/*!
* MediaWiki Widgets - ComplexTitleInputWidget class.
*
* @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
( function ( $, mw ) {
/**
* Like TitleInputWidget, but the namespace has to be input through a separate dropdown field.
*
* @class
* @extends OO.ui.Widget
*
* @constructor
* @param {Object} [config] Configuration options
* @cfg {Object} namespace Configuration for the NamespaceInputWidget dropdown with list of
* namespaces
* @cfg {Object} title Configuration for the TitleInputWidget text field
*/
mw.widgets.ComplexTitleInputWidget = function MwWidgetsComplexTitleInputWidget( config ) {
// Parent constructor
mw.widgets.ComplexTitleInputWidget.parent.call( this, config );
// Properties
this.namespace = new mw.widgets.NamespaceInputWidget( config.namespace );
this.title = new mw.widgets.TitleInputWidget( $.extend(
{},
config.title,
{
relative: true,
namespace: config.namespace.value || null
}
) );
// Events
this.namespace.connect( this, { change: 'updateTitleNamespace' } );
// Initialization
this.$element
.addClass( 'mw-widget-complexTitleInputWidget' )
.append(
this.namespace.$element,
this.title.$element
);
this.updateTitleNamespace();
};
/* Setup */
OO.inheritClass( mw.widgets.ComplexTitleInputWidget, OO.ui.Widget );
/* Static Methods */
/**
* @inheritdoc
*/
mw.widgets.ComplexTitleInputWidget.static.reusePreInfuseDOM = function ( node, config ) {
config = mw.widgets.ComplexTitleInputWidget.parent.static.reusePreInfuseDOM( node, config );
config.namespace = mw.widgets.NamespaceInputWidget.static.reusePreInfuseDOM(
$( node ).find( '.mw-widget-namespaceInputWidget' ),
config.namespace
);
config.title = mw.widgets.TitleInputWidget.static.reusePreInfuseDOM(
$( node ).find( '.mw-widget-titleInputWidget' ),
config.title
);
return config;
};
/**
* @inheritdoc
*/
mw.widgets.ComplexTitleInputWidget.static.gatherPreInfuseState = function ( node, config ) {
var state = mw.widgets.ComplexTitleInputWidget.parent.static.gatherPreInfuseState( node, config );
state.namespace = mw.widgets.NamespaceInputWidget.static.gatherPreInfuseState(
$( node ).find( '.mw-widget-namespaceInputWidget' ),
config.namespace
);
state.title = mw.widgets.TitleInputWidget.static.gatherPreInfuseState(
$( node ).find( '.mw-widget-titleInputWidget' ),
config.title
);
return state;
};
/* Methods */
/**
* Update the namespace to use for search suggestions of the title when the value of namespace
* dropdown changes.
*/
mw.widgets.ComplexTitleInputWidget.prototype.updateTitleNamespace = function () {
this.title.setNamespace( Number( this.namespace.getValue() ) );
};
/**
* @inheritdoc
*/
mw.widgets.ComplexTitleInputWidget.prototype.restorePreInfuseState = function ( state ) {
mw.widgets.ComplexTitleInputWidget.parent.prototype.restorePreInfuseState.call( this, state );
this.namespace.restorePreInfuseState( state.namespace );
this.title.restorePreInfuseState( state.title );
};
/**
* @inheritdoc
*/
mw.widgets.ComplexTitleInputWidget.prototype.setDisabled = function ( disabled ) {
mw.widgets.ComplexTitleInputWidget.parent.prototype.setDisabled.call( this, disabled );
if ( this.namespace ) {
this.namespace.setDisabled( disabled );
}
if ( this.title ) {
this.title.setDisabled( disabled );
}
return this;
};
}( jQuery, mediaWiki ) );
|