Index: trunk/extensions/ClickTracking/modules/ext.UserBuckets.js |
— | — | @@ -21,25 +21,25 @@ |
22 | 22 | var buckets = $.getBuckets(); |
23 | 23 | for ( var iter in mw.activeCampaigns ) { |
24 | 24 | 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 ){ |
28 | 28 | campaign.all(); |
29 | 29 | } |
30 | 30 | |
31 | | - if(campaign.preferences && !campaign.preferences.setBuckets){ |
| 31 | + if ( campaign.preferences && !campaign.preferences.setBuckets ) { |
32 | 32 | continue; |
33 | 33 | } |
34 | 34 | |
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 |
37 | 37 | var bucketTotal = 0; |
38 | 38 | for ( var rate in campaign.rates ){ |
39 | 39 | bucketTotal += campaign.rates[rate]; |
40 | 40 | } |
41 | 41 | |
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) ); |
44 | 44 | |
45 | 45 | // recurse through the rates until we get into the range the user falls in, |
46 | 46 | // assign them to that range |
— | — | @@ -47,22 +47,29 @@ |
48 | 48 | var next_val = 0; |
49 | 49 | for( rate in campaign.rates ){ |
50 | 50 | 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 ); |
53 | 53 | break; |
54 | 54 | } |
55 | 55 | prev_val = next_val; |
56 | 56 | } |
57 | 57 | } |
58 | 58 | |
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 | + } |
63 | 73 | } |
64 | | - if ( campaign.allActive ) { |
65 | | - campaign.allActive(); |
66 | | - } |
67 | 74 | } |
68 | 75 | |
69 | 76 | } |