Remove delay when logging link clicks

EventLogging uses sendBeacon now so there is no danger of losing
clicks because the browser navigates away. (On modern browsers,
anyway; but we can live with being a little imprecise on older
browsers. We don't use link click stats much, anyway.)

Bug: T89533
Change-Id: Id83f60585d11f06610d8514c211f0116c60ea936
This commit is contained in:
Gergő Tisza 2015-02-15 06:18:55 +00:00
parent 4abcc2e13c
commit 1d79a5c483
5 changed files with 21 additions and 60 deletions

View file

@ -73,15 +73,13 @@
* @param {jQuery} $container
*/
DP.createDownloadButton = function ( $container ) {
var self = this;
// TODO: Use oojs-ui constructive button widget instead
this.$downloadButton = $( '<a>' )
.attr( 'target', '_blank' )
.attr( 'download', '' )
.addClass( 'mw-ui-button mw-ui-constructive mw-mmv-download-go-button' )
.click( function ( e ) {
self.trackLinkClick.call( this, 'download', e );
.click( function () {
mw.mmv.actionLogger.log( 'download' );
} );
this.$selectionArrow = $( '<span>' )
@ -127,15 +125,13 @@
* @param {jQuery} $container
*/
DP.createPreviewLink = function ( $container ) {
var self = this;
this.$previewLink = $( '<a>' )
.attr( 'target', '_blank' )
.addClass( 'mw-mmv-download-preview-link' )
.text( mw.message( 'multimediaviewer-download-preview-link-title' ).text() )
.appendTo( $container )
.click( function ( e ) {
self.trackLinkClick.call( this, 'download-view-in-browser', e );
.click( function () {
mw.mmv.actionLogger.log( 'download-view-in-browser' );
} );
};

View file

@ -195,30 +195,6 @@
}
};
/**
* Tracks a click on a link and lets the user navigate to it
* @param {string} action The action label to log.
* @param {jQuery.Event} e Click event object
*/
EP.trackLinkClick = function ( action, e ) {
var $link = $( this );
if ( e.altKey || e.shiftKey || e.ctrlKey || e.metaKey || e.button === 1 ) {
// They are likely opening the link in a new window or tab
mw.mmv.actionLogger.log( action );
return;
}
// If it's a plain click, we need to wait for the logging to
// be done before navigating to the desired page
e.preventDefault();
// We want to redirect anyway, whether logging worked or not
mw.mmv.actionLogger.log( action ).always( function () {
window.location.href = $link.prop( 'href' );
} );
};
/**
* Makes the entire input/textarea selected when focused.
* Invoked with that input/textarea as context.

View file

@ -253,23 +253,21 @@
* Initializes the credit elements.
*/
MPP.initializeCredit = function () {
var panel = this;
this.$credit = $( '<p>' )
.addClass( 'mw-mmv-credit empty' )
.appendTo( this.$imageMetadataLeft )
.on( 'click.mmv-mp', '.mw-mmv-credit-fallback', function ( e ) {
panel.trackLinkClick( this, 'author-page', e );
.on( 'click.mmv-mp', '.mw-mmv-credit-fallback', function () {
mw.mmv.actionLogger.log( 'author-page' );
} );
// we need an inline container for tipsy, otherwise it would be centered weirdly
this.$authorAndSource = $( '<span>' )
.addClass( 'mw-mmv-source-author' )
.on( 'click', '.mw-mmv-author a', function ( e ) {
panel.trackLinkClick.call( this, 'author-page', e );
.on( 'click', '.mw-mmv-author a', function () {
mw.mmv.actionLogger.log( 'author-page' );
} )
.on( 'click', '.mw-mmv-source a', function ( e ) {
panel.trackLinkClick.call( this, 'source-page', e );
.on( 'click', '.mw-mmv-source a', function () {
mw.mmv.actionLogger.log( 'source-page' );
} );
@ -323,8 +321,8 @@
.addClass( 'mw-mmv-license' )
.prop( 'href', '#' )
.appendTo( this.$licenseLi )
.on( 'click', function ( e ) {
panel.trackLinkClick.call( this, 'license-page', e );
.on( 'click', function () {
mw.mmv.actionLogger.log( 'license-page' );
} );
this.$restrictions = $( '<span>' )
@ -391,8 +389,6 @@
* Initializes the link to the uploader's file page.
*/
MPP.initializeUploader = function () {
var self = this;
this.$usernameLi = $( '<li>' )
.addClass( 'mw-mmv-username-li empty' )
.appendTo( this.$imageLinks );
@ -401,15 +397,13 @@
.addClass( 'mw-mmv-username' )
.prop( 'href', '#' )
.appendTo( this.$usernameLi )
.click( function ( e ) { self.trackLinkClick.call( this, 'uploader-page', e ); } );
.click( function () { mw.mmv.actionLogger.log( 'uploader-page' ); } );
};
/**
* Initializes the geolocation element.
*/
MPP.initializeLocation = function () {
var self = this;
this.$locationLi = $( '<li>' )
.addClass( 'mw-mmv-location-li empty' )
.appendTo( this.$imageLinks );
@ -417,33 +411,32 @@
this.$location = $( '<a>' )
.addClass( 'mw-mmv-location' )
.appendTo( this.$locationLi )
.click( function ( e ) { self.trackLinkClick.call( this, 'location-page', e ); } );
.click( function () { mw.mmv.actionLogger.log( 'location-page' ); } );
};
/**
* Initializes two about links at the bottom of the panel.
*/
MPP.initializeAboutLinks = function () {
var separator = ' | ',
self = this;
var separator = ' | ';
this.$mmvAboutLink = $( '<a>' )
.prop( 'href', mw.config.get( 'wgMultimediaViewer' ).infoLink )
.text( mw.message( 'multimediaviewer-about-mmv' ).text() )
.addClass( 'mw-mmv-about-link' )
.click( function ( e ) { self.trackLinkClick.call( this, 'about-page', e ); } );
.click( function () { mw.mmv.actionLogger.log( 'about-page' ); } );
this.$mmvDiscussLink = $( '<a>' )
.prop( 'href', mw.config.get( 'wgMultimediaViewer' ).discussionLink )
.text( mw.message( 'multimediaviewer-discuss-mmv' ).text() )
.addClass( 'mw-mmv-discuss-link' )
.click( function ( e ) { self.trackLinkClick.call( this, 'discuss-page', e ); } );
.click( function () { mw.mmv.actionLogger.log( 'discuss-page' ); } );
this.$mmvHelpLink = $( '<a>' )
.prop( 'href', mw.config.get( 'wgMultimediaViewer' ).helpLink )
.text( mw.message( 'multimediaviewer-help-mmv' ).text() )
.addClass( 'mw-mmv-help-link' )
.click( function ( e ) { self.trackLinkClick.call( this, 'help-page', e ); } );
.click( function () { mw.mmv.actionLogger.log( 'help-page' ); } );
this.$mmvAboutLinks = $( '<div>' )
.addClass( 'mw-mmv-about-links' )

View file

@ -39,8 +39,6 @@
SP = Share.prototype;
SP.init = function () {
var self = this;
this.$pane.addClass( 'mw-mmv-share-pane' )
.appendTo( this.$container );
@ -63,8 +61,8 @@
.prop( 'target', '_blank' )
.html( '&nbsp;' )
.appendTo( this.$pane )
.click( function ( e ) {
self.trackLinkClick.call( this, 'share-page', e );
.click( function () {
mw.mmv.actionLogger.log( 'share-page' );
} );
this.pageInput.$element.appendTo( this.$pane );

View file

@ -363,13 +363,11 @@
* @param {jQuery} $div The panel to which we're adding the link.
*/
ODP.addInfoLink = function ( $div, eventName ) {
var self = this;
$( '<a>' )
.addClass( 'mw-mmv-project-info-link' )
.prop( 'href', mw.config.get( 'wgMultimediaViewer' ).helpLink )
.text( mw.message( 'multimediaviewer-options-learn-more' ) )
.click( function ( e ) { self.trackLinkClick.call( this, eventName, e ); } )
.click( function () { mw.mmv.actionLogger.log( eventName ); } )
.appendTo( $div.find( '.mw-mmv-options-text' ) );
};