Index: trunk/extensions/UsabilityInitiative/ClickTracking/ClickTracking.js |
— | — | @@ -1,26 +1,23 @@ |
2 | | -(function($) { |
3 | | - if( !wgClickTrackingIsThrottled ) { |
4 | | - // creates 'track action' function to call the clicktracking API and send the ID |
5 | | - $.trackAction = function ( id ) { |
6 | | - $j.post( wgScriptPath + '/api.php', { 'action': 'clicktracking', 'eventid': id, 'token': wgTrackingToken } ); |
| 2 | +( function( $ ) { |
| 3 | + if ( !wgClickTrackingIsThrottled ) { |
| 4 | + // Create 'track action' function to call the clicktracking API and send the ID |
| 5 | + $.trackAction = function( id ) { |
| 6 | + $j.post( |
| 7 | + wgScriptPath + '/api.php', { 'action': 'clicktracking', 'eventid': id, 'token': wgTrackingToken } |
| 8 | + ); |
7 | 9 | }; |
8 | | - |
9 | | - // Clicktrack the left sidebar links |
| 10 | + // Add click tracking hooks to the sidebar |
10 | 11 | $j(document).ready( function() { |
11 | | - $( '#p-logo a, #p-navigation a, #p-tb a' ).click( function() { |
12 | | - var id = 'leftnav-' + skin + '-' + |
13 | | - ( $(this).attr( 'id' ) || $(this).parent().attr( 'id' ) ); |
| 12 | + $( '#p-logo a, #p-navigation a, #p-interaction a, #p-tb a' ).each( function() { |
14 | 13 | var href = $(this).attr( 'href' ); |
15 | | - // Don't attach to javascript: URLs and the like, |
16 | | - // only to local URLs (start with a /), http:// , |
17 | | - // https:// and same-protocol URLs (start with //) |
18 | | - if ( href[0] == '/' || href.match( /^https?:\/\// ) ) |
19 | | - window.location = wgScriptPath + |
20 | | - '/api.php?action=clicktracking&eventid=' + |
21 | | - id + '&token=' + wgTrackingToken + |
22 | | - '&redirectto=' + escape( href ); |
23 | | - }); |
24 | | - }); |
| 14 | + // Only modify local and same-schema URLs |
| 15 | + if ( href[0] == '/' || href.match( /^https?:\/\// ) ) { |
| 16 | + var id = 'leftnav-' + skin + '-' + ( $(this).attr( 'id' ) || $(this).parent().attr( 'id' ) ); |
| 17 | + href = wgScriptPath + '/api.php?action=clicktracking' + |
| 18 | + '&eventid=' + id + '&token=' + wgTrackingToken + '&redirectto=' + escape( href ); |
| 19 | + $(this).attr( 'href', href ); |
| 20 | + } |
| 21 | + } ); |
| 22 | + } ); |
25 | 23 | } |
26 | | - |
27 | | -})(jQuery); |
| 24 | +} )( jQuery ); |