mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/RevisionSlider
synced 2024-11-15 11:40:43 +00:00
ec80c4fa6f
As the pointers can switch side the idea of having a left and right one will just lead to confusion, so lets kill that idea now! :D Change-Id: I9d56314ea4cf46402df56e0a038bfb9655218960
83 lines
1.9 KiB
JavaScript
83 lines
1.9 KiB
JavaScript
( function ( mw, $ ) {
|
|
var PointerView = function ( pointer, id, offset ) {
|
|
this.pointer = pointer;
|
|
this.id = id;
|
|
this.offset = offset;
|
|
};
|
|
|
|
$.extend( PointerView.prototype, {
|
|
/**
|
|
* @type {string}
|
|
*/
|
|
id: '',
|
|
|
|
/**
|
|
* @type {int}
|
|
*/
|
|
offset: 0,
|
|
|
|
/**
|
|
* @type {Pointer}
|
|
*/
|
|
|
|
/**
|
|
* @type {jQuery}
|
|
*/
|
|
$html: null,
|
|
|
|
initialize: function () {
|
|
this.$html = $( '<div id="' + this.id + '" class="pointer" />' );
|
|
},
|
|
|
|
/**
|
|
* @return {jQuery}
|
|
*/
|
|
render: function () {
|
|
this.initialize();
|
|
return this.getElement();
|
|
},
|
|
|
|
/**
|
|
* @return {jQuery}
|
|
*/
|
|
getElement: function () {
|
|
return this.$html;
|
|
},
|
|
|
|
getOffset: function () {
|
|
return this.offset;
|
|
},
|
|
|
|
animateTo: function ( posInPx, duration ) {
|
|
this.getElement().animate( { left: posInPx }, duration );
|
|
},
|
|
|
|
slideToPosition: function ( slider, duration ) {
|
|
var relativePos = this.pointer.getPosition() - slider.getFirstVisibleRevisionIndex();
|
|
this.animateTo( relativePos * slider.getView().revisionWidth, duration );
|
|
},
|
|
|
|
slideToSide: function ( slider, posBeforeSlider, duration ) {
|
|
if ( posBeforeSlider ) {
|
|
this.animateTo( this.offset - slider.getView().revisionWidth, duration );
|
|
} else {
|
|
this.animateTo( ( slider.getRevisionsPerWindow() + 1 ) * slider.getView().revisionWidth - this.offset, duration );
|
|
}
|
|
},
|
|
|
|
slideToSideOrPosition: function ( slider, duration ) {
|
|
var firstVisibleRev = slider.getFirstVisibleRevisionIndex(),
|
|
posBeforeSlider = this.pointer.getPosition() < firstVisibleRev,
|
|
isVisible = !posBeforeSlider && this.pointer.getPosition() <= firstVisibleRev + slider.getRevisionsPerWindow();
|
|
if ( isVisible ) {
|
|
this.slideToPosition( slider, duration );
|
|
} else {
|
|
this.slideToSide( slider, posBeforeSlider, duration );
|
|
}
|
|
}
|
|
} );
|
|
|
|
mw.libs.revisionSlider = mw.libs.revisionSlider || {};
|
|
mw.libs.revisionSlider.PointerView = PointerView;
|
|
}( mediaWiki, jQuery ) );
|