2014-04-25 11:43:42 +00:00
|
|
|
( function ( $, mw ) {
|
|
|
|
|
|
|
|
/**
|
2015-03-19 09:19:39 +00:00
|
|
|
* @class mw.popups.logger
|
2014-04-25 11:43:42 +00:00
|
|
|
* @singleton
|
|
|
|
*/
|
2015-03-19 09:19:39 +00:00
|
|
|
var logger = {};
|
2014-04-25 11:43:42 +00:00
|
|
|
|
2015-03-26 01:28:29 +00:00
|
|
|
/**
|
|
|
|
* Sampling rate at which events are logged
|
|
|
|
* @property samplingRate
|
|
|
|
*/
|
|
|
|
logger.samplingRate = 10;
|
|
|
|
|
2014-04-25 11:43:42 +00:00
|
|
|
/**
|
2015-03-19 11:04:29 +00:00
|
|
|
* Get action based on click event
|
2014-04-25 11:43:42 +00:00
|
|
|
*
|
2015-03-19 11:04:29 +00:00
|
|
|
* @method getAction
|
2014-04-25 11:43:42 +00:00
|
|
|
* @param {Object} event
|
2016-04-15 22:52:23 +00:00
|
|
|
* @return {string}
|
2014-04-25 11:43:42 +00:00
|
|
|
*/
|
2015-03-19 11:04:29 +00:00
|
|
|
logger.getAction = function ( event ) {
|
2014-04-25 11:43:42 +00:00
|
|
|
if ( event.which === 2 ) { // middle click
|
2015-03-19 11:04:29 +00:00
|
|
|
return 'opened in new tab';
|
2014-04-25 11:43:42 +00:00
|
|
|
} else if ( event.which === 1 ) {
|
|
|
|
if ( event.ctrlKey || event.metaKey ) {
|
2015-03-19 11:04:29 +00:00
|
|
|
return 'opened in new tab';
|
2014-04-25 11:43:42 +00:00
|
|
|
} else if ( event.shiftKey ) {
|
2015-03-19 11:04:29 +00:00
|
|
|
return 'opened in new window';
|
2014-04-25 11:43:42 +00:00
|
|
|
} else {
|
2015-03-19 11:04:29 +00:00
|
|
|
return 'opened in same tab';
|
2014-04-25 11:43:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Logs the popup event as defined in the following schema-
|
|
|
|
* https://meta.wikimedia.org/wiki/Schema:Popups
|
|
|
|
*
|
2015-03-19 09:19:39 +00:00
|
|
|
* @method log
|
2015-03-19 11:04:29 +00:00
|
|
|
* @param {Object} event
|
|
|
|
* @return {jQuery.Promise}
|
2014-04-25 11:43:42 +00:00
|
|
|
*/
|
2015-03-19 11:04:29 +00:00
|
|
|
logger.log = function ( event ) {
|
2015-03-26 01:28:29 +00:00
|
|
|
if (
|
|
|
|
mw.eventLog === undefined ||
|
|
|
|
Math.floor( Math.random() * logger.samplingRate ) !== 0
|
|
|
|
) {
|
2015-03-19 11:04:29 +00:00
|
|
|
return $.Deferred().resolve();
|
2015-01-09 02:16:25 +00:00
|
|
|
}
|
|
|
|
|
2015-03-19 11:04:29 +00:00
|
|
|
// Get duration from time
|
2015-03-26 01:25:54 +00:00
|
|
|
if ( $.isNumeric( event.time ) ) {
|
|
|
|
event.duration = Math.floor( mw.now() - event.time );
|
2016-04-15 22:52:23 +00:00
|
|
|
// FIXME: the time property should not be sent to the back-end regardless of its value.
|
2015-03-26 01:25:54 +00:00
|
|
|
delete event.time;
|
|
|
|
}
|
2014-04-25 11:43:42 +00:00
|
|
|
|
2015-08-26 10:15:16 +00:00
|
|
|
return mw.eventLog.logEvent( 'Popups', event );
|
2014-04-25 11:43:42 +00:00
|
|
|
};
|
|
|
|
|
2015-03-19 09:19:39 +00:00
|
|
|
mw.popups.logger = logger;
|
2014-04-25 11:43:42 +00:00
|
|
|
|
2015-08-26 10:15:16 +00:00
|
|
|
} )( jQuery, mediaWiki );
|