mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/RelatedArticles
synced 2024-12-23 13:23:36 +00:00
911d78e8ee
Follow up to I9442b0336e22ca795cc06f76068215266fe81271 Bug: T306228 Change-Id: Ifb1f1937009b098999471cfa5e820a063dc5a4a0
53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
( function () {
|
|
/**
|
|
* Renders the related articles.
|
|
*/
|
|
function main() {
|
|
var CardModel = require( './CardModel.js' ),
|
|
CardView = require( './CardView.js' ),
|
|
CardListView = require( './CardListView.js' );
|
|
|
|
/**
|
|
* Generates `mw.cards.CardView`s from pages
|
|
*
|
|
* @param {Object[]} pages
|
|
* @return {mw.cards.CardView[]}
|
|
*/
|
|
function getCards( pages ) {
|
|
return pages.map( function ( page ) {
|
|
var result = {
|
|
title: page.title,
|
|
url: mw.util.getUrl( page.title ),
|
|
hasThumbnail: false,
|
|
extract: ( page.description || page.extract ||
|
|
( page.pageprops ? page.pageprops.description : '' ) )
|
|
};
|
|
|
|
if ( page.thumbnail ) {
|
|
result.hasThumbnail = true;
|
|
result.thumbnailUrl = page.thumbnail.source;
|
|
result.isThumbnailPortrait = page.thumbnail.height >= page.thumbnail.width;
|
|
}
|
|
|
|
return new CardView( new CardModel( result ) );
|
|
} );
|
|
}
|
|
|
|
mw.trackSubscribe( 'ext.relatedArticles.init', function ( _, pages ) {
|
|
var $readMore,
|
|
cards;
|
|
|
|
cards = new CardListView( getCards( pages ) );
|
|
|
|
$readMore = $( '<aside>' ).addClass( 'ra-read-more noprint' )
|
|
.append( $( '<h2>' ).text( mw.msg( 'relatedarticles-read-more-heading' ) ) )
|
|
.append( cards.$el );
|
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
|
$( '.read-more-container' ).append( $readMore );
|
|
} );
|
|
}
|
|
main();
|
|
|
|
}() );
|