mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-14 11:15:08 +00:00
6eef4f325b
Adds the jscs and jshint packages for development and their tasks in Grunt. Also fixes all the code convention errors. Change-Id: If1c9dfdbe22d4912d78b6a51b1292866970a85cc
63 lines
1.3 KiB
JavaScript
63 lines
1.3 KiB
JavaScript
( function ( $, mw ) {
|
|
|
|
/**
|
|
* @class mw.popups.logger
|
|
* @singleton
|
|
*/
|
|
var logger = {};
|
|
|
|
/**
|
|
* Sampling rate at which events are logged
|
|
* @property samplingRate
|
|
*/
|
|
logger.samplingRate = 10;
|
|
|
|
/**
|
|
* Get action based on click event
|
|
*
|
|
* @method getAction
|
|
* @param {Object} event
|
|
*/
|
|
logger.getAction = function ( event ) {
|
|
if ( event.which === 2 ) { // middle click
|
|
return 'opened in new tab';
|
|
} else if ( event.which === 1 ) {
|
|
if ( event.ctrlKey || event.metaKey ) {
|
|
return 'opened in new tab';
|
|
} else if ( event.shiftKey ) {
|
|
return 'opened in new window';
|
|
} else {
|
|
return 'opened in same tab';
|
|
}
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Logs the popup event as defined in the following schema-
|
|
* https://meta.wikimedia.org/wiki/Schema:Popups
|
|
*
|
|
* @method log
|
|
* @param {Object} event
|
|
* @return {jQuery.Promise}
|
|
*/
|
|
logger.log = function ( event ) {
|
|
if (
|
|
mw.eventLog === undefined ||
|
|
Math.floor( Math.random() * logger.samplingRate ) !== 0
|
|
) {
|
|
return $.Deferred().resolve();
|
|
}
|
|
|
|
// Get duration from time
|
|
if ( $.isNumeric( event.time ) ) {
|
|
event.duration = Math.floor( mw.now() - event.time );
|
|
delete event.time;
|
|
}
|
|
|
|
return mw.eventLog.logEvent( 'Popups', event );
|
|
};
|
|
|
|
mw.popups.logger = logger;
|
|
|
|
} )( jQuery, mediaWiki );
|