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,
|
|
|
|
extract: page.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 ) );
|
|
|
|
|
2016-08-18 22:20:48 +00:00
|
|
|
$readMore = $( '<aside class="ra-read-more noprint"></aside>' )
|
2015-11-16 10:40:03 +00:00
|
|
|
.append( $( '<h2></h2>' ).text( mw.msg( 'relatedarticles-read-more-heading' ) ) )
|
|
|
|
.append( cards.$el );
|
|
|
|
|
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
|
|
|
}() );
|