mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/RelatedArticles
synced 2024-12-18 19:10:54 +00:00
7c23636954
If the page has related articles, is in mainspace, isn't the main page, and the output is being rendered with the MinervaBeta skin then a "Related Articles" section is added to the page just before the footer. Separate loading the information necessary to render the pages, choosing the renderer, and rendering the data so that multiple skins - currently Minerva and Vector per the mocks - not just multiple resolutions can all be handled the same way: * The bootstrap script (ext.relatedArticles.readMore.bootstrap/index.js) for fetches the page image and Wikidata description; loading the renderer module; and, finally, notifying the renderer module that it should render the data, which it does by emitting "ext.relatedArticles.readMore.init" event using mw#track * The Minerva renderer subscribes to the event and, when it's fired, renders the data by passing it to the WatchstarPageList view Bug: T113635 Change-Id: I651342bdf9796938fa7051828dd13bc6fe774783
53 lines
1.4 KiB
JavaScript
53 lines
1.4 KiB
JavaScript
( function ( $ ) {
|
|
|
|
var MOBILE_WEB_WATCHING_FUNNEL = 'read-more';
|
|
|
|
/**
|
|
* Converts the set of pages generated in the init script into a set of
|
|
* `Page`s, suitable for use with `WatchstarPageList`.
|
|
*
|
|
* @param {Object[]} pages
|
|
* @return {Page[]}
|
|
*/
|
|
function convertPages( pages ) {
|
|
var Page = mw.mobileFrontend.require( 'mobile.startup/Page' );
|
|
|
|
return $.map( pages, function ( rawPage ) {
|
|
return new Page( {
|
|
id: rawPage.id,
|
|
title: rawPage.title,
|
|
thumbnail: rawPage.thumbnail,
|
|
wikidataDescription: rawPage.description
|
|
} );
|
|
} );
|
|
}
|
|
|
|
mw.trackSubscribe( 'ext.relatedArticles.init', function ( _, data ) {
|
|
var WatchstarPageList = mw.mobileFrontend.require( 'mobile.pagelist.scripts/WatchstarPageList' ),
|
|
pageList,
|
|
$container = $( '#content' ),
|
|
$readMore;
|
|
|
|
pageList = new WatchstarPageList( {
|
|
pages: convertPages( data.pages ),
|
|
|
|
// FIXME: When the user clicks any watchstar, a
|
|
// MobileWebWatching event is logged. Watchstar, which
|
|
// logs the event, has a sensible default value for
|
|
// MobileWebWatching.funnel, but it's overwritten
|
|
// by WatchstarPageList.
|
|
funnel: MOBILE_WEB_WATCHING_FUNNEL
|
|
} );
|
|
|
|
$readMore = $( '<aside class="ra-read-more post-content"></aside>' );
|
|
$readMore.append(
|
|
$( '<h2></h2>' ).text( mw.msg( 'relatedarticles-read-more-heading' ) )
|
|
);
|
|
|
|
$readMore.append( pageList.$el );
|
|
|
|
$container.append( $readMore );
|
|
} );
|
|
|
|
}( jQuery ) );
|