2018-11-16 16:33:52 +00:00
|
|
|
( function () {
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* Module handling the slider logic of the RevisionSlider
|
|
|
|
*
|
|
|
|
* @param {RevisionList} revisions
|
|
|
|
* @constructor
|
|
|
|
*/
|
2016-05-10 12:42:05 +00:00
|
|
|
var Slider = function ( revisions ) {
|
|
|
|
this.revisions = revisions;
|
2017-07-04 10:29:59 +00:00
|
|
|
this.view = new mw.libs.revisionSlider.SliderView( this );
|
2016-05-10 12:42:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$.extend( Slider.prototype, {
|
|
|
|
/**
|
|
|
|
* @type {RevisionList}
|
|
|
|
*/
|
|
|
|
revisions: null,
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* @type {number}
|
|
|
|
*/
|
2017-03-27 19:04:31 +00:00
|
|
|
oldestVisibleRevisionIndex: 0,
|
2016-05-10 12:42:05 +00:00
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* @type {number}
|
|
|
|
*/
|
2016-05-10 12:42:05 +00:00
|
|
|
revisionsPerWindow: 0,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {SliderView}
|
|
|
|
*/
|
|
|
|
view: null,
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* @return {RevisionList}
|
|
|
|
*/
|
2017-08-17 14:08:49 +00:00
|
|
|
getRevisionList: function () {
|
2016-05-10 12:42:05 +00:00
|
|
|
return this.revisions;
|
|
|
|
},
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* @return {SliderView}
|
|
|
|
*/
|
2016-05-10 12:42:05 +00:00
|
|
|
getView: function () {
|
|
|
|
return this.view;
|
|
|
|
},
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* Sets the number of revisions that are visible at once (depending on browser window size)
|
|
|
|
*
|
|
|
|
* @param {number} n
|
|
|
|
*/
|
2016-05-10 12:42:05 +00:00
|
|
|
setRevisionsPerWindow: function ( n ) {
|
|
|
|
this.revisionsPerWindow = n;
|
|
|
|
},
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* @return {number}
|
|
|
|
*/
|
2016-05-10 12:42:05 +00:00
|
|
|
getRevisionsPerWindow: function () {
|
|
|
|
return this.revisionsPerWindow;
|
|
|
|
},
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
2017-03-27 19:04:31 +00:00
|
|
|
* Returns the index of the oldest revision that is visible in the current window
|
2016-06-17 13:06:12 +00:00
|
|
|
*
|
|
|
|
* @return {number}
|
|
|
|
*/
|
2017-03-27 19:04:31 +00:00
|
|
|
getOldestVisibleRevisionIndex: function () {
|
|
|
|
return this.oldestVisibleRevisionIndex;
|
2016-05-10 12:42:05 +00:00
|
|
|
},
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
2017-03-27 19:04:31 +00:00
|
|
|
* Returns the index of the newest revision that is visible in the current window
|
2016-06-17 13:06:12 +00:00
|
|
|
*
|
|
|
|
* @return {number}
|
|
|
|
*/
|
2017-03-27 19:04:31 +00:00
|
|
|
getNewestVisibleRevisionIndex: function () {
|
|
|
|
return this.oldestVisibleRevisionIndex + this.revisionsPerWindow - 1;
|
2016-05-10 20:47:37 +00:00
|
|
|
},
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
2016-05-10 20:47:37 +00:00
|
|
|
isAtStart: function () {
|
2017-03-27 19:04:31 +00:00
|
|
|
return this.getOldestVisibleRevisionIndex() === 0 || this.revisions.getLength() <= this.revisionsPerWindow;
|
2016-05-10 20:47:37 +00:00
|
|
|
},
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
2016-05-10 20:47:37 +00:00
|
|
|
isAtEnd: function () {
|
2017-03-27 19:04:31 +00:00
|
|
|
return this.getNewestVisibleRevisionIndex() === this.revisions.getLength() - 1 || this.revisions.getLength() <= this.revisionsPerWindow;
|
2016-05-10 20:47:37 +00:00
|
|
|
},
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* Sets the index of the first revision that is visible in the current window
|
|
|
|
*
|
|
|
|
* @param {number} value
|
|
|
|
*/
|
2016-05-11 10:01:44 +00:00
|
|
|
setFirstVisibleRevisionIndex: function ( value ) {
|
2017-03-27 19:04:31 +00:00
|
|
|
this.oldestVisibleRevisionIndex = value;
|
2016-05-11 10:01:44 +00:00
|
|
|
},
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
2017-03-27 19:04:31 +00:00
|
|
|
* Sets the new oldestVisibleRevisionIndex after sliding in a direction
|
2016-06-17 13:06:12 +00:00
|
|
|
*
|
2017-07-12 15:03:25 +00:00
|
|
|
* @param {number} direction - Either -1, 0 or 1
|
2016-06-17 13:06:12 +00:00
|
|
|
*/
|
2016-05-10 12:42:05 +00:00
|
|
|
slide: function ( direction ) {
|
2016-05-20 14:42:14 +00:00
|
|
|
var highestPossibleFirstRev = this.revisions.getLength() - this.revisionsPerWindow;
|
2016-05-10 12:42:05 +00:00
|
|
|
|
2017-03-27 19:04:31 +00:00
|
|
|
this.oldestVisibleRevisionIndex += direction * this.revisionsPerWindow;
|
|
|
|
this.oldestVisibleRevisionIndex = Math.min( this.oldestVisibleRevisionIndex, highestPossibleFirstRev );
|
|
|
|
this.oldestVisibleRevisionIndex = Math.max( 0, this.oldestVisibleRevisionIndex );
|
2016-05-10 12:42:05 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
mw.libs.revisionSlider = mw.libs.revisionSlider || {};
|
|
|
|
mw.libs.revisionSlider.Slider = Slider;
|
2018-11-16 16:33:52 +00:00
|
|
|
}() );
|