mediawiki-extensions-Relate.../resources/ext.relatedArticles.readMore/index.js
Jon Robson e5431a1c0b Limit RelatedArticles feature to ES6 browsers
We currently require support for IntersectionObserver.
which is supported on Edge >= 15 (15 has partial support),
Firefox >55, Chrome >58, Safari 12.1, Opera >=38,
iOS Safari >=12.2, Android 100

Full ES6 is supported in Edge >=15, Firefox >=54, Chrome >=51,
Safari >=10, Opera >=38, iOS Safari >=10, so such a change
would only drop support for Edge 15 and Firefox 54.

CSS.escape is guaranteed in all these browsers according to
caniuse, with the only discrepancy being the Edge browser (versions
16-18) so it is also suggested we remove support for those browsers.

Firefox 54 accounts for 0.0026% of page views
Edge 15-18 accounts for 0.069% of page views

Bug: T306355
Change-Id: Id2987e3456607b610c38da9ee157a026d1d00ada
2022-04-27 15:45:42 +00:00

49 lines
1.2 KiB
JavaScript

const 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 ) {
const 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 ) );
} );
}
/**
* Renders the related articles.
*
* @param {Object[]} pages
* @param {Element} el
*/
function render( pages, el ) {
const cards = new CardListView( getCards( pages ) ),
$readMore = $( '<aside>' ).addClass( 'ra-read-more noprint' )
.append( $( '<h2>' ).text( mw.msg( 'relatedarticles-read-more-heading' ) ) )
.append( cards.$el );
$( el ).append( $readMore );
}
module.exports = {
render,
getCards
};