2023-06-22 09:41:37 +00:00
|
|
|
const DiffPage = require( './ext.RevisionSlider.DiffPage.js' ),
|
2020-11-20 09:27:07 +00:00
|
|
|
HelpButtonView = require( './ext.RevisionSlider.HelpButtonView.js' ),
|
2020-11-20 10:31:12 +00:00
|
|
|
makeRevisions = require( './ext.RevisionSlider.RevisionList.js' ).makeRevisions,
|
2020-11-20 07:46:57 +00:00
|
|
|
Pointer = require( './ext.RevisionSlider.Pointer.js' ),
|
2020-11-20 10:31:12 +00:00
|
|
|
RevisionListView = require( './ext.RevisionSlider.RevisionListView.js' ),
|
2020-03-29 20:36:10 +00:00
|
|
|
RevisionSliderApi = require( './ext.RevisionSlider.Api.js' ),
|
|
|
|
SliderArrowView = require( './ext.RevisionSlider.SliderArrowView.js' ),
|
|
|
|
utils = require( './ext.RevisionSlider.util.js' );
|
2020-11-18 09:11:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Module handling the view logic of the RevisionSlider slider
|
|
|
|
*
|
|
|
|
* @class SliderView
|
|
|
|
* @param {Slider} slider
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
function SliderView( slider ) {
|
|
|
|
this.slider = slider;
|
2020-03-29 20:36:10 +00:00
|
|
|
this.diffPage = new DiffPage( this.slider.getRevisionList() );
|
2020-11-18 09:11:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$.extend( SliderView.prototype, {
|
|
|
|
|
2022-11-22 13:30:14 +00:00
|
|
|
revisionWidth: 16,
|
2020-11-18 09:11:12 +00:00
|
|
|
containerMargin: 140,
|
|
|
|
outerMargin: 20,
|
|
|
|
|
2022-11-22 13:30:14 +00:00
|
|
|
/** @type {jQuery} */
|
2020-11-18 09:11:12 +00:00
|
|
|
$element: null,
|
2022-11-22 13:30:14 +00:00
|
|
|
/** @type {DiffPage} */
|
2020-11-18 09:11:12 +00:00
|
|
|
diffPage: null,
|
2022-11-22 13:30:14 +00:00
|
|
|
/** @type {Slider} */
|
2020-11-18 09:11:12 +00:00
|
|
|
slider: null,
|
2022-11-22 13:30:14 +00:00
|
|
|
/** @type {Pointer} */
|
2020-11-18 09:11:12 +00:00
|
|
|
pointerOlder: null,
|
2022-11-22 13:30:14 +00:00
|
|
|
/** @type {Pointer} */
|
2020-11-18 09:11:12 +00:00
|
|
|
pointerNewer: null,
|
2022-11-22 13:30:14 +00:00
|
|
|
/** @type {OO.ui.ButtonWidget} */
|
2020-11-18 09:11:12 +00:00
|
|
|
backwardArrowButton: null,
|
2022-11-22 13:30:14 +00:00
|
|
|
/** @type {OO.ui.ButtonWidget} */
|
2020-11-18 09:11:12 +00:00
|
|
|
forwardArrowButton: null,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {string}
|
2016-06-17 13:06:12 +00:00
|
|
|
*
|
2020-11-18 09:11:12 +00:00
|
|
|
* Value of scrollLeft property when in RTL mode varies between browser. This identifies
|
|
|
|
* an implementation used by user's browser:
|
|
|
|
* - 'default': 0 is the left-most position, values increase when scrolling right (same as scrolling from left to right in LTR mode)
|
|
|
|
* - 'negative': 0 is right-most position, values decrease when scrolling left (ie. all values except 0 are negative)
|
|
|
|
* - 'reverse': 0 is right-most position, values incrase when scrolling left
|
2016-06-17 13:06:12 +00:00
|
|
|
*/
|
2020-11-18 09:11:12 +00:00
|
|
|
rtlScrollLeftType: 'default',
|
2016-05-10 12:42:05 +00:00
|
|
|
|
2022-11-22 13:30:14 +00:00
|
|
|
/** @type {boolean} */
|
2020-11-18 09:11:12 +00:00
|
|
|
noMoreNewerRevisions: false,
|
2022-11-22 13:30:14 +00:00
|
|
|
/** @type {boolean} */
|
2020-11-18 09:11:12 +00:00
|
|
|
noMoreOlderRevisions: false,
|
2022-11-22 13:30:14 +00:00
|
|
|
/** @type {string|null} */
|
2020-11-18 09:11:12 +00:00
|
|
|
dir: null,
|
2022-11-22 13:30:14 +00:00
|
|
|
/** @type {boolean} */
|
2020-11-18 09:11:12 +00:00
|
|
|
isDragged: false,
|
2022-11-22 13:30:14 +00:00
|
|
|
/** @type {boolean} */
|
2020-11-18 09:11:12 +00:00
|
|
|
escapePressed: false,
|
2022-11-22 13:30:14 +00:00
|
|
|
/** @type {number|null} */
|
2020-11-18 09:11:12 +00:00
|
|
|
lastOldPointerPosition: null,
|
2022-11-22 13:30:14 +00:00
|
|
|
/** @type {number|null} */
|
2020-11-18 09:11:12 +00:00
|
|
|
lastNewPointerPosition: null,
|
|
|
|
|
|
|
|
render: function ( $container ) {
|
2023-06-22 09:41:37 +00:00
|
|
|
const containerWidth = this.calculateSliderContainerWidth(),
|
2020-11-18 09:11:12 +00:00
|
|
|
$revisions = this.getRevisionListView().render( this.revisionWidth ),
|
2020-03-29 20:36:10 +00:00
|
|
|
sliderArrowView = new SliderArrowView( this );
|
2020-11-18 09:11:12 +00:00
|
|
|
|
|
|
|
this.dir = $container.css( 'direction' ) || 'ltr';
|
|
|
|
|
|
|
|
if ( this.dir === 'rtl' ) {
|
2020-03-29 20:36:10 +00:00
|
|
|
this.rtlScrollLeftType = utils.determineRtlScrollType();
|
2020-11-18 09:11:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.pointerOlder = this.pointerOlder || new Pointer( 'mw-revslider-pointer-older' );
|
|
|
|
this.pointerNewer = this.pointerNewer || new Pointer( 'mw-revslider-pointer-newer' );
|
|
|
|
|
|
|
|
this.backwardArrowButton = sliderArrowView.renderBackwardArrow();
|
|
|
|
this.forwardArrowButton = sliderArrowView.renderForwardArrow();
|
|
|
|
|
|
|
|
this.$element = $( '<div>' )
|
|
|
|
.addClass( 'mw-revslider-revision-slider' )
|
|
|
|
.css( {
|
|
|
|
direction: $container.css( 'direction' ),
|
|
|
|
width: ( containerWidth + this.containerMargin ) + 'px'
|
|
|
|
} )
|
|
|
|
.append(
|
|
|
|
this.backwardArrowButton.$element,
|
|
|
|
this.renderRevisionsContainer( containerWidth, $revisions ),
|
|
|
|
this.renderPointerContainer( containerWidth ),
|
|
|
|
this.forwardArrowButton.$element,
|
|
|
|
$( '<div>' ).css( { clear: 'both' } ),
|
|
|
|
this.pointerOlder.getLine().render(), this.pointerNewer.getLine().render(),
|
|
|
|
HelpButtonView.render()
|
|
|
|
);
|
|
|
|
|
|
|
|
this.initPointers( $revisions );
|
|
|
|
|
|
|
|
this.slider.setRevisionsPerWindow( this.$element.find( '.mw-revslider-revisions-container' ).width() / this.revisionWidth );
|
|
|
|
|
|
|
|
this.initializePointers( this.getOldRevElement( $revisions ), this.getNewRevElement( $revisions ) );
|
|
|
|
this.resetRevisionStylesBasedOnPointerPosition( $revisions );
|
|
|
|
this.addClickHandlerToRevisions( $revisions );
|
|
|
|
|
2023-04-22 19:04:58 +00:00
|
|
|
$container.empty().append( this.$element );
|
2020-11-18 09:11:12 +00:00
|
|
|
|
|
|
|
this.slideView( Math.floor( ( this.getNewerPointerPos() - 1 ) / this.slider.getRevisionsPerWindow() ), 0 );
|
|
|
|
this.diffPage.addHandlersToCoreLinks( this );
|
|
|
|
this.diffPage.replaceState( mw.config.get( 'wgDiffNewId' ), mw.config.get( 'wgDiffOldId' ), this );
|
|
|
|
this.diffPage.initOnPopState( this );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the revisions container and adds the revisions to it
|
|
|
|
*
|
|
|
|
* @param {number} containerWidth
|
|
|
|
* @param {jQuery} $revisions
|
|
|
|
* @return {jQuery} the revisions container
|
|
|
|
*/
|
|
|
|
renderRevisionsContainer: function ( containerWidth, $revisions ) {
|
|
|
|
return $( '<div>' )
|
|
|
|
.addClass( 'mw-revslider-revisions-container' )
|
|
|
|
.css( {
|
|
|
|
width: containerWidth + 'px'
|
|
|
|
} )
|
|
|
|
.append( $revisions );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the pointer container and adds the pointers to it
|
|
|
|
*
|
|
|
|
* @param {number} containerWidth
|
|
|
|
* @return {jQuery} the pointer container
|
|
|
|
*/
|
|
|
|
renderPointerContainer: function ( containerWidth ) {
|
2023-06-22 09:41:37 +00:00
|
|
|
const self = this;
|
|
|
|
const pointerContainerWidth = containerWidth + this.revisionWidth - 1;
|
|
|
|
let pointerContainerPosition = 53,
|
|
|
|
pointerContainerStyle, lastMouseMoveRevisionPos;
|
2020-11-18 09:11:12 +00:00
|
|
|
|
|
|
|
pointerContainerStyle = { left: pointerContainerPosition + 'px', width: pointerContainerWidth + 'px' };
|
|
|
|
if ( this.dir === 'rtl' ) {
|
|
|
|
// Due to properly limit dragging a pointer on the right side of the screen,
|
|
|
|
// there must some extra space added to the right of the revision bar container
|
|
|
|
// For this reason right position of the pointer container in the RTL mode is
|
|
|
|
// a bit moved off right compared to its left position in the LTR mode
|
|
|
|
pointerContainerPosition = pointerContainerPosition - this.revisionWidth + 1;
|
|
|
|
pointerContainerStyle = { right: pointerContainerPosition + 'px', width: pointerContainerWidth + 'px' };
|
|
|
|
}
|
|
|
|
|
|
|
|
return $( '<div>' )
|
|
|
|
.addClass( 'mw-revslider-pointer-container' )
|
|
|
|
.css( pointerContainerStyle )
|
|
|
|
.append( this.renderPointerContainers() )
|
|
|
|
.on( 'click', function ( event ) {
|
|
|
|
self.pointerContainerClickHandler( event );
|
|
|
|
} )
|
|
|
|
.on( 'mouseout', function () {
|
|
|
|
if ( !self.isDragged ) {
|
|
|
|
self.getRevisionListView().unsetAllHovered();
|
|
|
|
}
|
|
|
|
} )
|
|
|
|
.on( 'mouseover', function ( event ) {
|
|
|
|
if ( !self.isDragged ) {
|
|
|
|
lastMouseMoveRevisionPos = self.showTooltipsOnMouseMoveHandler(
|
|
|
|
event,
|
|
|
|
null
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} )
|
|
|
|
.on( 'mousemove', function ( event ) {
|
|
|
|
if ( !self.isDragged ) {
|
|
|
|
lastMouseMoveRevisionPos = self.showTooltipsOnMouseMoveHandler(
|
|
|
|
event,
|
|
|
|
lastMouseMoveRevisionPos
|
|
|
|
);
|
2016-12-07 20:56:36 +00:00
|
|
|
}
|
|
|
|
} );
|
2020-11-18 09:11:12 +00:00
|
|
|
},
|
2016-12-07 20:56:36 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
renderPointerContainers: function () {
|
|
|
|
return [
|
|
|
|
$( '<div>' )
|
|
|
|
.addClass( 'mw-revslider-pointer-container-older' )
|
|
|
|
.append(
|
|
|
|
$( '<div>' ).addClass( 'mw-revslider-slider-line' ),
|
|
|
|
this.pointerOlder.getView().render()
|
|
|
|
),
|
|
|
|
$( '<div>' )
|
|
|
|
.addClass( 'mw-revslider-pointer-container-newer' )
|
|
|
|
.append(
|
|
|
|
$( '<div>' ).addClass( 'mw-revslider-slider-line' ),
|
|
|
|
this.pointerNewer.getView().render()
|
|
|
|
)
|
|
|
|
];
|
|
|
|
},
|
2018-09-11 06:10:47 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
/**
|
|
|
|
* Initializes the pointer dragging logic
|
|
|
|
*
|
|
|
|
* @param {jQuery} $revisions
|
|
|
|
*/
|
|
|
|
initPointers: function ( $revisions ) {
|
2023-06-22 09:41:37 +00:00
|
|
|
const $pointers = this.$element.find( '.mw-revslider-pointer' ),
|
2020-11-18 09:11:12 +00:00
|
|
|
$pointerOlder = this.pointerOlder.getView().getElement(),
|
|
|
|
$pointerNewer = this.pointerNewer.getView().getElement(),
|
|
|
|
self = this;
|
|
|
|
|
|
|
|
$pointerNewer.attr( 'tabindex', 0 );
|
|
|
|
$pointerOlder.attr( 'tabindex', 0 );
|
|
|
|
|
2023-04-21 07:03:07 +00:00
|
|
|
$( document.body ).on( 'keydown', function ( e ) {
|
2023-08-24 08:28:52 +00:00
|
|
|
if ( e.which === OO.ui.Keys.ESCAPE ) {
|
2020-11-18 09:11:12 +00:00
|
|
|
self.escapePressed = true;
|
|
|
|
$pointers.trigger( 'mouseup' );
|
|
|
|
}
|
|
|
|
} );
|
2018-09-11 06:10:47 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
$pointerOlder.on( 'keydown', function ( event ) {
|
|
|
|
self.buildTabbingRulesOnKeyDown(
|
|
|
|
$pointerOlder,
|
|
|
|
event,
|
|
|
|
$revisions
|
|
|
|
);
|
|
|
|
} );
|
2018-09-11 06:10:47 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
$pointerOlder.on( 'keyup', function ( event ) {
|
|
|
|
self.buildTabbingRulesOnKeyUp(
|
|
|
|
$pointerOlder,
|
|
|
|
event,
|
|
|
|
$revisions
|
|
|
|
);
|
|
|
|
} );
|
2018-09-11 06:10:47 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
$pointerNewer.on( 'keydown', function ( event ) {
|
|
|
|
self.buildTabbingRulesOnKeyDown(
|
|
|
|
$pointerNewer,
|
|
|
|
event,
|
|
|
|
$revisions
|
2017-07-11 08:17:24 +00:00
|
|
|
);
|
2020-11-18 09:11:12 +00:00
|
|
|
} );
|
2017-07-11 08:17:24 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
$pointerNewer.on( 'keyup', function ( event ) {
|
|
|
|
self.buildTabbingRulesOnKeyUp(
|
|
|
|
$pointerNewer,
|
|
|
|
event,
|
|
|
|
$revisions
|
|
|
|
);
|
|
|
|
} );
|
2017-07-11 08:17:24 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
$pointers.on(
|
|
|
|
'touchstart touchmove touchend touchcancel touchleave',
|
2020-03-29 20:36:10 +00:00
|
|
|
utils.touchEventConverter
|
2020-11-18 09:11:12 +00:00
|
|
|
);
|
2017-06-29 14:35:54 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
$pointerOlder.draggable( this.buildDraggableOptions(
|
|
|
|
$revisions,
|
|
|
|
'.mw-revslider-pointer-container-older'
|
|
|
|
) );
|
2017-07-10 22:39:38 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
$pointerNewer.draggable( this.buildDraggableOptions(
|
|
|
|
$revisions,
|
|
|
|
'.mw-revslider-pointer-container-newer'
|
|
|
|
) );
|
|
|
|
},
|
2017-07-10 22:39:38 +00:00
|
|
|
|
2023-03-22 21:05:10 +00:00
|
|
|
/** @return {number} */
|
2020-11-18 09:11:12 +00:00
|
|
|
getOlderPointerPos: function () {
|
|
|
|
return this.pointerOlder.getPosition();
|
|
|
|
},
|
2017-07-10 22:39:38 +00:00
|
|
|
|
2023-03-22 21:05:10 +00:00
|
|
|
/** @return {number} */
|
2020-11-18 09:11:12 +00:00
|
|
|
getNewerPointerPos: function () {
|
|
|
|
return this.pointerNewer.getPosition();
|
|
|
|
},
|
2017-07-10 22:39:38 +00:00
|
|
|
|
2023-03-22 21:05:10 +00:00
|
|
|
/**
|
|
|
|
* @param {number} pos
|
|
|
|
* @return {number}
|
|
|
|
*/
|
2020-11-18 09:11:12 +00:00
|
|
|
setOlderPointerPos: function ( pos ) {
|
|
|
|
return this.pointerOlder.setPosition( pos );
|
|
|
|
},
|
2017-06-29 14:35:54 +00:00
|
|
|
|
2023-03-22 21:05:10 +00:00
|
|
|
/**
|
|
|
|
* @param {number} pos
|
|
|
|
* @return {number}
|
|
|
|
*/
|
2020-11-18 09:11:12 +00:00
|
|
|
setNewerPointerPos: function ( pos ) {
|
|
|
|
return this.pointerNewer.setPosition( pos );
|
|
|
|
},
|
2017-06-29 14:35:54 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
showTooltipsOnMouseMoveHandler: function ( event, lastValidPosition ) {
|
2023-06-22 09:41:37 +00:00
|
|
|
const pos = this.getRevisionPositionFromLeftOffset( event.pageX );
|
2017-06-29 14:35:54 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
if ( pos === lastValidPosition ) {
|
2017-06-29 14:35:54 +00:00
|
|
|
return pos;
|
2020-11-18 09:11:12 +00:00
|
|
|
}
|
|
|
|
|
2023-06-22 09:41:37 +00:00
|
|
|
const $hoveredRevisionWrapper = this.getRevElementAtPosition( this.getRevisionsElement(), pos ).parent();
|
|
|
|
const $lastRevisionWrapper = this.getRevElementAtPosition( this.getRevisionsElement(), lastValidPosition ).parent();
|
2020-11-18 09:11:12 +00:00
|
|
|
this.getRevisionListView().unsetRevisionGhosts( $lastRevisionWrapper );
|
2023-08-25 10:36:26 +00:00
|
|
|
this.getRevisionListView().setRevisionHoveredFromMouseEvent( $hoveredRevisionWrapper, event );
|
2020-11-18 09:11:12 +00:00
|
|
|
|
|
|
|
return pos;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for click events on the pointer container element. Forwards these events to the generic handler for
|
|
|
|
* revision clicks.
|
|
|
|
*
|
|
|
|
* @param {MouseEvent} event
|
|
|
|
*/
|
|
|
|
pointerContainerClickHandler: function ( event ) {
|
2023-06-22 09:41:37 +00:00
|
|
|
const clickedPos = this.getRevisionPositionFromLeftOffset( event.pageX ),
|
2020-11-18 09:11:12 +00:00
|
|
|
$revisionWrapper = this.getRevElementAtPosition( this.getRevisionsElement(), clickedPos ).parent(),
|
|
|
|
hasClickedTop = event.pageY - $revisionWrapper.offset().top < $revisionWrapper.height() / 2;
|
|
|
|
|
|
|
|
this.handleRevisionClick( $revisionWrapper, clickedPos, hasClickedTop );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for click events on a revisionWrapper element. Forwards these events to the generic handler for
|
|
|
|
* revision clicks.
|
|
|
|
*
|
|
|
|
* @param {MouseEvent} event
|
|
|
|
* @param {jQuery} $revisionWrapper
|
|
|
|
*/
|
|
|
|
revisionWrapperClickHandler: function ( event, $revisionWrapper ) {
|
2023-06-22 09:41:37 +00:00
|
|
|
const hasClickedTop = event.pageY - $revisionWrapper.offset().top < $revisionWrapper.height() / 2,
|
2020-11-18 09:11:12 +00:00
|
|
|
clickedPos = +$revisionWrapper.find( '.mw-revslider-revision' ).attr( 'data-pos' );
|
|
|
|
|
|
|
|
this.handleRevisionClick( $revisionWrapper, clickedPos, hasClickedTop );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* React on clicks on a revision element and move pointers
|
|
|
|
*
|
|
|
|
* @param {jQuery} $revisionWrapper
|
|
|
|
* @param {number} clickedPos
|
|
|
|
* @param {boolean} hasClickedTop
|
|
|
|
*/
|
|
|
|
handleRevisionClick: function ( $revisionWrapper, clickedPos, hasClickedTop ) {
|
2023-06-22 09:41:37 +00:00
|
|
|
let newNewerPointerPos, newOlderPointerPos;
|
2020-11-18 09:11:12 +00:00
|
|
|
|
|
|
|
if ( hasClickedTop &&
|
|
|
|
( $revisionWrapper.hasClass( 'mw-revslider-revision-newer' ) ||
|
|
|
|
$revisionWrapper.hasClass( 'mw-revslider-revision-intermediate' ) )
|
|
|
|
) {
|
|
|
|
newNewerPointerPos = clickedPos;
|
|
|
|
newOlderPointerPos = this.pointerOlder.getPosition();
|
|
|
|
} else if ( !hasClickedTop &&
|
|
|
|
( $revisionWrapper.hasClass( 'mw-revslider-revision-older' ) ||
|
|
|
|
$revisionWrapper.hasClass( 'mw-revslider-revision-intermediate' ) )
|
|
|
|
) {
|
|
|
|
newNewerPointerPos = this.pointerNewer.getPosition();
|
|
|
|
newOlderPointerPos = clickedPos;
|
|
|
|
} else {
|
|
|
|
if ( hasClickedTop ) {
|
2017-08-17 14:08:49 +00:00
|
|
|
newNewerPointerPos = clickedPos;
|
2020-11-18 09:11:12 +00:00
|
|
|
newOlderPointerPos = clickedPos - 1;
|
2017-06-29 14:35:54 +00:00
|
|
|
} else {
|
2020-11-18 09:11:12 +00:00
|
|
|
newNewerPointerPos = clickedPos + 1;
|
|
|
|
newOlderPointerPos = clickedPos;
|
2017-06-29 14:35:54 +00:00
|
|
|
}
|
2020-11-18 09:11:12 +00:00
|
|
|
}
|
2017-06-29 14:35:54 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
if (
|
|
|
|
newOlderPointerPos === newNewerPointerPos ||
|
|
|
|
!this.slider.getRevisionList().isValidPosition( newOlderPointerPos ) ||
|
|
|
|
!this.slider.getRevisionList().isValidPosition( newNewerPointerPos )
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
2017-06-29 14:35:54 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
this.updatePointersAndDiffView( newNewerPointerPos, newOlderPointerPos, true );
|
|
|
|
},
|
2017-08-17 14:08:49 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
/**
|
|
|
|
* @param {jQuery} $revisions
|
|
|
|
*/
|
|
|
|
addClickHandlerToRevisions: function ( $revisions ) {
|
2023-06-22 09:41:37 +00:00
|
|
|
const self = this;
|
2020-11-18 09:11:12 +00:00
|
|
|
$revisions.find( '.mw-revslider-revision-wrapper' ).on( 'click', function ( event ) {
|
|
|
|
self.revisionWrapperClickHandler( event, $( this ) );
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build rules for tabbing when `keydown` event triggers on pointers
|
|
|
|
*
|
|
|
|
* @param {jQuery} $pointer
|
|
|
|
* @param {KeyboardEvent} event
|
|
|
|
* @param {jQuery} $revisions
|
|
|
|
*/
|
|
|
|
buildTabbingRulesOnKeyDown: function ( $pointer, event, $revisions ) {
|
2023-08-24 08:58:22 +00:00
|
|
|
const oldPos = this.getOlderPointerPos(),
|
|
|
|
newPos = this.getNewerPointerPos(),
|
|
|
|
pointer = this.whichPointer( $pointer ),
|
2021-10-07 13:55:44 +00:00
|
|
|
isNewer = pointer.getView().isNewerPointer();
|
2023-06-22 09:41:37 +00:00
|
|
|
let offset = 0;
|
2020-11-18 09:11:12 +00:00
|
|
|
|
2023-08-24 08:28:52 +00:00
|
|
|
if ( event.which === OO.ui.Keys.RIGHT ) {
|
2020-11-18 09:11:12 +00:00
|
|
|
offset = 1;
|
|
|
|
|
|
|
|
if ( isNewer ) {
|
2023-08-24 08:58:22 +00:00
|
|
|
if ( newPos === this.slider.getNewestVisibleRevisionIndex() + 1 ) {
|
2020-11-18 09:11:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-08-24 08:58:22 +00:00
|
|
|
this.setNewerPointerPos( newPos + 1 );
|
2020-11-18 09:11:12 +00:00
|
|
|
} else {
|
|
|
|
if ( oldPos !== newPos - 1 ) {
|
2023-08-24 08:58:22 +00:00
|
|
|
this.setOlderPointerPos( oldPos + 1 );
|
2018-09-11 06:10:47 +00:00
|
|
|
}
|
|
|
|
}
|
2023-08-24 08:28:52 +00:00
|
|
|
} else if ( event.which === OO.ui.Keys.LEFT ) {
|
2020-11-18 09:11:12 +00:00
|
|
|
offset = -1;
|
2018-09-11 06:10:47 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
if ( isNewer ) {
|
|
|
|
if ( oldPos !== newPos - 1 ) {
|
2023-08-24 08:58:22 +00:00
|
|
|
this.setNewerPointerPos( newPos - 1 );
|
2018-09-11 06:10:47 +00:00
|
|
|
}
|
2020-11-18 09:11:12 +00:00
|
|
|
} else {
|
2023-08-24 08:58:22 +00:00
|
|
|
if ( oldPos === this.slider.getOldestVisibleRevisionIndex() + 1 ) {
|
2020-11-18 09:11:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-08-24 08:58:22 +00:00
|
|
|
this.setOlderPointerPos( oldPos - 1 );
|
2018-09-11 06:10:47 +00:00
|
|
|
}
|
2023-08-24 08:34:36 +00:00
|
|
|
} else if ( event.which !== OO.ui.Keys.ENTER ) {
|
|
|
|
// FIXME: The code below was never designed for the enter key, only for left/right. Add
|
|
|
|
// proper enter key handling that mimics the toggle behavior of PopupButtonWidget.
|
|
|
|
return;
|
2020-11-18 09:11:12 +00:00
|
|
|
}
|
2018-09-11 06:10:47 +00:00
|
|
|
|
2023-08-24 08:58:22 +00:00
|
|
|
this.resetRevisionStylesBasedOnPointerPosition( $revisions );
|
|
|
|
this.alignPointersAndLines( 1 );
|
2018-09-11 06:10:47 +00:00
|
|
|
|
2023-08-24 08:58:22 +00:00
|
|
|
const pos = this.getRevisionPositionFromLeftOffset(
|
|
|
|
$pointer.offset().left + this.revisionWidth / 2
|
2020-11-18 09:11:12 +00:00
|
|
|
) + offset;
|
2018-09-11 06:10:47 +00:00
|
|
|
|
2023-08-24 08:58:22 +00:00
|
|
|
const $hoveredRevisionWrapper = this.getRevElementAtPosition( $revisions, pos ).parent();
|
|
|
|
this.getRevisionListView().showTooltip( $hoveredRevisionWrapper );
|
2020-11-18 09:11:12 +00:00
|
|
|
},
|
2018-09-11 06:10:47 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
/**
|
|
|
|
* Build rules for tabbing when `keyup` event triggers on pointers
|
|
|
|
*
|
|
|
|
* @param {jQuery} $pointer
|
|
|
|
* @param {KeyboardEvent} event
|
|
|
|
* @param {jQuery} $revisions
|
|
|
|
*/
|
|
|
|
buildTabbingRulesOnKeyUp: function ( $pointer, event, $revisions ) {
|
2023-08-24 08:28:52 +00:00
|
|
|
if ( event.which !== OO.ui.Keys.RIGHT && event.which !== OO.ui.Keys.LEFT ) {
|
2020-11-18 09:11:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-03-23 16:42:49 +00:00
|
|
|
|
2023-08-24 08:58:22 +00:00
|
|
|
const diff = this.getRevElementAtPosition(
|
|
|
|
$revisions, this.getNewerPointerPos()
|
2020-11-18 09:11:12 +00:00
|
|
|
).data( 'revid' );
|
2017-07-10 16:50:22 +00:00
|
|
|
|
2023-08-24 08:58:22 +00:00
|
|
|
const oldid = this.getRevElementAtPosition(
|
|
|
|
$revisions, this.getOlderPointerPos()
|
2020-11-18 09:11:12 +00:00
|
|
|
).data( 'revid' );
|
2017-07-10 16:50:22 +00:00
|
|
|
|
2023-08-24 08:58:22 +00:00
|
|
|
this.lastRequest = this.refreshDiffView( diff, oldid, true );
|
2017-07-10 16:50:22 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
this.lastRequest.then( function () {
|
|
|
|
$pointer.trigger( 'focus' );
|
|
|
|
} );
|
|
|
|
},
|
2017-04-06 11:47:59 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
/**
|
|
|
|
* Build options for the draggable
|
|
|
|
*
|
|
|
|
* @param {jQuery} $revisions
|
|
|
|
* @param {string} containmentClass
|
|
|
|
* @return {Object}
|
|
|
|
*/
|
|
|
|
buildDraggableOptions: function ( $revisions, containmentClass ) {
|
2023-06-22 09:41:37 +00:00
|
|
|
let lastValidLeftPos;
|
|
|
|
const self = this;
|
2020-11-18 09:11:12 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
axis: 'x',
|
|
|
|
grid: [ this.revisionWidth, null ],
|
|
|
|
containment: containmentClass,
|
|
|
|
start: function () {
|
|
|
|
if ( self.pointerIsBlockedByOther( this ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
self.isDragged = true;
|
|
|
|
self.getRevisionListView().disableHover();
|
|
|
|
self.setPointerDragCursor();
|
|
|
|
self.fadeOutPointerLines();
|
|
|
|
self.escapePressed = false;
|
|
|
|
self.lastOldPointerPosition = self.getOlderPointerPos();
|
|
|
|
self.lastNewPointerPosition = self.getNewerPointerPos();
|
|
|
|
},
|
|
|
|
stop: function () {
|
2023-06-22 09:41:37 +00:00
|
|
|
const $p = $( this ),
|
2020-11-18 09:11:12 +00:00
|
|
|
relativeIndex = self.getRelativePointerIndex( $p ),
|
2023-06-22 09:41:37 +00:00
|
|
|
pointer = self.whichPointer( $p );
|
2020-11-18 09:11:12 +00:00
|
|
|
|
|
|
|
self.isDragged = false;
|
|
|
|
self.getRevisionListView().enableHover();
|
|
|
|
self.removePointerDragCursor();
|
|
|
|
|
|
|
|
if ( self.escapePressed ) {
|
|
|
|
return;
|
|
|
|
}
|
2017-04-06 11:47:59 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
mw.track( 'counter.MediaWiki.RevisionSlider.event.pointerMove' );
|
2017-04-06 11:47:59 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
pointer.setPosition( self.slider.getOldestVisibleRevisionIndex() + relativeIndex );
|
2017-06-29 14:15:10 +00:00
|
|
|
|
2023-06-22 09:41:37 +00:00
|
|
|
const diff = self.getRevElementAtPosition(
|
2020-11-18 09:11:12 +00:00
|
|
|
$revisions, self.getNewerPointerPos()
|
|
|
|
).data( 'revid' );
|
|
|
|
|
2023-06-22 09:41:37 +00:00
|
|
|
const oldid = self.getRevElementAtPosition(
|
2020-11-18 09:11:12 +00:00
|
|
|
$revisions, self.getOlderPointerPos()
|
|
|
|
).data( 'revid' );
|
|
|
|
|
|
|
|
if ( self.getNewerPointerPos() === self.lastNewPointerPosition &&
|
|
|
|
self.getOlderPointerPos() === self.lastOldPointerPosition ) {
|
|
|
|
return;
|
2017-04-06 11:47:59 +00:00
|
|
|
}
|
2020-11-18 09:11:12 +00:00
|
|
|
|
|
|
|
self.refreshDiffView( diff, oldid, true );
|
|
|
|
self.alignPointersAndLines( 0 );
|
|
|
|
self.resetRevisionStylesBasedOnPointerPosition( $revisions );
|
|
|
|
},
|
|
|
|
drag: function ( event, ui ) {
|
|
|
|
lastValidLeftPos = self.draggableDragAction(
|
|
|
|
event,
|
|
|
|
ui,
|
|
|
|
this,
|
|
|
|
lastValidLeftPos
|
|
|
|
);
|
|
|
|
},
|
|
|
|
revert: function () {
|
|
|
|
return self.escapePressed;
|
2017-04-06 11:47:59 +00:00
|
|
|
}
|
2020-11-18 09:11:12 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
pointerIsBlockedByOther: function ( pointerElement ) {
|
2023-06-22 09:41:37 +00:00
|
|
|
const pointer = this.whichPointer( $( pointerElement ) ),
|
2020-11-18 09:11:12 +00:00
|
|
|
isNewer = pointer.getView().isNewerPointer();
|
|
|
|
|
|
|
|
return ( isNewer && this.getOlderPointerPos() >= this.slider.getNewestVisibleRevisionIndex() + 1 ) ||
|
|
|
|
( !isNewer && this.getNewerPointerPos() <= this.slider.getOldestVisibleRevisionIndex() + 1 );
|
|
|
|
},
|
2017-04-06 11:47:59 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
draggableDragAction: function ( event, ui, pointer, lastValidLeftPos ) {
|
2023-06-22 09:41:37 +00:00
|
|
|
const pos = this.getRevisionPositionFromLeftOffset(
|
2020-11-18 09:11:12 +00:00
|
|
|
$( pointer ).offset().left + this.revisionWidth / 2
|
|
|
|
);
|
|
|
|
|
|
|
|
if ( pos === lastValidLeftPos ) {
|
2017-06-29 14:15:10 +00:00
|
|
|
return pos;
|
2020-11-18 09:11:12 +00:00
|
|
|
}
|
2017-02-02 17:24:51 +00:00
|
|
|
|
2023-06-22 09:41:37 +00:00
|
|
|
const $revisions = this.getRevisionsElement();
|
|
|
|
const $hoveredRevisionWrapper = this.getRevElementAtPosition( $revisions, pos ).parent();
|
2020-11-18 09:11:12 +00:00
|
|
|
this.getRevisionListView().showTooltip( $hoveredRevisionWrapper );
|
|
|
|
|
|
|
|
return pos;
|
|
|
|
},
|
|
|
|
|
|
|
|
getRevisionPositionFromLeftOffset: function ( leftOffset ) {
|
2023-06-22 09:41:37 +00:00
|
|
|
const $revisions = this.getRevisionsElement(),
|
|
|
|
revisionsX = utils.correctElementOffsets( $revisions.offset() ).left;
|
|
|
|
let pos = Math.ceil( Math.abs( leftOffset - revisionsX ) / this.revisionWidth );
|
2020-11-18 09:11:12 +00:00
|
|
|
|
|
|
|
if ( this.dir === 'rtl' ) {
|
|
|
|
// pre-loading the revisions on the right side leads to shifted position numbers
|
|
|
|
if ( this.slider.isAtStart() ) {
|
|
|
|
pos = this.slider.getRevisionsPerWindow() - pos + 1;
|
2016-06-27 14:00:13 +00:00
|
|
|
} else {
|
2020-11-18 09:11:12 +00:00
|
|
|
pos += this.slider.getRevisionsPerWindow();
|
2016-05-12 11:29:45 +00:00
|
|
|
}
|
2020-11-18 09:11:12 +00:00
|
|
|
}
|
2017-06-29 14:35:54 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
return pos;
|
|
|
|
},
|
|
|
|
|
|
|
|
setPointerDragCursor: function () {
|
|
|
|
$( '.mw-revslider-pointer, ' +
|
|
|
|
'.mw-revslider-pointer-container, ' +
|
|
|
|
'.mw-revslider-pointer-container-newer, ' +
|
|
|
|
'.mw-revslider-pointer-container-older, ' +
|
|
|
|
'.mw-revslider-pointer-line, ' +
|
|
|
|
'.mw-revslider-revision-wrapper' )
|
|
|
|
.addClass( 'mw-revslider-pointer-grabbing' );
|
|
|
|
},
|
|
|
|
|
|
|
|
removePointerDragCursor: function () {
|
|
|
|
$( '.mw-revslider-pointer, ' +
|
|
|
|
'.mw-revslider-pointer-container, ' +
|
|
|
|
'.mw-revslider-pointer-container-newer, ' +
|
|
|
|
'.mw-revslider-pointer-container-older, ' +
|
|
|
|
'.mw-revslider-pointer-line, ' +
|
|
|
|
'.mw-revslider-revision-wrapper' )
|
|
|
|
.removeClass( 'mw-revslider-pointer-grabbing' );
|
|
|
|
},
|
2017-06-29 14:35:54 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
/**
|
|
|
|
* Get the relative index for a pointer.
|
|
|
|
*
|
|
|
|
* @param {jQuery} $pointer
|
|
|
|
* @return {number}
|
|
|
|
*/
|
|
|
|
getRelativePointerIndex: function ( $pointer ) {
|
2023-06-22 09:41:37 +00:00
|
|
|
let pos = $pointer.position().left;
|
|
|
|
const pointer = this.whichPointer( $pointer );
|
2017-06-29 14:35:54 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
if ( this.dir === 'rtl' ) {
|
|
|
|
pos = pointer.getView().getAdjustedLeftPositionWhenRtl( pos );
|
|
|
|
}
|
|
|
|
return Math.ceil( ( pos + this.revisionWidth / 2 ) / this.revisionWidth );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads a new diff and optionally adds a state to the history
|
|
|
|
*
|
|
|
|
* @param {number} diff
|
|
|
|
* @param {number} oldid
|
|
|
|
* @param {boolean} pushState
|
|
|
|
* @return {jQuery}
|
|
|
|
*/
|
|
|
|
refreshDiffView: function ( diff, oldid, pushState ) {
|
|
|
|
this.diffPage.refresh( diff, oldid, this );
|
|
|
|
if ( pushState ) {
|
|
|
|
this.diffPage.pushState( diff, oldid, this );
|
|
|
|
}
|
|
|
|
return this.diffPage.lastRequest;
|
|
|
|
},
|
|
|
|
|
|
|
|
showNextDiff: function () {
|
|
|
|
this.updatePointersAndDiffView(
|
|
|
|
this.getNewerPointerPos() + 1,
|
|
|
|
this.getNewerPointerPos(),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
showPrevDiff: function () {
|
|
|
|
this.updatePointersAndDiffView(
|
|
|
|
this.getOlderPointerPos(),
|
|
|
|
this.getOlderPointerPos() - 1,
|
|
|
|
true
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates and moves pointers to new positions, resets styles and refreshes diff accordingly
|
|
|
|
*
|
|
|
|
* @param {number} newPointerPos
|
|
|
|
* @param {number} oldPointerPos
|
|
|
|
* @param {boolean} pushState
|
|
|
|
*/
|
|
|
|
updatePointersAndDiffView: function (
|
|
|
|
newPointerPos,
|
|
|
|
oldPointerPos,
|
|
|
|
pushState
|
|
|
|
) {
|
|
|
|
this.setNewerPointerPos( newPointerPos );
|
|
|
|
this.setOlderPointerPos( oldPointerPos );
|
|
|
|
this.alignPointersAndLines();
|
|
|
|
this.resetRevisionStylesBasedOnPointerPosition( this.getRevisionsElement() );
|
|
|
|
this.refreshDiffView(
|
|
|
|
+$( '.mw-revslider-revision[data-pos="' + newPointerPos + '"]' ).attr( 'data-revid' ),
|
|
|
|
+$( '.mw-revslider-revision[data-pos="' + oldPointerPos + '"]' ).attr( 'data-revid' ),
|
|
|
|
pushState
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {jQuery} $revs
|
|
|
|
* @param {number} pos
|
|
|
|
* @return {jQuery}
|
|
|
|
*/
|
|
|
|
getRevElementAtPosition: function ( $revs, pos ) {
|
|
|
|
return $revs.find( 'div.mw-revslider-revision[data-pos="' + pos + '"]' );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the jQuery element of the older selected revision
|
|
|
|
*
|
|
|
|
* @param {jQuery} $revs
|
|
|
|
* @return {jQuery}
|
|
|
|
*/
|
|
|
|
getOldRevElement: function ( $revs ) {
|
|
|
|
return $revs.find( 'div.mw-revslider-revision[data-revid="' + mw.config.get( 'wgDiffOldId' ) + '"]' );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the jQuery element of the newer selected revision
|
|
|
|
*
|
|
|
|
* @param {jQuery} $revs
|
|
|
|
* @return {jQuery}
|
|
|
|
*/
|
|
|
|
getNewRevElement: function ( $revs ) {
|
|
|
|
return $revs.find( 'div.mw-revslider-revision[data-revid="' + mw.config.get( 'wgDiffNewId' ) + '"]' );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the Pointer objects based on the selected revisions
|
|
|
|
*
|
|
|
|
* @param {jQuery} $oldRevElement
|
|
|
|
* @param {jQuery} $newRevElement
|
|
|
|
*/
|
|
|
|
initializePointers: function ( $oldRevElement, $newRevElement ) {
|
|
|
|
if ( this.getOlderPointerPos() !== 0 || this.getNewerPointerPos() !== 0 ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ( $oldRevElement.length === 0 && $newRevElement.length === 0 ) {
|
|
|
|
// Note: this is currently caught in init.js
|
|
|
|
throw new Error( 'RS-revs-not-specified' );
|
|
|
|
}
|
|
|
|
if ( $oldRevElement.length !== 0 ) {
|
|
|
|
this.setOlderPointerPos( $oldRevElement.data( 'pos' ) );
|
|
|
|
} else {
|
|
|
|
this.setOlderPointerPos( -1 );
|
|
|
|
}
|
|
|
|
this.setNewerPointerPos( $newRevElement.data( 'pos' ) );
|
|
|
|
this.resetSliderLines();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resets the slider lines based on the selected revisions
|
|
|
|
*/
|
|
|
|
resetSliderLines: function () {
|
|
|
|
this.updateOlderSliderLineCSS();
|
|
|
|
this.updateNewerSliderLineCSS();
|
|
|
|
},
|
|
|
|
|
|
|
|
updateOlderSliderLineCSS: function () {
|
2023-06-22 09:41:37 +00:00
|
|
|
let widthToSet = ( this.getOlderDistanceToOldest() + this.getDistanceBetweenPointers() ) *
|
|
|
|
this.revisionWidth;
|
|
|
|
const marginToSet = -this.revisionWidth / 2;
|
2020-11-18 09:11:12 +00:00
|
|
|
|
|
|
|
widthToSet = Math.min( widthToSet, this.calculateSliderContainerWidth() + this.revisionWidth );
|
|
|
|
|
|
|
|
this.setSliderLineCSS(
|
|
|
|
$( '.mw-revslider-pointer-container-older' ), widthToSet, marginToSet
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
updateNewerSliderLineCSS: function () {
|
2023-06-22 09:41:37 +00:00
|
|
|
let widthToSet = ( this.getNewerDistanceToNewest() + this.getDistanceBetweenPointers() + 2 ) *
|
2020-11-18 09:11:12 +00:00
|
|
|
this.revisionWidth,
|
|
|
|
marginToSet = ( this.getOlderDistanceToOldest() * this.revisionWidth ) -
|
|
|
|
this.revisionWidth / 2;
|
|
|
|
|
|
|
|
widthToSet = Math.min( widthToSet, this.calculateSliderContainerWidth() + this.revisionWidth );
|
|
|
|
marginToSet = Math.max( marginToSet, -0.5 * this.revisionWidth );
|
|
|
|
|
|
|
|
this.setSliderLineCSS(
|
|
|
|
$( '.mw-revslider-pointer-container-newer' ), widthToSet, marginToSet
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
setSliderLineCSS: function ( $lineContainer, widthToSet, marginToSet ) {
|
|
|
|
if ( this.dir === 'ltr' ) {
|
|
|
|
$lineContainer.css( {
|
|
|
|
width: widthToSet,
|
|
|
|
'margin-left': marginToSet
|
|
|
|
} );
|
|
|
|
} else {
|
|
|
|
$lineContainer.css( {
|
|
|
|
width: widthToSet,
|
|
|
|
'margin-right': marginToSet + this.revisionWidth
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
getOlderDistanceToOldest: function () {
|
|
|
|
return this.getOlderPointerPos() - this.slider.getOldestVisibleRevisionIndex();
|
|
|
|
},
|
|
|
|
|
|
|
|
getNewerDistanceToNewest: function () {
|
|
|
|
return this.slider.getNewestVisibleRevisionIndex() - this.getNewerPointerPos();
|
|
|
|
},
|
|
|
|
|
|
|
|
getDistanceBetweenPointers: function () {
|
|
|
|
return this.getNewerPointerPos() - this.getOlderPointerPos();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Highlights revisions between the pointers
|
|
|
|
*
|
|
|
|
* @param {jQuery} $revisions
|
|
|
|
*/
|
|
|
|
resetRevisionStylesBasedOnPointerPosition: function ( $revisions ) {
|
2023-06-22 09:41:37 +00:00
|
|
|
const olderRevPosition = this.getOlderPointerPos(),
|
2020-11-18 09:11:12 +00:00
|
|
|
newerRevPosition = this.getNewerPointerPos(),
|
|
|
|
startPosition = this.slider.getOldestVisibleRevisionIndex(),
|
2023-06-22 09:41:37 +00:00
|
|
|
endPosition = this.slider.getNewestVisibleRevisionIndex();
|
|
|
|
let positionIndex = startPosition;
|
2020-11-18 09:11:12 +00:00
|
|
|
|
|
|
|
$revisions.find( 'div.mw-revslider-revision' )
|
|
|
|
.removeClass( 'mw-revslider-revision-old mw-revslider-revision-new' );
|
|
|
|
$revisions.find( 'div.mw-revslider-revision-wrapper' )
|
|
|
|
.removeClass( 'mw-revslider-revision-intermediate mw-revslider-revision-older mw-revslider-revision-newer' );
|
|
|
|
|
|
|
|
this.getRevElementAtPosition( $revisions, olderRevPosition ).addClass( 'mw-revslider-revision-old' );
|
|
|
|
this.getRevElementAtPosition( $revisions, newerRevPosition ).addClass( 'mw-revslider-revision-new' );
|
|
|
|
|
|
|
|
while ( positionIndex <= endPosition ) {
|
|
|
|
positionIndex++;
|
|
|
|
if ( positionIndex <= olderRevPosition ) {
|
|
|
|
this.getRevElementAtPosition( $revisions, positionIndex ).parent().addClass( 'mw-revslider-revision-older' );
|
|
|
|
} else if ( positionIndex > olderRevPosition && positionIndex < newerRevPosition ) {
|
|
|
|
this.getRevElementAtPosition( $revisions, positionIndex ).parent().addClass( 'mw-revslider-revision-intermediate' );
|
|
|
|
} else if ( positionIndex >= newerRevPosition ) {
|
|
|
|
this.getRevElementAtPosition( $revisions, positionIndex ).parent().addClass( 'mw-revslider-revision-newer' );
|
2017-06-29 14:35:54 +00:00
|
|
|
}
|
2020-11-18 09:11:12 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Redraws the lines for the pointers
|
|
|
|
*/
|
|
|
|
redrawPointerLines: function () {
|
|
|
|
this.fadeInPointerLines();
|
|
|
|
$( '.mw-revslider-pointer-line-upper, .mw-revslider-pointer-line-lower' )
|
|
|
|
.removeClass( 'mw-revslider-bottom-line mw-revslider-left-line mw-revslider-right-line' );
|
|
|
|
this.pointerOlder.getLine().drawLine();
|
|
|
|
this.pointerNewer.getLine().drawLine();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fades out the lines for the pointers
|
|
|
|
*/
|
|
|
|
fadeOutPointerLines: function () {
|
|
|
|
// FIXME: Use CSS transition
|
|
|
|
// eslint-disable-next-line no-jquery/no-fade
|
|
|
|
$( '.mw-revslider-pointer-line' ).fadeTo( 0, 0.3 );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fades in the lines for the pointers
|
|
|
|
*/
|
|
|
|
fadeInPointerLines: function () {
|
|
|
|
// FIXME: Use CSS transition
|
|
|
|
// eslint-disable-next-line no-jquery/no-fade
|
|
|
|
$( '.mw-revslider-pointer-line' ).fadeTo( 0, 1 );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {number}
|
|
|
|
*/
|
|
|
|
calculateSliderContainerWidth: function () {
|
|
|
|
return Math.min(
|
|
|
|
this.slider.getRevisionList().getLength(),
|
2020-03-29 20:36:10 +00:00
|
|
|
utils.calculateRevisionsPerWindow( this.containerMargin + this.outerMargin, this.revisionWidth )
|
2020-11-18 09:11:12 +00:00
|
|
|
) * this.revisionWidth;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Slide the view to the next chunk of older / newer revisions
|
|
|
|
*
|
|
|
|
* @param {number} direction - Either -1, 0 or 1
|
|
|
|
* @param {number|string} [duration]
|
|
|
|
*/
|
|
|
|
slideView: function ( direction, duration ) {
|
2023-06-22 09:41:37 +00:00
|
|
|
const $animatedElement = this.$element.find( '.mw-revslider-revisions-container' ),
|
2020-11-18 09:11:12 +00:00
|
|
|
self = this;
|
|
|
|
|
|
|
|
this.slider.slide( direction );
|
|
|
|
this.pointerOlder.getView().getElement().draggable( 'disable' );
|
|
|
|
this.pointerNewer.getView().getElement().draggable( 'disable' );
|
|
|
|
|
|
|
|
if ( this.slider.isAtStart() ) {
|
|
|
|
this.backwardArrowButton.setDisabled( true );
|
|
|
|
} else {
|
|
|
|
this.backwardArrowButton.setDisabled( false );
|
|
|
|
}
|
|
|
|
if ( this.slider.isAtEnd() ) {
|
|
|
|
this.forwardArrowButton.setDisabled( true );
|
|
|
|
} else {
|
|
|
|
this.forwardArrowButton.setDisabled( false );
|
|
|
|
}
|
|
|
|
|
2023-06-22 09:41:37 +00:00
|
|
|
const animateObj = { scrollLeft: this.slider.getOldestVisibleRevisionIndex() * this.revisionWidth };
|
2020-11-18 09:11:12 +00:00
|
|
|
if ( this.dir === 'rtl' ) {
|
|
|
|
animateObj.scrollLeft = this.getRtlScrollLeft( $animatedElement, animateObj.scrollLeft );
|
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line no-jquery/no-animate
|
|
|
|
$animatedElement.animate(
|
|
|
|
animateObj,
|
|
|
|
duration,
|
|
|
|
null,
|
|
|
|
function () {
|
|
|
|
self.pointerOlder.getView().getElement().draggable( 'enable' );
|
|
|
|
self.pointerNewer.getView().getElement().draggable( 'enable' );
|
|
|
|
|
|
|
|
if ( self.slider.isAtStart() && !self.noMoreOlderRevisions ) {
|
|
|
|
self.addOlderRevisionsIfNeeded( $( '.mw-revslider-revision-slider' ) );
|
|
|
|
}
|
|
|
|
if ( self.slider.isAtEnd() && !self.noMoreNewerRevisions ) {
|
|
|
|
self.addNewerRevisionsIfNeeded( $( '.mw-revslider-revision-slider' ) );
|
2017-08-17 14:08:49 +00:00
|
|
|
}
|
2016-05-10 20:04:21 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
self.resetRevisionStylesBasedOnPointerPosition(
|
|
|
|
self.getRevisionsElement()
|
|
|
|
);
|
2016-05-10 20:47:37 +00:00
|
|
|
}
|
2020-11-18 09:11:12 +00:00
|
|
|
);
|
2016-05-10 20:47:37 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
this.alignPointersAndLines( duration );
|
|
|
|
},
|
2016-05-21 00:10:08 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
/**
|
|
|
|
* @param {jQuery} $element
|
|
|
|
* @param {number} scrollLeft
|
|
|
|
* @return {number}
|
|
|
|
*/
|
|
|
|
getRtlScrollLeft: function ( $element, scrollLeft ) {
|
|
|
|
if ( this.rtlScrollLeftType === 'reverse' ) {
|
|
|
|
return scrollLeft;
|
|
|
|
}
|
|
|
|
if ( this.rtlScrollLeftType === 'negative' ) {
|
|
|
|
return -scrollLeft;
|
|
|
|
}
|
|
|
|
return $element.prop( 'scrollWidth' ) - $element.width() - scrollLeft;
|
|
|
|
},
|
2016-05-10 12:42:05 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
/**
|
|
|
|
* Visually move pointers to the positions set and reset pointer- and slider-lines
|
|
|
|
*
|
|
|
|
* @param {number|string} [duration]
|
|
|
|
*/
|
|
|
|
alignPointersAndLines: function ( duration ) {
|
2023-06-22 09:41:37 +00:00
|
|
|
const self = this;
|
2020-11-18 09:11:12 +00:00
|
|
|
|
|
|
|
this.fadeOutPointerLines();
|
|
|
|
|
|
|
|
this.pointerOlder.getView()
|
|
|
|
.slideToSideOrPosition( this.slider, duration )
|
|
|
|
.promise().done( function () {
|
|
|
|
self.resetSliderLines();
|
|
|
|
self.redrawPointerLines();
|
|
|
|
} );
|
|
|
|
this.pointerNewer.getView()
|
|
|
|
.slideToSideOrPosition( this.slider, duration )
|
|
|
|
.promise().done( function () {
|
|
|
|
self.resetSliderLines();
|
|
|
|
self.redrawPointerLines();
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the Pointer object that belongs to the passed element
|
|
|
|
*
|
|
|
|
* @param {jQuery} $e
|
|
|
|
* @return {Pointer}
|
|
|
|
*/
|
|
|
|
whichPointer: function ( $e ) {
|
|
|
|
return $e.hasClass( 'mw-revslider-pointer-older' ) ? this.pointerOlder : this.pointerNewer;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {jQuery} $slider
|
|
|
|
*/
|
|
|
|
addNewerRevisionsIfNeeded: function ( $slider ) {
|
2023-06-22 09:41:37 +00:00
|
|
|
const api = new RevisionSliderApi( mw.util.wikiScript( 'api' ) ),
|
2020-11-18 09:11:12 +00:00
|
|
|
self = this,
|
|
|
|
revisions = this.slider.getRevisionList().getRevisions(),
|
2021-10-07 13:55:44 +00:00
|
|
|
revisionCount = utils.calculateRevisionsPerWindow( this.containerMargin + this.outerMargin, this.revisionWidth );
|
2020-11-18 09:11:12 +00:00
|
|
|
if ( this.noMoreNewerRevisions || !this.slider.isAtEnd() ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
api.fetchRevisionData( mw.config.get( 'wgPageName' ), {
|
|
|
|
startId: revisions[ revisions.length - 1 ].getId(),
|
|
|
|
dir: 'newer',
|
|
|
|
limit: revisionCount + 1,
|
|
|
|
knownUserGenders: this.slider.getRevisionList().getUserGenders(),
|
|
|
|
changeTags: this.slider.getRevisionList().getAvailableTags()
|
|
|
|
} ).then( function ( data ) {
|
2023-06-22 09:41:37 +00:00
|
|
|
const revs = data.revisions.slice( 1 );
|
2020-11-18 09:11:12 +00:00
|
|
|
if ( revs.length === 0 ) {
|
|
|
|
self.noMoreNewerRevisions = true;
|
|
|
|
return;
|
2016-05-21 00:10:08 +00:00
|
|
|
}
|
2020-11-18 09:11:12 +00:00
|
|
|
|
|
|
|
self.addRevisionsAtEnd( $slider, revs );
|
|
|
|
|
|
|
|
if ( !( 'continue' in data ) ) {
|
|
|
|
self.noMoreNewerRevisions = true;
|
2016-05-21 00:10:08 +00:00
|
|
|
}
|
2020-11-18 09:11:12 +00:00
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {jQuery} $slider
|
|
|
|
*/
|
|
|
|
addOlderRevisionsIfNeeded: function ( $slider ) {
|
2023-06-22 09:41:37 +00:00
|
|
|
const api = new RevisionSliderApi( mw.util.wikiScript( 'api' ) ),
|
2020-11-18 09:11:12 +00:00
|
|
|
self = this,
|
|
|
|
revisions = this.slider.getRevisionList().getRevisions(),
|
2023-06-22 09:41:37 +00:00
|
|
|
revisionCount = utils.calculateRevisionsPerWindow( this.containerMargin + this.outerMargin, this.revisionWidth );
|
|
|
|
let precedingRevisionSize = 0;
|
2020-11-18 09:11:12 +00:00
|
|
|
if ( this.noMoreOlderRevisions || !this.slider.isAtStart() ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
api.fetchRevisionData( mw.config.get( 'wgPageName' ), {
|
|
|
|
startId: revisions[ 0 ].getId(),
|
|
|
|
dir: 'older',
|
|
|
|
// fetch an extra revision if there are more older revision than the current "window",
|
|
|
|
// this makes it possible to correctly set a size of the bar related to the oldest revision to add
|
|
|
|
limit: revisionCount + 2,
|
|
|
|
knownUserGenders: this.slider.getRevisionList().getUserGenders(),
|
|
|
|
changeTags: this.slider.getRevisionList().getAvailableTags()
|
|
|
|
} ).then( function ( data ) {
|
2023-06-22 09:41:37 +00:00
|
|
|
let revs = data.revisions.slice( 1 ).reverse();
|
2020-11-18 09:11:12 +00:00
|
|
|
if ( revs.length === 0 ) {
|
|
|
|
self.noMoreOlderRevisions = true;
|
2016-06-27 14:00:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
if ( revs.length === revisionCount + 1 ) {
|
|
|
|
precedingRevisionSize = revs[ 0 ].size;
|
|
|
|
revs = revs.slice( 1 );
|
|
|
|
}
|
|
|
|
self.addRevisionsAtStart( $slider, revs, precedingRevisionSize );
|
2016-06-27 14:00:13 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
if ( !( 'continue' in data ) ) {
|
|
|
|
self.noMoreOlderRevisions = true;
|
2016-06-27 14:00:13 +00:00
|
|
|
}
|
2020-11-18 09:11:12 +00:00
|
|
|
} );
|
|
|
|
},
|
2016-06-27 14:00:13 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
/**
|
|
|
|
* @param {jQuery} $slider
|
|
|
|
* @param {Array} revs
|
|
|
|
*/
|
|
|
|
addRevisionsAtEnd: function ( $slider, revs ) {
|
2023-06-22 09:41:37 +00:00
|
|
|
const revPositionOffset = this.slider.getRevisionList().getLength(),
|
2021-10-07 13:55:44 +00:00
|
|
|
$revisions = $slider.find( '.mw-revslider-revisions-container .mw-revslider-revisions' );
|
2016-06-27 14:00:13 +00:00
|
|
|
|
2020-03-29 21:15:32 +00:00
|
|
|
this.slider.getRevisionList().push( makeRevisions( revs ) );
|
2016-06-27 14:00:13 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
// Pushed revisions have their relative sizes set correctly with regard to the last previously
|
|
|
|
// loaded revision. This should be taken into account when rendering newly loaded revisions (tooltip)
|
2023-06-22 09:41:37 +00:00
|
|
|
const revisionsToRender = this.slider.getRevisionList().slice( revPositionOffset );
|
2016-06-27 14:00:13 +00:00
|
|
|
|
2023-06-22 09:41:37 +00:00
|
|
|
const $addedRevisions = new RevisionListView( revisionsToRender, this.dir ).render( this.revisionWidth, revPositionOffset );
|
2016-06-27 14:00:13 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
$addedRevisions.find( '.mw-revslider-revision-wrapper' ).each( function () {
|
|
|
|
$revisions.append( $( this ) );
|
|
|
|
} );
|
2016-06-27 14:00:13 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
this.addClickHandlerToRevisions( this.getRevisionsElement() );
|
2016-06-27 14:00:13 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
if ( this.shouldExpandSlider( $slider ) ) {
|
|
|
|
this.expandSlider( $slider );
|
|
|
|
}
|
2016-06-27 14:00:13 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
this.getRevisionListView().adjustRevisionSizes( $slider );
|
2017-08-17 14:08:49 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
if ( !this.slider.isAtEnd() ) {
|
|
|
|
this.forwardArrowButton.setDisabled( false );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {jQuery} $slider
|
|
|
|
* @param {Array} revs
|
|
|
|
* @param {number} precedingRevisionSize optional size of the revision preceding the first of revs,
|
|
|
|
* used to correctly determine first revision's relative size
|
|
|
|
*/
|
|
|
|
addRevisionsAtStart: function ( $slider, revs, precedingRevisionSize ) {
|
2023-06-22 09:41:37 +00:00
|
|
|
const $revisions = $slider.find( '.mw-revslider-revisions-container .mw-revslider-revisions' );
|
|
|
|
const $revisionContainer = $slider.find( '.mw-revslider-revisions-container' );
|
|
|
|
let revisionStyleResetRequired = false;
|
2020-11-18 09:11:12 +00:00
|
|
|
|
2020-03-29 21:15:32 +00:00
|
|
|
this.slider.getRevisionList().unshift( makeRevisions( revs ), precedingRevisionSize );
|
2020-11-18 09:11:12 +00:00
|
|
|
|
|
|
|
$slider.find( '.mw-revslider-revision' ).each( function () {
|
|
|
|
$( this ).attr( 'data-pos', parseInt( $( this ).attr( 'data-pos' ), 10 ) + revs.length );
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Pushed (unshifted) revisions have their relative sizes set correctly with regard to the last previously
|
|
|
|
// loaded revision. This should be taken into account when rendering newly loaded revisions (tooltip)
|
2023-06-22 09:41:37 +00:00
|
|
|
const revisionsToRender = this.slider.getRevisionList().slice( 0, revs.length );
|
2020-11-18 09:11:12 +00:00
|
|
|
|
2023-06-22 09:41:37 +00:00
|
|
|
const $addedRevisions = new RevisionListView( revisionsToRender, this.dir ).render( this.revisionWidth );
|
2020-11-18 09:11:12 +00:00
|
|
|
|
|
|
|
this.addClickHandlerToRevisions( this.getRevisionsElement() );
|
|
|
|
|
|
|
|
if ( this.getOlderPointerPos() !== -1 ) {
|
|
|
|
this.setOlderPointerPos( this.getOlderPointerPos() + revisionsToRender.getLength() );
|
|
|
|
} else {
|
|
|
|
// Special case: old revision has been previously not loaded, need to initialize correct position
|
2023-06-22 09:41:37 +00:00
|
|
|
const $oldRevElement = this.getOldRevElement( $addedRevisions );
|
2020-11-18 09:11:12 +00:00
|
|
|
if ( $oldRevElement.length !== 0 ) {
|
|
|
|
this.setOlderPointerPos( $oldRevElement.data( 'pos' ) );
|
|
|
|
revisionStyleResetRequired = true;
|
2016-06-27 14:00:13 +00:00
|
|
|
}
|
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
}
|
|
|
|
this.setNewerPointerPos( this.getNewerPointerPos() + revisionsToRender.getLength() );
|
2016-06-27 14:00:13 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
$( $addedRevisions.find( '.mw-revslider-revision-wrapper' ).get().reverse() ).each( function () { // TODO: this is horrible
|
|
|
|
$revisions.prepend( $( this ) );
|
|
|
|
} );
|
2016-06-27 14:00:13 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
if ( revisionStyleResetRequired ) {
|
|
|
|
this.resetRevisionStylesBasedOnPointerPosition( $slider );
|
|
|
|
}
|
2016-06-27 14:00:13 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
this.slider.setFirstVisibleRevisionIndex( this.slider.getOldestVisibleRevisionIndex() + revisionsToRender.getLength() );
|
2016-06-27 14:00:13 +00:00
|
|
|
|
2023-08-24 08:58:22 +00:00
|
|
|
const revIdOld = this.getRevElementAtPosition( $revisions, this.getOlderPointerPos() ).data( 'revid' );
|
|
|
|
const revIdNew = this.getRevElementAtPosition( $revisions, this.getNewerPointerPos() ).data( 'revid' );
|
2020-11-18 09:11:12 +00:00
|
|
|
this.diffPage.replaceState( revIdNew, revIdOld, this );
|
2017-08-17 14:08:49 +00:00
|
|
|
|
2023-06-22 09:41:37 +00:00
|
|
|
const scrollLeft = this.slider.getOldestVisibleRevisionIndex() * this.revisionWidth;
|
2020-11-18 09:11:12 +00:00
|
|
|
$revisionContainer.scrollLeft( scrollLeft );
|
|
|
|
if ( this.dir === 'rtl' ) {
|
2023-08-24 08:58:22 +00:00
|
|
|
$revisionContainer.scrollLeft( this.getRtlScrollLeft( $revisionContainer, scrollLeft ) );
|
2020-11-18 09:11:12 +00:00
|
|
|
}
|
2016-06-27 14:00:13 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
if ( this.shouldExpandSlider( $slider ) ) {
|
|
|
|
this.expandSlider( $slider );
|
|
|
|
}
|
2016-06-27 14:00:13 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
this.getRevisionListView().adjustRevisionSizes( $slider );
|
2016-06-27 14:00:13 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
this.backwardArrowButton.setDisabled( false );
|
|
|
|
},
|
2016-06-27 14:00:13 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
/**
|
|
|
|
* @param {jQuery} $slider
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
shouldExpandSlider: function ( $slider ) {
|
2023-06-22 09:41:37 +00:00
|
|
|
const sliderWidth = $slider.width(),
|
2020-11-18 09:11:12 +00:00
|
|
|
maxAvailableWidth = this.calculateSliderContainerWidth() + this.containerMargin;
|
2016-08-16 10:36:52 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
return !( this.noMoreNewerRevisions && this.noMoreOlderRevisions ) && sliderWidth < maxAvailableWidth;
|
|
|
|
},
|
2016-06-27 14:00:13 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
/**
|
|
|
|
* @param {jQuery} $slider
|
|
|
|
*/
|
|
|
|
expandSlider: function ( $slider ) {
|
2023-06-22 09:41:37 +00:00
|
|
|
const containerWidth = this.calculateSliderContainerWidth();
|
2016-06-27 14:00:13 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
$slider.css( { width: ( containerWidth + this.containerMargin ) + 'px' } );
|
|
|
|
$slider.find( '.mw-revslider-revisions-container' ).css( { width: containerWidth + 'px' } );
|
|
|
|
$slider.find( '.mw-revslider-pointer-container' ).css( { width: containerWidth + this.revisionWidth - 1 + 'px' } );
|
2016-08-16 10:36:52 +00:00
|
|
|
|
2023-06-22 09:41:37 +00:00
|
|
|
const expandedRevisionWindowCapacity = $slider.find( '.mw-revslider-revisions-container' ).width() / this.revisionWidth;
|
2020-11-18 09:11:12 +00:00
|
|
|
this.slider.setRevisionsPerWindow( expandedRevisionWindowCapacity );
|
2016-06-27 14:00:13 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
this.slideView( Math.floor( ( this.getNewerPointerPos() - 1 ) / expandedRevisionWindowCapacity ), 0 );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {RevisionListView}
|
|
|
|
*/
|
|
|
|
getRevisionListView: function () {
|
|
|
|
return this.slider.getRevisionList().getView();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {jQuery}
|
|
|
|
*/
|
|
|
|
getRevisionsElement: function () {
|
|
|
|
return this.getRevisionListView().getElement();
|
|
|
|
}
|
|
|
|
} );
|
2016-05-10 12:42:05 +00:00
|
|
|
|
2020-03-29 20:36:10 +00:00
|
|
|
module.exports = SliderView;
|