Merge "resourceloader: Don't call wfExpandUrl() on load.php urls"
[lhc/web/wiklou.git] / resources / src / mediawiki.widgets / mw.widgets.ComplexTitleInputWidget.js
1 /*!
2 * MediaWiki Widgets - ComplexTitleInputWidget class.
3 *
4 * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
6 */
7 ( function ( $, mw ) {
8
9 /**
10 * Like TitleInputWidget, but the namespace has to be input through a separate dropdown field.
11 *
12 * @class
13 * @extends OO.ui.Widget
14 *
15 * @constructor
16 * @param {Object} [config] Configuration options
17 * @cfg {Object} namespace Configuration for the NamespaceInputWidget dropdown with list of
18 * namespaces
19 * @cfg {Object} title Configuration for the TitleInputWidget text field
20 */
21 mw.widgets.ComplexTitleInputWidget = function MwWidgetsComplexTitleInputWidget( config ) {
22 // Parent constructor
23 mw.widgets.ComplexTitleInputWidget.parent.call( this, config );
24
25 // Properties
26 this.namespace = new mw.widgets.NamespaceInputWidget( config.namespace );
27 this.title = new mw.widgets.TitleInputWidget( $.extend(
28 {},
29 config.title,
30 {
31 relative: true,
32 namespace: config.namespace.value || null
33 }
34 ) );
35
36 // Events
37 this.namespace.connect( this, { change: 'updateTitleNamespace' } );
38
39 // Initialization
40 this.$element
41 .addClass( 'mw-widget-complexTitleInputWidget' )
42 .append(
43 this.namespace.$element,
44 this.title.$element
45 );
46 this.updateTitleNamespace();
47 };
48
49 /* Setup */
50
51 OO.inheritClass( mw.widgets.ComplexTitleInputWidget, OO.ui.Widget );
52
53 /* Methods */
54
55 /**
56 * Update the namespace to use for search suggestions of the title when the value of namespace
57 * dropdown changes.
58 */
59 mw.widgets.ComplexTitleInputWidget.prototype.updateTitleNamespace = function () {
60 this.title.setNamespace( Number( this.namespace.getValue() ) );
61 };
62
63 }( jQuery, mediaWiki ) );