Log login-click event

Our logEvent wrapper now returns jQuery.Promise too.

Added timeout out parameter to our logEvent wrapper. Unlike
GettingStarted, I didn't create separate logUnlessTimeout
function.

Chrome apparently emulates enter on links as a click, so
this catches enters, left and middle clicks, but not if
the link is opened via right click menu. Might not catch
enter in all browsers.

Change-Id: I4b0eb56e7c7d6e56f8fd99d536f9b60b94a2e09e
This commit is contained in:
Niklas Laxström
2013-07-16 10:46:36 +00:00
parent a1d7e391fb
commit 8e1726e745
2 changed files with 34 additions and 2 deletions

View File

@@ -158,13 +158,32 @@
* and ensures the correct schema is loaded.
*
* @param {Object} data Event action and optional fields
* @param {int} [timeout] Fail the request if it is not completed within
* the specified timeout. Can be use for example to log actions that
* cause the browser to navigate to other pages.
* @return {jQuery.Promise} jQuery Promise object for the logging call
* @since 2013.07
* @see https://meta.wikimedia.org/wiki/Schema:UniversalLanguageSelector
*/
mw.uls.logEvent = function ( event ) {
mw.uls.logEvent = function ( event, timeout ) {
// We need to create our own deferred for two reasons:
// - logEvent might not be executed immediately
// - we cannot reject a promise returned by it
// So we proxy the original promises status updates
// and register our timeout if requested (for links).
var deferred = $.Deferred();
logEventQueue.add( function () {
mw.eventLog.logEvent( 'UniversalLanguageSelector', event );
mw.eventLog.logEvent( 'UniversalLanguageSelector', event )
.done( deferred.resolve )
.fail( deferred.reject );
} );
if ( timeout !== undefined ) {
window.setTimeout( deferred.reject, timeout );
}
return deferred.promise();
};
/**