User:MPinchuk (WMF) (usurped)/common.js

Object.keys = Object.keys || function ( o ) { return $.map( o, function ( k ) { return k; } ); };

var deps = ["ext.UserBuckets", "ext.UserBuckets.AccountCreationUserBucket", "jquery.clickTracking"];

mw.loader.using(deps, function { $(function  { var campaigns = {};

$.each( mw.activeCampaigns, function ( name, options ) {       campaigns[ name ] = {            version: options.version,            all: Object.keys( options.rates )        };    } );

$.each( $.getBuckets( true ), function ( name, active ) {       campaigns[ name ].active = active[ 0 ];    } );

var fieldsets = $.map( campaigns, function ( options, name ) {

var $fieldset = $( ' ' ).append(           $( ' ', { text: name, css: { display: 'block' } } )        );

var fields = $.map( options.all, function ( bucket ) {           var id = [ name, bucket ].join( '-' );

var $label = $( ' ', {               text : bucket,                for  : id            } );

var $input = $( ' ', {                   id    : id,                    type  : 'radio',                    name  : name,                    value : bucket,                    checked: ( bucket === options.active )            } );

$label.append( $input ); return $label; } );

$.fn.append.apply( $fieldset, fields );

return $fieldset;

} );

var $form = $( ' ', { 'class': 'campaigns' } ); $.fn.append.apply( $form, fieldsets ); $form.appendTo( '#p-lang' ); $form.css( 'font-size', '0.75em')

$( 'input:radio', $form ).on( 'change', function {        var campaign = $( this ).attr( 'name' );        var bucket = $( this ).val;        var version = campaigns[ campaign ].version;        $.setBucket( campaign, bucket, version );        mw.util.jsMessage( 'Assigned to bucket "' + bucket + '" for campaign "' + campaign + '"' );        return true;    }); }); });