Merge "SpecialMovepage: Convert form to use OOUI controls"
[lhc/web/wiklou.git] / resources / src / mediawiki.widgets / mw.widgets.TitleInputWidget.js
index cf4d788..d5a7abc 100644 (file)
                var widget = this;
 
                // Config initialization
-               config = $.extend( { maxLength: 255 }, config );
+               config = $.extend( {
+                       maxLength: 255,
+                       limit: 10
+               }, config );
 
                // Parent constructor
                mw.widgets.TitleInputWidget.parent.call( this, $.extend( {}, config, { autocomplete: false } ) );
@@ -38,7 +41,7 @@
                OO.ui.mixin.LookupElement.call( this, config );
 
                // Properties
-               this.limit = config.limit || 10;
+               this.limit = config.limit;
                this.maxLength = config.maxLength;
                this.namespace = config.namespace !== undefined ? config.namespace : null;
                this.relative = config.relative !== undefined ? config.relative : true;
 
        /* Methods */
 
+       /**
+        * Get the namespace to prepend to titles in suggestions, if any.
+        *
+        * @return {number|null} Namespace number
+        */
+       mw.widgets.TitleInputWidget.prototype.getNamespace = function () {
+               return this.namespace;
+       };
+
+       /**
+        * Set the namespace to prepend to titles in suggestions, if any.
+        *
+        * @param {number|null} namespace Namespace number
+        */
+       mw.widgets.TitleInputWidget.prototype.setNamespace = function ( namespace ) {
+               this.namespace = namespace;
+               this.lookupCache = {};
+               this.closeLookupMenu();
+       };
+
        /**
         * @inheritdoc
         */
                                        widget.interwikiPrefixes.indexOf( interwiki ) !== -1
                                ) {
                                        return $.Deferred().resolve( { query: {
-                                               pages: [{
+                                               pages: [ {
                                                        title: widget.value
-                                               }]
+                                               } ]
                                        } } ).promise( promiseAbortObject );
                                } else {
                                        params = {
 
                if ( data.redirects ) {
                        for ( i = 0, len = data.redirects.length; i < len; i++ ) {
-                               redirect = data.redirects[i];
-                               redirectsTo[redirect.to] = redirectsTo[redirect.to] || [];
-                               redirectsTo[redirect.to].push( redirect.from );
+                               redirect = data.redirects[ i ];
+                               redirectsTo[ redirect.to ] = redirectsTo[ redirect.to ] || [];
+                               redirectsTo[ redirect.to ].push( redirect.from );
                        }
                }
 
                for ( index in data.pages ) {
-                       suggestionPage = data.pages[index];
-                       pageData[suggestionPage.title] = {
+                       suggestionPage = data.pages[ index ];
+                       pageData[ suggestionPage.title ] = {
                                missing: suggestionPage.missing !== undefined,
                                redirect: suggestionPage.redirect !== undefined,
                                disambiguation: OO.getProp( suggestionPage, 'pageprops', 'disambiguation' ) !== undefined,
                                titles.push( suggestionPage.title );
                        }
 
-                       redirects = redirectsTo[suggestionPage.title] || [];
+                       redirects = redirectsTo[ suggestionPage.title ] || [];
                        for ( i = 0, len = redirects.length; i < len; i++ ) {
-                               pageData[redirects[i]] = {
+                               pageData[ redirects[ i ] ] = {
                                        missing: false,
                                        redirect: true,
                                        disambiguation: false,
                                        description: mw.msg( 'mw-widgets-titleinput-description-redirect', suggestionPage.title )
                                };
-                               titles.push( redirects[i] );
+                               titles.push( redirects[ i ] );
                        }
                }
 
                );
 
                if ( !pageExists ) {
-                       pageData[this.value] = {
+                       pageData[ this.value ] = {
                                missing: true, redirect: false, disambiguation: false,
                                description: mw.msg( 'mw-widgets-titleinput-description-new-page' )
                        };
                        titles.push( this.value );
                }
                for ( i = 0, len = titles.length; i < len; i++ ) {
-                       page = pageData[titles[i]] || {};
-                       items.push( new mw.widgets.TitleOptionWidget( this.getOptionWidgetData( titles[i], page ) ) );
+                       page = pageData[ titles[ i ] ] || {};
+                       items.push( new mw.widgets.TitleOptionWidget( this.getOptionWidgetData( titles[ i ], page ) ) );
                }
 
                return items;