Index: trunk/extensions/ClickTracking/modules/ext.UserBuckets.js |
— | — | @@ -1,54 +1,25 @@ |
2 | | -// FIXME: Use jquery.json.js instead |
3 | | -var JSON; |
4 | | -if (!JSON) { |
5 | | - JSON = {}; |
6 | | - |
7 | | - if(!JSON.stringify){ |
8 | | - /* Very limited JSON encoder */ |
9 | | - JSON.stringify = function( js_obj ) { |
10 | | - var returnstr = "{ "; |
11 | | - |
12 | | - // trailing commas and json don't mix |
13 | | - var propertynum = 0; |
14 | | - for ( property in js_obj ) { |
15 | | - if ( propertynum > 0 ) { |
16 | | - returnstr += ", "; |
17 | | - } |
18 | | - returnstr += "\"" + property + "\"" + " : "; |
19 | | - if ( typeof js_obj[property] == 'object' ) { |
20 | | - returnstr += JSON.stringify( js_obj[property] ); |
21 | | - } else { |
22 | | - returnstr += "\"" + js_obj[property] + "\" "; |
23 | | - } |
24 | | - propertynum++; |
25 | | - } |
26 | | - |
27 | | - returnstr += " }"; |
28 | | - return returnstr; |
29 | | - }; |
30 | | - } |
31 | | -} |
32 | | - |
33 | 2 | ( function( $ ) { |
34 | 3 | //lazy-load |
35 | 4 | $.getBuckets = function (force){ |
36 | | - if (typeof($j.userBuckets) == 'undefined' || force ){ |
37 | | - $j.userBuckets = $.parseJSON( $.cookie('userbuckets') ); |
| 5 | + if ( typeof $.userBuckets == 'undefined' || force ){ |
| 6 | + $.userBuckets = $.parseJSON( $.cookie('userbuckets') ); |
38 | 7 | } |
39 | | - return $j.userBuckets; |
| 8 | + return $.userBuckets; |
40 | 9 | }; |
41 | 10 | |
42 | 11 | $.setBucket = function ( bucketName, bucketValue, bucketVersion ){ |
43 | 12 | var bucketCookies = $.getBuckets(); |
44 | | - if(!bucketCookies) { bucketCookies ={};} |
| 13 | + if ( !bucketCookies ) { |
| 14 | + bucketCookies = {}; |
| 15 | + } |
45 | 16 | bucketCookies[ bucketName ] = [ bucketValue, bucketVersion ]; |
46 | | - $j.cookie('userbuckets', JSON.stringify( bucketCookies ) , { expires: 365 }); //expires in 1 year |
47 | | - bucketCookies = $.getBuckets(true); //force it to rerun and update |
| 17 | + $.cookie('userbuckets', $.toJSON( bucketCookies ) , { expires: 365 }); //expires in 1 year |
| 18 | + bucketCookies = $.getBuckets(true); // Force rerun and update |
48 | 19 | }; |
49 | 20 | |
50 | 21 | $.setupActiveBuckets = function(){ |
51 | 22 | var buckets = $.getBuckets(); |
52 | | - for(iter in mw.activeCampaigns){ |
| 23 | + for ( iter in mw.activeCampaigns ) { |
53 | 24 | var campaign = mw.activeCampaigns[iter]; |
54 | 25 | // if bucket has been set, or bucket version is out of date, |
55 | 26 | // set up a user bucket |
— | — | @@ -89,7 +60,7 @@ |
90 | 61 | if(typeof(campaign[$.getBuckets()[campaign.name][0]]) == "function"){ |
91 | 62 | campaign[$.getBuckets()[campaign.name][0]](); //function to execute |
92 | 63 | } |
93 | | - if(campaign.allActive){ |
| 64 | + if ( campaign.allActive ) { |
94 | 65 | campaign.allActive(); |
95 | 66 | } |
96 | 67 | } |
— | — | @@ -98,9 +69,9 @@ |
99 | 70 | |
100 | 71 | }; |
101 | 72 | |
102 | | -//no need to do any of this if there are no active campaigns |
103 | | -if( (typeof(MW) != "undefined") && MW.activeCampaigns){ |
104 | | - $j( document ).ready( jQuery.setupActiveBuckets ); |
| 73 | +// No need to do any of this if there are no active campaigns |
| 74 | +if ( mw.activeCampaigns && mw.activeCampaigns.length ) { |
| 75 | + $( $.setupActiveBuckets ); |
105 | 76 | } |
106 | 77 | |
107 | 78 | |
Index: trunk/extensions/ClickTracking/ClickTracking.php |
— | — | @@ -89,7 +89,7 @@ |
90 | 90 | ) + $ctResourceTemplate; |
91 | 91 | $wgResourceModules['ext.UserBuckets'] = array( |
92 | 92 | 'scripts' => 'ext.UserBuckets.js', |
93 | | - 'dependencies' => array('jquery.clickTracking', 'jquery.cookie'), |
| 93 | + 'dependencies' => array('jquery.clickTracking', 'jquery.json', 'jquery.cookie'), |
94 | 94 | ) + $ctResourceTemplate; |
95 | 95 | |
96 | 96 | //uncomment for sample campaign |