ApiSandbox: Visual separation of fields
[mediawiki.git] / resources / src / mediawiki.widgets / mw.widgets.ComplexTitleInputWidget.js
blobddae9b1f7fb0a1334a2bcfa8e9a8a71bdf429e2d
1 /*!
2 * MediaWiki Widgets - ComplexTitleInputWidget class.
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 ) {
9 /**
10 * Like TitleInputWidget, but the namespace has to be input through a separate dropdown field.
12 * @class
13 * @extends OO.ui.Widget
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
21 mw.widgets.ComplexTitleInputWidget = function MwWidgetsComplexTitleInputWidget( config ) {
22 // Parent constructor
23 mw.widgets.ComplexTitleInputWidget.parent.call( this, config );
25 // Properties
26 this.namespace = new mw.widgets.NamespaceInputWidget( config.namespace );
27 this.title = new mw.widgets.TitleInputWidget( $.extend(
28 {},
29 config.title,
31 relative: true,
32 namespace: config.namespace.value || null
34 ) );
36 // Events
37 this.namespace.connect( this, { change: 'updateTitleNamespace' } );
39 // Initialization
40 this.$element
41 .addClass( 'mw-widget-complexTitleInputWidget' )
42 .append(
43 this.namespace.$element,
44 this.title.$element
46 this.updateTitleNamespace();
49 /* Setup */
51 OO.inheritClass( mw.widgets.ComplexTitleInputWidget, OO.ui.Widget );
53 /* Static Methods */
54 /*jshint -W024*/
56 /**
57 * @inheritdoc
59 mw.widgets.ComplexTitleInputWidget.static.reusePreInfuseDOM = function ( node, config ) {
60 config = mw.widgets.ComplexTitleInputWidget.parent.static.reusePreInfuseDOM( node, config );
61 config.namespace = mw.widgets.NamespaceInputWidget.static.reusePreInfuseDOM(
62 $( node ).find( '.mw-widget-namespaceInputWidget' ),
63 config.namespace
65 config.title = mw.widgets.TitleInputWidget.static.reusePreInfuseDOM(
66 $( node ).find( '.mw-widget-titleInputWidget' ),
67 config.title
69 return config;
72 /**
73 * @inheritdoc
75 mw.widgets.ComplexTitleInputWidget.static.gatherPreInfuseState = function ( node, config ) {
76 var state = mw.widgets.ComplexTitleInputWidget.parent.static.gatherPreInfuseState( node, config );
77 state.namespace = mw.widgets.NamespaceInputWidget.static.gatherPreInfuseState(
78 $( node ).find( '.mw-widget-namespaceInputWidget' ),
79 config.namespace
81 state.title = mw.widgets.TitleInputWidget.static.gatherPreInfuseState(
82 $( node ).find( '.mw-widget-titleInputWidget' ),
83 config.title
85 return state;
88 /*jshint +W024*/
90 /* Methods */
92 /**
93 * Update the namespace to use for search suggestions of the title when the value of namespace
94 * dropdown changes.
96 mw.widgets.ComplexTitleInputWidget.prototype.updateTitleNamespace = function () {
97 this.title.setNamespace( Number( this.namespace.getValue() ) );
101 * @inheritdoc
103 mw.widgets.ComplexTitleInputWidget.prototype.restorePreInfuseState = function ( state ) {
104 mw.widgets.ComplexTitleInputWidget.parent.prototype.restorePreInfuseState.call( this, state );
105 this.namespace.restorePreInfuseState( state.namespace );
106 this.title.restorePreInfuseState( state.title );
109 }( jQuery, mediaWiki ) );