Use $.noop instead of function () {}
[lhc/web/wiklou.git] / resources / src / mediawiki.special / mediawiki.special.apisandbox.js
index da8bdcd..694f86a 100644 (file)
                                this.setIcon( ok ? null : 'alert' );
                                this.setIconTitle( ok ? '' : mw.message( 'apisandbox-alert-field' ).plain() );
                                return $.Deferred().resolve( ok ).promise();
+                       },
+                       createItemWidget: function ( data, label ) {
+                               var item = OO.ui.CapsuleMultiselectWidget.prototype.createItemWidget.call( this, data, label );
+                               if ( this.paramInfo.deprecatedvalues &&
+                                       this.paramInfo.deprecatedvalues.indexOf( data ) >= 0
+                               ) {
+                                       item.$element.addClass( 'apihelp-deprecated-value' );
+                               }
+                               return item;
                        }
                },
 
                                        }
 
                                        items = $.map( pi.type, function ( v ) {
-                                               return new OO.ui.MenuOptionWidget( { data: String( v ), label: String( v ) } );
+                                               var config = {
+                                                       data: String( v ),
+                                                       label: String( v ),
+                                                       classes: []
+                                               };
+                                               if ( pi.deprecatedvalues && pi.deprecatedvalues.indexOf( v ) >= 0 ) {
+                                                       config.classes.push( 'apihelp-deprecated-value' );
+                                               }
+                                               return new OO.ui.MenuOptionWidget( config );
                                        } );
                                        if ( Util.apiBool( pi.multi ) ) {
                                                if ( pi.allspecifier !== undefined ) {
                                                $.extend( widget, WidgetMethods.dropdownWidget );
                                                if ( Util.apiBool( pi.submodules ) ) {
                                                        widget.getSubmodules = WidgetMethods.submoduleWidget.single;
-                                                       widget.getMenu().on( 'choose', ApiSandbox.updateUI );
+                                                       widget.getMenu().on( 'select', ApiSandbox.updateUI );
+                                               }
+                                               if ( pi.deprecatedvalues ) {
+                                                       widget.getMenu().on( 'select', function ( item ) {
+                                                               this.$element.toggleClass(
+                                                                       'apihelp-deprecated-value',
+                                                                       pi.deprecatedvalues.indexOf( item.data ) >= 0
+                                                               );
+                                                       }, [], widget );
                                                }
                                        }
 
                                                menu: { items: [] },
                                                $overlay: $( '#mw-apisandbox-ui' )
                                        } );
-                                       formatDropdown.getMenu().on( 'choose', Util.onFormatDropdownChange );
+                                       formatDropdown.getMenu().on( 'select', Util.onFormatDropdownChange );
                                }
 
                                menu = formatDropdown.getMenu();
                                        } )
                                        .then( function ( data, jqXHR ) {
                                                var m, loadTime, button, clear,
-                                                       ct = jqXHR.getResponseHeader( 'Content-Type' );
+                                                       ct = jqXHR.getResponseHeader( 'Content-Type' ),
+                                                       loginSuppressed = jqXHR.getResponseHeader( 'MediaWiki-Login-Suppressed' ) || 'false';
 
                                                $result.empty();
+                                               if ( loginSuppressed !== 'false' ) {
+                                                       $( '<div>' )
+                                                               .addClass( 'warning' )
+                                                               .append( Util.parseMsg( 'apisandbox-results-login-suppressed' ) )
+                                                               .appendTo( $result );
+                                               }
                                                if ( /^text\/mediawiki-api-prettyprint-wrapped(?:;|$)/.test( ct ) ) {
                                                        data = JSON.parse( data );
                                                        if ( data.modules.length ) {
                                        nooptional: true
                                } );
                                button = new OO.ui.ButtonWidget( {
-                                       icon: 'remove',
+                                       icon: 'trash',
                                        flags: 'destructive'
                                } );
                                layout = new OO.ui.ActionFieldLayout(
                                                if ( $.isFunction( f.focus ) ) {
                                                        f.focus();
                                                }
-                                       },
-                                       doNothing = function () {};
+                                       };
 
                                // This is something of a hack. We always want the 'format' and
                                // 'action' parameters from the main module to be specified,
                                                }
 
                                                descriptionContainer = $( '<div>' );
-                                               descriptionContainer.append( $( '<div>', {
-                                                       addClass: 'description',
-                                                       append: Util.parseHTML( pi.parameters[ i ].description )
-                                               } ) );
+
+                                               tmp = Util.parseHTML( pi.parameters[ i ].description );
+                                               tmp.filter( 'dl' ).makeCollapsible( {
+                                                       collapsed: true
+                                               } ).children( '.mw-collapsible-toggle' ).each( function () {
+                                                       var $this = $( this );
+                                                       $this.parent().prev( 'p' ).append( $this );
+                                               } );
+                                               descriptionContainer.append( $( '<div>', { addClass: 'description', append: tmp } ) );
+
                                                if ( pi.parameters[ i ].info && pi.parameters[ i ].info.length ) {
                                                        for ( j = 0; j < pi.parameters[ i ].info.length; j++ ) {
                                                                descriptionContainer.append( $( '<div>', {
                                                // it makes it too hard to read and our "disabled"
                                                // isn't really disabled.
                                                widgetField.onFieldDisable( false );
-                                               widgetField.onFieldDisable = doNothing;
+                                               widgetField.onFieldDisable = $.noop;
 
                                                if ( Util.apiBool( pi.parameters[ i ].deprecated ) ) {
                                                        deprecatedItems.push( widgetField, helpField );