2016-05-10 12:42:05 +00:00
|
|
|
( function ( mw, $ ) {
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* @param {Revision[]} revs
|
|
|
|
* @constructor
|
|
|
|
*/
|
2016-05-10 12:42:05 +00:00
|
|
|
var RevisionList = function ( revs ) {
|
2016-05-10 16:45:11 +00:00
|
|
|
this.revisions = [];
|
2016-05-10 12:42:05 +00:00
|
|
|
this.initialize( revs );
|
|
|
|
this.view = new mw.libs.revisionSlider.RevisionListView( this );
|
|
|
|
};
|
|
|
|
|
|
|
|
$.extend( RevisionList.prototype, {
|
|
|
|
/**
|
|
|
|
* @type {Revision[]}
|
|
|
|
*/
|
|
|
|
revisions: [],
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {RevisionListView}
|
|
|
|
*/
|
|
|
|
view: null,
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* Inititializes the RevisionList from a list of Revisions
|
|
|
|
*
|
|
|
|
* @param {Revision[]} revs
|
|
|
|
*/
|
2016-05-10 12:42:05 +00:00
|
|
|
initialize: function ( revs ) {
|
2016-05-12 13:52:54 +00:00
|
|
|
var i, rev;
|
2016-05-10 12:42:05 +00:00
|
|
|
|
|
|
|
for ( i = 0; i < revs.length; i++ ) {
|
2016-07-04 20:45:34 +00:00
|
|
|
rev = revs[ i ];
|
|
|
|
rev.setRelativeSize( i > 0 ? rev.getSize() - revs[ i - 1 ].getSize() : rev.getSize() );
|
2016-05-12 13:52:54 +00:00
|
|
|
|
|
|
|
this.revisions.push( rev );
|
2016-05-10 12:42:05 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* @return {number}
|
|
|
|
*/
|
2016-05-10 12:42:05 +00:00
|
|
|
getBiggestChangeSize: function () {
|
|
|
|
var max = 0,
|
2016-05-12 13:52:54 +00:00
|
|
|
i;
|
2016-05-10 12:42:05 +00:00
|
|
|
|
2016-05-12 13:52:54 +00:00
|
|
|
for ( i = 0; i < this.revisions.length; i++ ) {
|
|
|
|
max = Math.max( max, Math.abs( this.revisions[ i ].getRelativeSize() ) );
|
2016-05-10 12:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return max;
|
|
|
|
},
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* @return {Revision[]}
|
|
|
|
*/
|
2016-05-10 12:42:05 +00:00
|
|
|
getRevisions: function () {
|
|
|
|
return this.revisions;
|
|
|
|
},
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* @return {number}
|
|
|
|
*/
|
2016-05-10 12:42:05 +00:00
|
|
|
getLength: function () {
|
|
|
|
return this.revisions.length;
|
|
|
|
},
|
|
|
|
|
2016-07-25 13:35:41 +00:00
|
|
|
/**
|
2016-06-27 14:00:13 +00:00
|
|
|
* @return {RevisionListView}
|
2016-07-25 13:35:41 +00:00
|
|
|
*/
|
2016-06-27 14:00:13 +00:00
|
|
|
getView: function () {
|
|
|
|
return this.view;
|
2016-07-25 13:35:41 +00:00
|
|
|
},
|
|
|
|
|
2016-06-27 14:00:13 +00:00
|
|
|
getUserGenders: function () {
|
|
|
|
var userGenders = {};
|
2016-07-25 13:35:41 +00:00
|
|
|
this.revisions.forEach( function ( revision ) {
|
2016-06-27 14:00:13 +00:00
|
|
|
if ( revision.getUser() ) {
|
|
|
|
userGenders[ revision.getUser() ] = revision.getUserGender();
|
2016-07-25 13:35:41 +00:00
|
|
|
}
|
|
|
|
} );
|
2016-06-27 14:00:13 +00:00
|
|
|
return userGenders;
|
2016-07-25 13:35:41 +00:00
|
|
|
},
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
2016-06-27 14:00:13 +00:00
|
|
|
* Adds revisions to the end of the list.
|
|
|
|
*
|
|
|
|
* @param {Revision[]} revs
|
2016-06-17 13:06:12 +00:00
|
|
|
*/
|
2016-06-27 14:00:13 +00:00
|
|
|
push: function ( revs ) {
|
|
|
|
var i, rev;
|
|
|
|
for ( i = 0; i < revs.length; i++ ) {
|
|
|
|
rev = revs[ i ];
|
|
|
|
rev.setRelativeSize(
|
|
|
|
i > 0 ?
|
|
|
|
rev.getSize() - revs[ i - 1 ].getSize() :
|
|
|
|
rev.getSize() - this.revisions[ this.revisions.length - 1 ].getSize()
|
|
|
|
);
|
|
|
|
|
|
|
|
this.revisions.push( rev );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds revisions to the beginning of the list.
|
|
|
|
*
|
|
|
|
* @param {Revision[]} revs
|
|
|
|
* @param {number} sizeBefore optional size of the revision preceding the first of revs, defaults to 0
|
|
|
|
*/
|
|
|
|
unshift: function ( revs, sizeBefore ) {
|
|
|
|
var originalFirstRev = this.revisions[ 0 ],
|
|
|
|
i, rev;
|
|
|
|
sizeBefore = sizeBefore || 0;
|
|
|
|
|
|
|
|
originalFirstRev.setRelativeSize( originalFirstRev.getSize() - revs[ revs.length - 1 ].getSize() );
|
|
|
|
for ( i = revs.length - 1; i >= 0; i-- ) {
|
|
|
|
rev = revs[ i ];
|
|
|
|
rev.setRelativeSize( i > 0 ? rev.getSize() - revs[ i - 1 ].getSize() : rev.getSize() - sizeBefore );
|
|
|
|
|
|
|
|
this.revisions.unshift( rev );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a subset of the list.
|
|
|
|
*
|
|
|
|
* @param {number} begin
|
|
|
|
* @param {number} end
|
|
|
|
* @return {RevisionList}
|
|
|
|
*/
|
|
|
|
slice: function ( begin, end ) {
|
|
|
|
var slicedList = new mw.libs.revisionSlider.RevisionList( [] );
|
|
|
|
slicedList.view = new mw.libs.revisionSlider.RevisionListView( slicedList );
|
|
|
|
slicedList.revisions = this.revisions.slice( begin, end );
|
|
|
|
return slicedList;
|
2016-05-10 12:42:05 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
mw.libs.revisionSlider = mw.libs.revisionSlider || {};
|
|
|
|
mw.libs.revisionSlider.RevisionList = RevisionList;
|
2016-07-04 20:45:34 +00:00
|
|
|
|
|
|
|
/**
|
2016-06-27 14:00:13 +00:00
|
|
|
* Transforms an array of revision data returned by MediaWiki API (including user gender information) into
|
2016-07-04 20:45:34 +00:00
|
|
|
* an array of Revision objects
|
|
|
|
*
|
|
|
|
* @param {Array} revs
|
|
|
|
* @return {Revision[]}
|
|
|
|
*/
|
|
|
|
mw.libs.revisionSlider.makeRevisions = function ( revs ) {
|
|
|
|
return revs.map( function ( revData ) {
|
|
|
|
return new mw.libs.revisionSlider.Revision( revData );
|
|
|
|
} );
|
|
|
|
};
|
2016-05-10 12:42:05 +00:00
|
|
|
}( mediaWiki, jQuery ) );
|