mediawiki-extensions-Relate.../resources/ext.relatedArticles.cards/CardView.js
Fomafix 00405b0309 Remove mediaWiki and jQuery from eslint globals
Remove all mappings in the closures like in
I7cf2426cde597259e8c6f3f6f615a1a81a0ca82b in core.

Change-Id: Ie9a2fadb8e276774784a4937bb5c3ec11f213352
2018-09-15 17:54:03 +00:00

55 lines
1.2 KiB
JavaScript

/* eslint-disable no-underscore-dangle */
( function () {
'use strict';
/**
* Renders a Card model and updates when it does.
*
* @class mw.cards.CardView
* @param {mw.cards.CardModel} model
*/
function CardView( model ) {
/**
* @property {mw.cards.CardModel}
*/
this.model = model;
// listen to model changes and re-render the view
this.model.on( 'change', this.render.bind( this ) );
/**
* @property {jQuery}
*/
this.$el = $( this._render() );
}
OO.initClass( CardView );
/**
* @property {Object} compiled template
*/
CardView.prototype.template = mw.template.get( 'ext.relatedArticles.cards', 'card.muhogan' );
/**
* 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 () {
var attributes = $.extend( {}, this.model.attributes );
attributes.thumbnailUrl = CSS.escape( attributes.thumbnailUrl );
return this.template.render( attributes );
};
mw.cards.CardView = CardView;
}() );