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
|
|
|
/**
|
|
|
|
* Model for an article
|
|
|
|
* It is the single source of truth about a Card, which is a representation
|
|
|
|
* of a wiki article. It emits a 'change' event when its attribute changes.
|
|
|
|
* A View can listen to this event and update the UI accordingly.
|
|
|
|
*
|
|
|
|
* @class mw.cards.CardModel
|
|
|
|
* @extends OO.EventEmitter
|
|
|
|
* @param {Object} attributes article data, such as title, url, etc. about
|
|
|
|
* an article
|
|
|
|
*/
|
|
|
|
function CardModel( attributes ) {
|
|
|
|
CardModel.super.apply( this, arguments );
|
2017-06-06 23:38:57 +00:00
|
|
|
/**
|
2022-04-14 23:11:07 +00:00
|
|
|
* @property {Object} attributes of the model
|
2017-06-06 23:38:57 +00:00
|
|
|
*/
|
2022-04-14 23:11:07 +00:00
|
|
|
this.attributes = attributes;
|
|
|
|
}
|
|
|
|
OO.inheritClass( CardModel, OO.EventEmitter );
|
2017-06-06 23:38:57 +00:00
|
|
|
|
2022-04-14 23:11:07 +00:00
|
|
|
/**
|
|
|
|
* Set a model attribute.
|
|
|
|
* Emits a 'change' event with the object whose key is the attribute
|
|
|
|
* that's being updated and value is the value that's being set. The event
|
|
|
|
* can also be silenced.
|
|
|
|
*
|
|
|
|
* @param {string} key attribute that's being set
|
|
|
|
* @param {Mixed} value the value of the key param
|
|
|
|
* @param {boolean} [silent] whether to emit the 'change' event. By default
|
|
|
|
* the 'change' event will be emitted.
|
|
|
|
*/
|
|
|
|
CardModel.prototype.set = function ( key, value, silent ) {
|
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 event = {};
|
2017-06-06 23:38:57 +00:00
|
|
|
|
2022-04-14 23:11:07 +00:00
|
|
|
this.attributes[ key ] = value;
|
|
|
|
if ( !silent ) {
|
|
|
|
event[ key ] = value;
|
|
|
|
this.emit( 'change', event );
|
|
|
|
}
|
|
|
|
};
|
2017-06-06 23:38:57 +00:00
|
|
|
|
2022-04-14 23:11:07 +00:00
|
|
|
/**
|
|
|
|
* Get the model attribute's value.
|
|
|
|
*
|
|
|
|
* @param {string} key attribute that's being looked up
|
|
|
|
* @return {Mixed}
|
|
|
|
*/
|
|
|
|
CardModel.prototype.get = function ( key ) {
|
|
|
|
return this.attributes[ key ];
|
|
|
|
};
|
2017-06-06 23:38:57 +00:00
|
|
|
|
2022-04-14 23:11:07 +00:00
|
|
|
module.exports = CardModel;
|