Jump to content

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

From Wikipedia, the free encyclopedia

This is the current revision of this page, as edited by JSutherland (WMF) (talk | contribs) at 21:26, 14 October 2021 (JSutherland (WMF) moved page User:Maryana (WMF)/common.js to User:MPinchuk (WMF) (usurped)/common.js without leaving a redirect: Automatically moved page while renaming the user "Maryana (WMF)" to "MPinchuk (WMF) (usurped)"). The present address (URL) is a permanent link to this version.

(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
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 = $( '<fieldset>' ).append(
            $( '<label>', { text: name, css: { display: 'block' } } )
        );

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

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

            var $input = $( '<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 = $( '<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;
    });
});
});