2023-06-22 09:41:37 +00:00
|
|
|
const SliderView = require( './ext.RevisionSlider.SliderView.js' );
|
2020-03-29 20:36:10 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
/**
|
|
|
|
* Module handling the slider logic of the RevisionSlider
|
|
|
|
*
|
|
|
|
* @class Slider
|
|
|
|
* @param {RevisionList} revisions
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
function Slider( revisions ) {
|
|
|
|
this.revisions = revisions;
|
2020-03-29 20:36:10 +00:00
|
|
|
this.view = new SliderView( this );
|
2020-11-18 09:11:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$.extend( Slider.prototype, {
|
2016-06-17 13:06:12 +00:00
|
|
|
/**
|
2020-11-18 09:11:12 +00:00
|
|
|
* @type {RevisionList}
|
|
|
|
*/
|
|
|
|
revisions: null,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
oldestVisibleRevisionIndex: 0,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
revisionsPerWindow: 0,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {SliderView}
|
|
|
|
*/
|
|
|
|
view: null,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {RevisionList}
|
|
|
|
*/
|
|
|
|
getRevisionList: function () {
|
|
|
|
return this.revisions;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {SliderView}
|
|
|
|
*/
|
|
|
|
getView: function () {
|
|
|
|
return this.view;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the number of revisions that are visible at once (depending on browser window size)
|
2016-06-17 13:06:12 +00:00
|
|
|
*
|
2020-11-18 09:11:12 +00:00
|
|
|
* @param {number} n
|
2016-06-17 13:06:12 +00:00
|
|
|
*/
|
2020-11-18 09:11:12 +00:00
|
|
|
setRevisionsPerWindow: function ( n ) {
|
|
|
|
this.revisionsPerWindow = n;
|
|
|
|
},
|
2016-05-10 12:42:05 +00:00
|
|
|
|
2020-01-24 16:21:23 +00:00
|
|
|
/**
|
2020-11-18 09:11:12 +00:00
|
|
|
* @return {number}
|
2020-01-24 16:21:23 +00:00
|
|
|
*/
|
2020-11-18 09:11:12 +00:00
|
|
|
getRevisionsPerWindow: function () {
|
|
|
|
return this.revisionsPerWindow;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the index of the oldest revision that is visible in the current window
|
|
|
|
*
|
|
|
|
* @return {number}
|
|
|
|
*/
|
|
|
|
getOldestVisibleRevisionIndex: function () {
|
|
|
|
return this.oldestVisibleRevisionIndex;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the index of the newest revision that is visible in the current window
|
|
|
|
*
|
|
|
|
* @return {number}
|
|
|
|
*/
|
|
|
|
getNewestVisibleRevisionIndex: function () {
|
|
|
|
return this.oldestVisibleRevisionIndex + this.revisionsPerWindow - 1;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
isAtStart: function () {
|
|
|
|
return this.getOldestVisibleRevisionIndex() === 0 || this.revisions.getLength() <= this.revisionsPerWindow;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
isAtEnd: function () {
|
|
|
|
return this.getNewestVisibleRevisionIndex() === this.revisions.getLength() - 1 || this.revisions.getLength() <= this.revisionsPerWindow;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the index of the first revision that is visible in the current window
|
|
|
|
*
|
|
|
|
* @param {number} value
|
|
|
|
*/
|
|
|
|
setFirstVisibleRevisionIndex: function ( value ) {
|
2023-10-25 12:52:56 +00:00
|
|
|
const highestPossibleFirstRev = this.revisions.getLength() - this.revisionsPerWindow;
|
|
|
|
value = Math.min( Math.max( 0, value ), highestPossibleFirstRev );
|
2020-11-18 09:11:12 +00:00
|
|
|
this.oldestVisibleRevisionIndex = value;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the new oldestVisibleRevisionIndex after sliding in a direction
|
|
|
|
*
|
|
|
|
* @param {number} direction - Either -1, 0 or 1
|
|
|
|
*/
|
|
|
|
slide: function ( direction ) {
|
2023-10-25 12:52:56 +00:00
|
|
|
const value = this.oldestVisibleRevisionIndex + direction * this.revisionsPerWindow;
|
|
|
|
this.setFirstVisibleRevisionIndex( value );
|
2020-11-18 09:11:12 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2020-03-29 20:36:10 +00:00
|
|
|
module.exports = {
|
|
|
|
Api: require( './ext.RevisionSlider.Api.js' ),
|
|
|
|
DiffPage: require( './ext.RevisionSlider.DiffPage.js' ),
|
2020-11-20 09:27:07 +00:00
|
|
|
HelpDialog: require( './ext.RevisionSlider.HelpDialog.js' ),
|
2020-11-20 10:31:12 +00:00
|
|
|
makeRevisions: require( './ext.RevisionSlider.RevisionList.js' ).makeRevisions,
|
|
|
|
Revision: require( './ext.RevisionSlider.Revision.js' ).Revision,
|
|
|
|
RevisionList: require( './ext.RevisionSlider.RevisionList.js' ).RevisionList,
|
|
|
|
RevisionListView: require( './ext.RevisionSlider.RevisionListView.js' ),
|
|
|
|
setUserOffset: require( './ext.RevisionSlider.Revision.js' ).setUserOffset,
|
2020-03-29 20:36:10 +00:00
|
|
|
Slider: Slider,
|
|
|
|
SliderView: SliderView,
|
2020-11-20 07:46:57 +00:00
|
|
|
utils: require( './ext.RevisionSlider.util.js' ),
|
|
|
|
|
|
|
|
private: {
|
|
|
|
Pointer: require( './ext.RevisionSlider.Pointer.js' ),
|
|
|
|
PointerView: require( './ext.RevisionSlider.PointerView.js' )
|
|
|
|
}
|
2020-03-29 20:36:10 +00:00
|
|
|
};
|