User:Ori Livneh (WMF)/trackedits.js

mw.loader.using( 'jquery.clickTracking', function {	'use strict';

// Stub console for old IEs var console = window.console || {}; console.time = console.time || function {}; console.timeEnd = console.timeEnd || function {};

// Get current time (in milliseconds since unix epoch) function now { return ( new Date ).getTime; }

// Store time at load for calculating edit session duration var t0 = now;

// Default duration (in miliseconds) to wait before // re-firing a stalled event var DEFAULT_TIMEOUT = 600;

$.fn.stall = function ( etype, callback, timeout ) {

timeout = timeout || DEFAULT_TIMEOUT; $( this ).one( etype, function ( event ) {			var fired = false;			var o;

console.time( 'stalled ' + etype );

function fire { if ( !fired ) { fired = true; console.timeEnd( 'stalled ' + etype ); event.target[ etype ]; }			}

window.setTimeout( fire, timeout );

try { o = callback.apply( this, arguments ); } catch ( err ) { fire; throw err; }

if ( o && o.always ) { o.always( fire ); }

return false; } );	};

var payload = { referrer : document.referrer, username : mw.config.get( 'wgUserName' ), article : mw.config.get( 'wgTitle' ), revision : mw.config.get( 'wgCurRevisionId' ), duration : 0 };

$( function {		$( '#wpSave' ).stall( 'click', function  { // Calculate editing session duration, in seconds payload[ 'duration' ] = ( now - t0 ) / 1000; $.trackActionWithInfo( 'e3-edit-beta', $.param(payload) ); } );	} );

} );