2017-06-06 23:38:57 +00:00
|
|
|
/* eslint-disable no-underscore-dangle */
|
2022-04-14 23:11:07 +00:00
|
|
|
'use strict';
|
2017-06-06 23:38:57 +00:00
|
|
|
|
2022-04-14 23:11:07 +00:00
|
|
|
/**
|
|
|
|
* Renders a Card model and updates when it does.
|
|
|
|
*
|
|
|
|
* @class mw.cards.CardView
|
|
|
|
* @param {mw.cards.CardModel} model
|
|
|
|
*/
|
|
|
|
function CardView( model ) {
|
2017-06-06 23:38:57 +00:00
|
|
|
/**
|
2022-04-14 23:11:07 +00:00
|
|
|
* @property {mw.cards.CardModel}
|
2017-06-06 23:38:57 +00:00
|
|
|
*/
|
2022-04-14 23:11:07 +00:00
|
|
|
this.model = model;
|
2017-06-06 23:38:57 +00:00
|
|
|
|
2022-04-14 23:11:07 +00:00
|
|
|
// listen to model changes and re-render the view
|
|
|
|
this.model.on( 'change', this.render.bind( this ) );
|
2017-06-06 23:38:57 +00:00
|
|
|
|
|
|
|
/**
|
2022-04-14 23:11:07 +00:00
|
|
|
* @property {jQuery}
|
2017-06-06 23:38:57 +00:00
|
|
|
*/
|
2022-04-14 23:11:07 +00:00
|
|
|
this.$el = $( this._render() );
|
|
|
|
}
|
|
|
|
OO.initClass( CardView );
|
2017-06-06 23:38:57 +00:00
|
|
|
|
2022-04-14 23:11:07 +00:00
|
|
|
/**
|
|
|
|
* Replace the html of this.$el with a newly rendered html using the model
|
|
|
|
* attributes.
|
|
|
|
*/
|
|
|
|
CardView.prototype.render = function () {
|
|
|
|
this.$el.replaceWith( this._render() );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the template using the model attributes.
|
|
|
|
*
|
|
|
|
* @ignore
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
CardView.prototype._render = function () {
|
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-18 22:20:04 +00:00
|
|
|
const $listItem = $( '<li>' ),
|
2022-04-14 23:11:07 +00:00
|
|
|
attributes = $.extend( {}, this.model.attributes );
|
2019-04-09 16:13:19 +00:00
|
|
|
|
2022-04-14 23:11:07 +00:00
|
|
|
attributes.thumbnailUrl = CSS.escape( attributes.thumbnailUrl );
|
2017-06-06 23:38:57 +00:00
|
|
|
|
2022-04-14 23:11:07 +00:00
|
|
|
$listItem.attr( {
|
|
|
|
title: attributes.title,
|
|
|
|
class: 'ext-related-articles-card'
|
|
|
|
} );
|
2019-04-09 16:13:19 +00:00
|
|
|
|
2022-04-14 23:11:07 +00:00
|
|
|
$listItem.append(
|
|
|
|
$( '<div>' )
|
|
|
|
.addClass( 'ext-related-articles-card-thumb' )
|
|
|
|
.addClass( attributes.hasThumbnail ?
|
2023-08-30 17:52:06 +00:00
|
|
|
'mw-no-invert' :
|
2022-04-14 23:11:07 +00:00
|
|
|
'ext-related-articles-card-thumb-placeholder'
|
|
|
|
)
|
|
|
|
.css( 'background-image', attributes.hasThumbnail ?
|
|
|
|
'url(' + attributes.thumbnailUrl + ')' :
|
|
|
|
null
|
|
|
|
),
|
|
|
|
$( '<a>' )
|
|
|
|
.attr( {
|
|
|
|
href: attributes.url,
|
|
|
|
'aria-hidden': 'true',
|
|
|
|
tabindex: -1
|
|
|
|
} ),
|
|
|
|
$( '<div>' )
|
|
|
|
.attr( { class: 'ext-related-articles-card-detail' } )
|
|
|
|
.append(
|
|
|
|
$( '<h3>' ).append(
|
|
|
|
$( '<a>' )
|
|
|
|
.attr( { href: attributes.url } )
|
|
|
|
.text( attributes.title )
|
2019-05-01 11:01:56 +00:00
|
|
|
),
|
2022-04-14 23:11:07 +00:00
|
|
|
$( '<p>' )
|
|
|
|
.attr( { class: 'ext-related-articles-card-extract' } )
|
|
|
|
.text( attributes.extract )
|
|
|
|
)
|
|
|
|
);
|
2019-04-09 16:13:19 +00:00
|
|
|
|
2022-04-14 23:11:07 +00:00
|
|
|
return $listItem;
|
|
|
|
};
|
2017-06-06 23:38:57 +00:00
|
|
|
|
2022-04-14 23:11:07 +00:00
|
|
|
module.exports = CardView;
|