mediawiki.htmlform: Preserve classes added by HTMLForm's cssclass option
authorRyan Lane <rlane@wikimedia.org>
Wed, 1 May 2013 21:15:32 +0000 (16:15 -0500)
committerRyan Lane <rlane@wikimedia.org>
Wed, 1 May 2013 23:01:07 +0000 (18:01 -0500)
Follow-up to commit 8a9341b. When changing the multi-select
checkbox container to a select multiple, preserve any custom
classes added via the cssclass argument for the htmlform field.

Change-Id: I41d2a306627b33b34d7e464147d771cc727f4f61

resources/mediawiki/mediawiki.htmlform.js

index 4336790..0a2819b 100644 (file)
 
        function addMulti( $oldContainer, $container ) {
                var name = $oldContainer.find( 'input:first-child' ).attr( 'name' ),
-               $select = $( '<select>' ),
-               dataPlaceholder = mw.message( 'htmlform-chosen-placeholder' );
+                       oldClass = ( ' ' + $oldContainer.attr( 'class' ) + ' ' ).replace( /(mw-htmlform-field-HTMLMultiSelectField|mw-chosen)/g, '' ),
+                       $select = $( '<select>' ),
+                       dataPlaceholder = mw.message( 'htmlform-chosen-placeholder' );
+               oldClass = $.trim( oldClass );
                $select.attr( {
                        name: name,
                        multiple: 'multiple',
                        'data-placeholder': dataPlaceholder.plain(),
-                       'class': 'htmlform-chzn-select mw-input'
+                       'class': 'htmlform-chzn-select mw-input ' + oldClass
                } );
                $oldContainer.find( 'input' ).each( function () {
                        var $oldInput = $(this),