Index: trunk/extensions/ClickTracking/modules/jquery.clickTracking.js |
— | — | @@ -25,33 +25,50 @@ |
26 | 26 | * @param {string} id event identifier |
27 | 27 | */ |
28 | 28 | $.trackAction = function( id ) { |
29 | | - $.post( |
30 | | - mw.config.get( 'wgScriptPath' ) + '/api.php', { |
31 | | - 'action': 'clicktracking', |
32 | | - 'format' : 'json', |
33 | | - 'namespacenumber': mw.config.get( 'wgNamespaceNumber' ), |
34 | | - 'eventid': id, |
35 | | - 'token': $.cookie( 'clicktracking-session' ) |
36 | | - } |
37 | | - ); |
| 29 | + $.trackActionWithOptions( { 'id' : id }); |
38 | 30 | }; |
39 | 31 | /** |
40 | 32 | * Performs click tracking API call |
41 | | - * |
| 33 | + * |
42 | 34 | * @param {string} id event identifier |
43 | 35 | * @param {string} info additional information to be stored with the click |
44 | 36 | */ |
45 | 37 | $.trackActionWithInfo = function( id, info ) { |
46 | | - $.post( |
47 | | - mw.config.get( 'wgScriptPath' ) + '/api.php', { |
| 38 | + $.trackActionWithOptions( { 'id' : id, 'info' : info }); |
| 39 | + }; |
| 40 | + |
| 41 | + /** |
| 42 | + * Performs click tracking API call |
| 43 | + * |
| 44 | + * @param {map} options Data to submit. Valid keys: id, namespace, info, token |
| 45 | + */ |
| 46 | + $.trackActionWithOptions = function( options ) { |
| 47 | + options = $.extend( { |
| 48 | + 'namespace' : mw.config.get( 'wgNamespaceNumber' ), |
| 49 | + 'token' : $.cookie( 'clicktracking-session' ) |
| 50 | + }, options); |
| 51 | + |
| 52 | + if ( ! options.id ) { |
| 53 | + $.error("You must specify an event ID"); |
| 54 | + return; |
| 55 | + } |
| 56 | + |
| 57 | + var data = { |
48 | 58 | 'action': 'clicktracking', |
49 | 59 | 'format' : 'json', |
50 | | - 'eventid': id, |
51 | | - 'namespacenumber': mw.config.get( 'wgNamespaceNumber' ), |
52 | | - 'token': $.cookie( 'clicktracking-session' ), |
53 | | - 'additional': info |
54 | | - } |
55 | | - ); |
| 60 | + 'eventid': options.id, |
| 61 | + 'token': options.token |
| 62 | + }; |
| 63 | + |
| 64 | + if ( typeof options.namespace != 'undefined' ) { |
| 65 | + data.namespacenumber = options.namespace; |
| 66 | + } |
| 67 | + |
| 68 | + if ( typeof options.info != 'undefined' ) { |
| 69 | + data.additional = options.info; |
| 70 | + } |
| 71 | + |
| 72 | + $.post( mw.config.get( 'wgScriptPath' ) + '/api.php', data); |
56 | 73 | }; |
57 | 74 | |
58 | 75 | /** |