r87186 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87185‎ | r87186 | r87187 >
Date:13:33, 1 May 2011
Author:krinkle
Status:ok
Tags:
Comment:
Follow-up r86961: Code conventions; line-wrap around 80-100 chars; using isFunction instead of typeof check
Modified paths:
  • /trunk/extensions/ClickTracking/modules/ext.UserBuckets.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ClickTracking/modules/ext.UserBuckets.js
@@ -21,25 +21,25 @@
2222 var buckets = $.getBuckets();
2323 for ( var iter in mw.activeCampaigns ) {
2424 var campaign = mw.activeCampaigns[iter];
25 - // if bucket has been set, or bucket version is out of date,
26 - // set up a user bucket
27 - if(campaign.all){
 25+ // If bucket has been set, or bucket version is out of date,
 26+ // set up a user bucket.
 27+ if ( campaign.all ){
2828 campaign.all();
2929 }
3030
31 - if(campaign.preferences && !campaign.preferences.setBuckets){
 31+ if ( campaign.preferences && !campaign.preferences.setBuckets ) {
3232 continue;
3333 }
3434
35 - if(!buckets || !buckets[campaign.name] || buckets[campaign.name][1] < campaign.version){
36 - //add up all rates
 35+ if ( !buckets || !buckets[campaign.name] || buckets[campaign.name][1] < campaign.version){
 36+ // Add up all rates
3737 var bucketTotal = 0;
3838 for ( var rate in campaign.rates ){
3939 bucketTotal += campaign.rates[rate];
4040 }
4141
42 - //give the user a random number in those rates
43 - var currentUser = Math.floor(Math.random() * (bucketTotal+1));
 42+ // Give the user a random number in those rates
 43+ var currentUser = Math.floor( Math.random() * (bucketTotal+1) );
4444
4545 // recurse through the rates until we get into the range the user falls in,
4646 // assign them to that range
@@ -47,22 +47,29 @@
4848 var next_val = 0;
4949 for( rate in campaign.rates ){
5050 next_val += campaign.rates[rate];
51 - if(prev_val <= currentUser && currentUser < next_val){
52 - $.setBucket(campaign.name, rate, campaign.version);
 51+ if ( prev_val <= currentUser && currentUser < next_val ){
 52+ $.setBucket( campaign.name, rate, campaign.version );
5353 break;
5454 }
5555 prev_val = next_val;
5656 }
5757 }
5858
59 - // do the actual code in the campaign based on the bucket
60 - if($.getBuckets() && $.getBuckets()[campaign.name] && $.getBuckets()[campaign.name][0] != "none"){
61 - if(typeof(campaign[$.getBuckets()[campaign.name][0]]) == "function"){
62 - campaign[$.getBuckets()[campaign.name][0]](); //function to execute
 59+ // Execute the actual code in the campaign based on the bucket
 60+ if ( $.getBuckets() && $.getBuckets()[campaign.name] ) {
 61+
 62+ var campaignBucket = $.getBuckets()[campaign.name][0];
 63+ if ( campaignBucket != 'none' ) {
 64+
 65+ // Function to execute
 66+ var func = campaign[campaignBucket];
 67+ if ( $.isFunction( func ) ) {
 68+ func();
 69+ }
 70+ if ( campaign.allActive ) {
 71+ campaign.allActive();
 72+ }
6373 }
64 - if ( campaign.allActive ) {
65 - campaign.allActive();
66 - }
6774 }
6875
6976 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r86961cross-browser funnimishg18:10, 26 April 2011

Status & tagging log