mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/RevisionSlider
synced 2024-11-15 11:40:43 +00:00
b1f6a1df56
This allows using browser back and forward buttons once users have started heading between revisions. This also updates the URL so that the page can be reloaded at any time and the same state will be held. (This also removes a commented out block of code that I think was left for updating the URL) Change-Id: I4cfe38f76eeb9e090f0a8a42e22e75cf84014d60
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() - 2 || this.revisions.getLength() <= this.revisionsPerWindow;
|
|
},
|
|
|
|
setFirstVisibleRevisionIndex: function ( value ) {
|
|
this.firstVisibleRevisionIndex = value;
|
|
},
|
|
|
|
slide: function ( direction ) {
|
|
var highestPossibleFirstRev = this.revisions.getLength() - 1 - 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 ) );
|