mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/RelatedArticles
synced 2024-12-19 11:30:44 +00:00
dc2e65a084
Previously RelatedArticles required the Cards extension This code refers to that old state and is cleaned up. ext.relatedArticles.cards is added a dependency of ext.relatedArticles.readMore since it now belongs to the same extension Change-Id: I4a89ed4256a4ae9fd22b0191748bd47ac3ffc593
53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
( function () {
|
|
/**
|
|
* Renders the related articles.
|
|
*/
|
|
function main() {
|
|
var CardModel = mw.cards.CardModel,
|
|
CardView = mw.cards.CardView,
|
|
CardListView = mw.cards.CardListView;
|
|
|
|
/**
|
|
* 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();
|
|
|
|
}() );
|