2023-08-21 08:08:23 +00:00
|
|
|
'use strict';
|
|
|
|
|
2019-09-20 13:03:16 +00:00
|
|
|
/**
|
2024-06-10 15:15:48 +00:00
|
|
|
* Temporary tracking to evaluate the impact of Reference Previews on
|
2024-01-30 11:18:52 +00:00
|
|
|
* users' interaction with references.
|
2019-10-24 14:56:18 +00:00
|
|
|
*
|
2024-06-10 15:15:48 +00:00
|
|
|
* @memberof module:ext.cite.ux-enhancements
|
2019-10-24 14:56:18 +00:00
|
|
|
* @see https://phabricator.wikimedia.org/T214493
|
2019-09-20 13:03:16 +00:00
|
|
|
* @see https://phabricator.wikimedia.org/T231529
|
2024-01-09 14:29:00 +00:00
|
|
|
* @see https://phabricator.wikimedia.org/T353798
|
2019-09-20 13:03:16 +00:00
|
|
|
* @see https://meta.wikimedia.org/wiki/Schema:ReferencePreviewsBaseline
|
2019-10-24 14:56:18 +00:00
|
|
|
* @see https://meta.wikimedia.org/wiki/Schema:ReferencePreviewsCite
|
2019-09-20 13:03:16 +00:00
|
|
|
*/
|
2020-12-13 17:56:00 +00:00
|
|
|
|
2024-01-09 14:29:00 +00:00
|
|
|
const CITE_BASELINE_LOGGING_SCHEMA = 'ext.cite.baseline';
|
|
|
|
// Same as in the Popups extension
|
|
|
|
// FIXME: Could be an extension wide constant when Reference Previews is merged into this code base
|
|
|
|
const REFERENCE_PREVIEWS_LOGGING_SCHEMA = 'event.ReferencePreviewsPopups';
|
|
|
|
|
2020-12-13 17:56:00 +00:00
|
|
|
// EventLogging may not be installed
|
2024-05-31 14:27:11 +00:00
|
|
|
mw.loader.using( 'ext.eventLogging' ).then( () => {
|
|
|
|
$( () => {
|
2019-11-13 13:23:47 +00:00
|
|
|
if ( !navigator.sendBeacon ||
|
2024-01-09 14:29:00 +00:00
|
|
|
!mw.config.get( 'wgIsArticle' )
|
2019-11-13 13:23:47 +00:00
|
|
|
) {
|
|
|
|
return;
|
2019-10-24 14:56:18 +00:00
|
|
|
}
|
2019-11-13 13:23:47 +00:00
|
|
|
|
2024-01-09 14:29:00 +00:00
|
|
|
// FIXME: This might be obsolete when the code moves to the this extension
|
2024-05-31 14:27:11 +00:00
|
|
|
mw.trackSubscribe( REFERENCE_PREVIEWS_LOGGING_SCHEMA, ( type, data ) => {
|
2024-01-09 14:29:00 +00:00
|
|
|
if ( data.action.indexOf( 'anonymous' ) !== -1 ) {
|
2024-04-15 08:29:38 +00:00
|
|
|
mw.config.set( 'wgCiteReferencePreviewsVisible', data.action === 'anonymousEnabled' );
|
2024-01-09 14:29:00 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2019-11-13 13:23:47 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
|
|
|
$( '#mw-content-text' ).on(
|
|
|
|
'click',
|
|
|
|
// Footnote links, references block in VisualEditor, and reference content links.
|
|
|
|
'.reference a[ href*="#" ], .mw-reference-text a, .reference-text a',
|
|
|
|
function () {
|
2023-08-21 08:08:23 +00:00
|
|
|
const isInReferenceBlock = $( this ).parents( '.references' ).length > 0;
|
2024-01-09 14:29:00 +00:00
|
|
|
mw.eventLog.dispatch( CITE_BASELINE_LOGGING_SCHEMA, {
|
2019-11-13 13:23:47 +00:00
|
|
|
action: ( isInReferenceBlock ?
|
|
|
|
'clickedReferenceContentLink' :
|
2024-01-09 14:29:00 +00:00
|
|
|
'clickedFootnote' ),
|
|
|
|
// FIXME: This might be obsolete when the code moves to the this extension and
|
|
|
|
// we get state directly.
|
|
|
|
// eslint-disable-next-line camelcase
|
2024-04-15 08:29:38 +00:00
|
|
|
with_ref_previews: mw.config.get( 'wgCiteReferencePreviewsVisible' )
|
2019-11-13 13:23:47 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
);
|
2019-10-24 14:56:18 +00:00
|
|
|
} );
|
2020-12-13 17:56:00 +00:00
|
|
|
} );
|