2018-09-14 05:30:46 +00:00
|
|
|
( function () {
|
2017-06-06 23:38:57 +00:00
|
|
|
// Make sure 'ext.relatedArticles.cards' is loaded. It may not be because of the race
|
2015-11-16 10:40:03 +00:00
|
|
|
// condition in the bootstrap file.
|
2017-06-06 23:38:57 +00:00
|
|
|
mw.loader.using( 'ext.relatedArticles.cards' ).done( function () {
|
2015-11-16 10:40:03 +00:00
|
|
|
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 ) {
|
2018-08-17 10:27:26 +00:00
|
|
|
return pages.map( function ( page ) {
|
2015-11-16 10:40:03 +00:00
|
|
|
var result = {
|
|
|
|
title: page.title,
|
|
|
|
url: mw.util.getUrl( page.title ),
|
2018-04-12 07:58:55 +00:00
|
|
|
hasThumbnail: false,
|
2019-08-23 18:15:32 +00:00
|
|
|
extract: ( page.description || page.extract ||
|
|
|
|
( page.pageprops ? page.pageprops.description : '' ) )
|
2015-11-16 10:40:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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 ) );
|
|
|
|
|
2019-02-10 16:46:48 +00:00
|
|
|
$readMore = $( '<aside>' ).addClass( 'ra-read-more noprint' )
|
2020-06-23 19:30:43 +00:00
|
|
|
.append( $( '<h2>' ).text( mw.msg( 'relatedarticles-read-more-heading' ) ) )
|
2015-11-16 10:40:03 +00:00
|
|
|
.append( cards.$el );
|
|
|
|
|
2019-04-03 23:20:58 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
2016-08-30 18:01:48 +00:00
|
|
|
$( '.read-more-container' ).append( $readMore );
|
2015-11-16 10:40:03 +00:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2018-09-14 05:30:46 +00:00
|
|
|
}() );
|