2016-05-10 12:42:05 +00:00
|
|
|
( function ( mw, $ ) {
|
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;
|
|
|
|
this.view = new mw.libs.revisionSlider.SliderView( this );
|
|
|
|
};
|
|
|
|
|
|
|
|
$.extend( Slider.prototype, {
|
|
|
|
/**
|
|
|
|
* @type {RevisionList}
|
|
|
|
*/
|
|
|
|
revisions: null,
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* @type {number}
|
|
|
|
*/
|
2016-05-10 12:42:05 +00:00
|
|
|
firstVisibleRevisionIndex: 0,
|
|
|
|
|
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}
|
|
|
|
*/
|
2016-05-10 12:42:05 +00:00
|
|
|
getRevisions: function () {
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Returns the index of the first revision that is visible in the current window
|
|
|
|
*
|
|
|
|
* @return {number}
|
|
|
|
*/
|
2016-05-10 12:42:05 +00:00
|
|
|
getFirstVisibleRevisionIndex: function () {
|
|
|
|
return this.firstVisibleRevisionIndex;
|
|
|
|
},
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* Returns the index of the last revision that is visible in the current window
|
|
|
|
*
|
|
|
|
* @return {number}
|
|
|
|
*/
|
2016-05-10 20:47:37 +00:00
|
|
|
getLastVisibleRevisionIndex: function () {
|
|
|
|
return this.firstVisibleRevisionIndex + this.revisionsPerWindow - 1;
|
|
|
|
},
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
2016-05-10 20:47:37 +00:00
|
|
|
isAtStart: function () {
|
|
|
|
return this.getFirstVisibleRevisionIndex() === 0 || this.revisions.getLength() <= this.revisionsPerWindow;
|
|
|
|
},
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
2016-05-10 20:47:37 +00:00
|
|
|
isAtEnd: function () {
|
2016-05-20 14:42:14 +00:00
|
|
|
return this.getLastVisibleRevisionIndex() === 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 ) {
|
|
|
|
this.firstVisibleRevisionIndex = value;
|
|
|
|
},
|
|
|
|
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
|
|
|
* Sets the new firstVisibleRevisionIndex after sliding in a direction
|
|
|
|
*
|
|
|
|
* @param {number} direction - Either -1 or 1
|
|
|
|
*/
|
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
|
|
|
|
|
|
|
this.firstVisibleRevisionIndex += direction * this.revisionsPerWindow;
|
|
|
|
this.firstVisibleRevisionIndex = Math.min( this.firstVisibleRevisionIndex, highestPossibleFirstRev );
|
|
|
|
this.firstVisibleRevisionIndex = Math.max( 0, this.firstVisibleRevisionIndex );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
mw.libs.revisionSlider = mw.libs.revisionSlider || {};
|
|
|
|
mw.libs.revisionSlider.Slider = Slider;
|
|
|
|
}( mediaWiki, jQuery ) );
|