mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/RevisionSlider
synced 2024-11-15 11:40:43 +00:00
90ef5dbb23
Bug: T135739 Change-Id: I00e30a585b3a38da7e405f200356163b20358df9
70 lines
1.7 KiB
JavaScript
70 lines
1.7 KiB
JavaScript
( function ( mw, $ ) {
|
|
var Slider = function ( revisions ) {
|
|
this.revisions = revisions;
|
|
this.view = new mw.libs.revisionSlider.SliderView( this );
|
|
};
|
|
|
|
$.extend( Slider.prototype, {
|
|
/**
|
|
* @type {RevisionList}
|
|
*/
|
|
revisions: null,
|
|
|
|
firstVisibleRevisionIndex: 0,
|
|
|
|
revisionsPerWindow: 0,
|
|
|
|
/**
|
|
* @type {SliderView}
|
|
*/
|
|
view: null,
|
|
|
|
getRevisions: function () {
|
|
return this.revisions;
|
|
},
|
|
|
|
getView: function () {
|
|
return this.view;
|
|
},
|
|
|
|
setRevisionsPerWindow: function ( n ) {
|
|
this.revisionsPerWindow = n;
|
|
},
|
|
|
|
getRevisionsPerWindow: function () {
|
|
return this.revisionsPerWindow;
|
|
},
|
|
|
|
getFirstVisibleRevisionIndex: function () {
|
|
return this.firstVisibleRevisionIndex;
|
|
},
|
|
|
|
getLastVisibleRevisionIndex: function () {
|
|
return this.firstVisibleRevisionIndex + this.revisionsPerWindow - 1;
|
|
},
|
|
|
|
isAtStart: function () {
|
|
return this.getFirstVisibleRevisionIndex() === 0 || this.revisions.getLength() <= this.revisionsPerWindow;
|
|
},
|
|
|
|
isAtEnd: function () {
|
|
return this.getLastVisibleRevisionIndex() === this.revisions.getLength() - 1 || this.revisions.getLength() <= this.revisionsPerWindow;
|
|
},
|
|
|
|
setFirstVisibleRevisionIndex: function ( value ) {
|
|
this.firstVisibleRevisionIndex = value;
|
|
},
|
|
|
|
slide: function ( direction ) {
|
|
var highestPossibleFirstRev = this.revisions.getLength() - this.revisionsPerWindow;
|
|
|
|
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 ) );
|