mediawiki-extensions-Revisi.../modules/ext.RevisionSlider.Slider.js
Jakob Warkotsch 90ef5dbb23 Fix bug that caused the most recent revision to never be visible.
Bug: T135739
Change-Id: I00e30a585b3a38da7e405f200356163b20358df9
2016-05-26 10:56:25 +02:00

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 ) );