r87048 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87047‎ | r87048 | r87049 >
Date:21:53, 27 April 2011
Author:krinkle
Status:ok
Tags:
Comment:
Using new jquery.json module in ext.UserBuckets module
Modified paths:
  • /trunk/extensions/ClickTracking/ClickTracking.php (modified) (history)
  • /trunk/extensions/ClickTracking/modules/ext.UserBuckets.js (modified) (history)

Diff [purge]

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 -
332 ( function( $ ) {
343 //lazy-load
354 $.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') );
387 }
39 - return $j.userBuckets;
 8+ return $.userBuckets;
409 };
4110
4211 $.setBucket = function ( bucketName, bucketValue, bucketVersion ){
4312 var bucketCookies = $.getBuckets();
44 - if(!bucketCookies) { bucketCookies ={};}
 13+ if ( !bucketCookies ) {
 14+ bucketCookies = {};
 15+ }
4516 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
4819 };
4920
5021 $.setupActiveBuckets = function(){
5122 var buckets = $.getBuckets();
52 - for(iter in mw.activeCampaigns){
 23+ for ( iter in mw.activeCampaigns ) {
5324 var campaign = mw.activeCampaigns[iter];
5425 // if bucket has been set, or bucket version is out of date,
5526 // set up a user bucket
@@ -89,7 +60,7 @@
9061 if(typeof(campaign[$.getBuckets()[campaign.name][0]]) == "function"){
9162 campaign[$.getBuckets()[campaign.name][0]](); //function to execute
9263 }
93 - if(campaign.allActive){
 64+ if ( campaign.allActive ) {
9465 campaign.allActive();
9566 }
9667 }
@@ -98,9 +69,9 @@
9970
10071 };
10172
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 );
10576 }
10677
10778
Index: trunk/extensions/ClickTracking/ClickTracking.php
@@ -89,7 +89,7 @@
9090 ) + $ctResourceTemplate;
9191 $wgResourceModules['ext.UserBuckets'] = array(
9292 'scripts' => 'ext.UserBuckets.js',
93 - 'dependencies' => array('jquery.clickTracking', 'jquery.cookie'),
 93+ 'dependencies' => array('jquery.clickTracking', 'jquery.json', 'jquery.cookie'),
9494 ) + $ctResourceTemplate;
9595
9696 //uncomment for sample campaign

Status & tagging log