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() );
|
2023-10-18 13:31:36 +00:00
|
|
|
this.diffPage.addHandlersToCoreLinks( this );
|
|
|
|
this.diffPage.initOnPopState( this );
|
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' );
|
|
|
|
|
2024-01-27 12:16:52 +00:00
|
|
|
this.backwardArrowButton = sliderArrowView.renderArrowButton( -1 );
|
|
|
|
this.forwardArrowButton = sliderArrowView.renderArrowButton( 1 );
|
2020-11-18 09:11:12 +00:00
|
|
|
|
|
|
|
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' } ),
|
2024-02-21 17:40:07 +00:00
|
|
|
this.pointerOlder.getLine().getElement(), this.pointerNewer.getLine().getElement(),
|
2020-11-18 09:11:12 +00:00
|
|
|
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.replaceState( mw.config.get( 'wgDiffNewId' ), mw.config.get( 'wgDiffOldId' ), this );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the revisions container and adds the revisions to it
|
|
|
|
*
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
2020-11-18 09:11:12 +00:00
|
|
|
* @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
|
|
|
|
*
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
2020-11-18 09:11:12 +00:00
|
|
|
* @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() )
|
2023-08-28 09:47:21 +00:00
|
|
|
.on( 'click', this.revisionsClickHandler.bind( this ) )
|
2020-11-18 09:11:12 +00:00
|
|
|
.on( 'mouseout', function () {
|
|
|
|
if ( !self.isDragged ) {
|
2024-02-20 07:43:15 +00:00
|
|
|
self.getRevisionListView().removeAllRevisionPreviewHighlights();
|
2020-11-18 09:11:12 +00:00
|
|
|
}
|
|
|
|
} )
|
|
|
|
.on( 'mouseover', function ( event ) {
|
|
|
|
if ( !self.isDragged ) {
|
2024-02-20 07:43:15 +00:00
|
|
|
lastMouseMoveRevisionPos = self.pointerContainerMouseMoveHandler(
|
2020-11-18 09:11:12 +00:00
|
|
|
event,
|
|
|
|
null
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} )
|
|
|
|
.on( 'mousemove', function ( event ) {
|
|
|
|
if ( !self.isDragged ) {
|
2024-02-20 07:43:15 +00:00
|
|
|
lastMouseMoveRevisionPos = self.pointerContainerMouseMoveHandler(
|
2020-11-18 09:11:12 +00:00
|
|
|
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
|
|
|
|
2023-10-24 13:45:31 +00:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @return {jQuery[]}
|
|
|
|
*/
|
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' ),
|
2024-02-21 17:40:07 +00:00
|
|
|
this.pointerOlder.getView().getElement()
|
2020-11-18 09:11:12 +00:00
|
|
|
),
|
|
|
|
$( '<div>' )
|
|
|
|
.addClass( 'mw-revslider-pointer-container-newer' )
|
|
|
|
.append(
|
|
|
|
$( '<div>' ).addClass( 'mw-revslider-slider-line' ),
|
2024-02-21 17:40:07 +00:00
|
|
|
this.pointerNewer.getView().getElement()
|
2020-11-18 09:11:12 +00:00
|
|
|
)
|
|
|
|
];
|
|
|
|
},
|
2018-09-11 06:10:47 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
/**
|
|
|
|
* Initializes the pointer dragging logic
|
|
|
|
*
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
2020-11-18 09:11:12 +00:00
|
|
|
* @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
|
|
|
|
2023-08-29 13:18:50 +00:00
|
|
|
$pointers
|
|
|
|
.on( 'focus', function ( event ) {
|
|
|
|
self.onPointerFocus( event, $revisions );
|
|
|
|
} )
|
2023-08-28 15:45:54 +00:00
|
|
|
.on( 'blur', this.getRevisionListView().onFocusBlur.bind( this.getRevisionListView() ) )
|
2023-08-29 13:18:50 +00:00
|
|
|
.on( 'keydown', function ( event ) {
|
|
|
|
self.buildTabbingRulesOnKeyDown( $( this ), event, $revisions );
|
|
|
|
} )
|
|
|
|
.on( 'keyup', function ( event ) {
|
|
|
|
self.buildTabbingRulesOnKeyUp( $( this ), event, $revisions );
|
|
|
|
} )
|
|
|
|
.on(
|
|
|
|
'touchstart touchmove touchend touchcancel touchleave',
|
|
|
|
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-10-24 13:45:31 +00:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @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-10-24 13:45:31 +00:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @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
|
|
|
/**
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
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
|
|
|
/**
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
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
|
|
|
|
2023-10-24 13:45:31 +00:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @param {MouseEvent} event
|
|
|
|
* @param {number} lastValidPosition
|
|
|
|
* @return {number}
|
|
|
|
*/
|
2024-02-20 07:43:15 +00:00
|
|
|
pointerContainerMouseMoveHandler: 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();
|
2024-02-20 07:43:15 +00:00
|
|
|
this.getRevisionListView().removeAllRevisionPreviewHighlights();
|
2024-02-20 08:11:21 +00:00
|
|
|
if ( $hoveredRevisionWrapper.length ) {
|
|
|
|
this.getRevisionListView().onRevisionHover( $hoveredRevisionWrapper, event );
|
|
|
|
}
|
2020-11-18 09:11:12 +00:00
|
|
|
|
|
|
|
return pos;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2023-08-28 09:47:21 +00:00
|
|
|
* React on clicks on a revision element and move pointers
|
2020-11-18 09:11:12 +00:00
|
|
|
*
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
2020-11-18 09:11:12 +00:00
|
|
|
* @param {MouseEvent} event
|
|
|
|
*/
|
2023-08-28 09:47:21 +00:00
|
|
|
revisionsClickHandler: function ( event ) {
|
2024-02-09 11:29:08 +00:00
|
|
|
let clickedPos;
|
|
|
|
// Just use the information from the element that received the click, if available
|
|
|
|
const $revElement = $( event.currentTarget ).find( '.mw-revslider-revision' );
|
|
|
|
if ( $revElement.length === 1 ) {
|
2024-02-21 12:56:44 +00:00
|
|
|
clickedPos = +$revElement.attr( 'data-pos' );
|
2024-02-09 11:29:08 +00:00
|
|
|
} else {
|
|
|
|
clickedPos = this.getRevisionPositionFromLeftOffset( event.pageX );
|
|
|
|
}
|
|
|
|
const $revisionWrapper = this.getRevElementAtPosition( this.getRevisionsElement(), clickedPos ).parent();
|
2023-11-29 11:50:34 +00:00
|
|
|
// Fail-safe in case a mouse click outside the valid range is picked up
|
|
|
|
if ( !$revisionWrapper.length ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const hasClickedTop = event.pageY - $revisionWrapper.offset().top < $revisionWrapper.height() / 2;
|
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 {
|
2023-08-29 13:18:50 +00:00
|
|
|
newNewerPointerPos = clickedPos;
|
|
|
|
newOlderPointerPos = clickedPos;
|
2020-11-18 09:11:12 +00:00
|
|
|
if ( hasClickedTop ) {
|
2023-08-29 13:18:50 +00:00
|
|
|
newOlderPointerPos--;
|
2017-06-29 14:35:54 +00:00
|
|
|
} else {
|
2023-08-29 13:18:50 +00:00
|
|
|
newNewerPointerPos++;
|
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
|
|
|
|
2024-02-10 15:10:47 +00:00
|
|
|
this.updatePointersAndDiffView( newNewerPointerPos, newOlderPointerPos );
|
2020-11-18 09:11:12 +00:00
|
|
|
},
|
2017-08-17 14:08:49 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
/**
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
2020-11-18 09:11:12 +00:00
|
|
|
* @param {jQuery} $revisions
|
|
|
|
*/
|
|
|
|
addClickHandlerToRevisions: function ( $revisions ) {
|
2023-08-28 09:47:21 +00:00
|
|
|
$revisions.find( '.mw-revslider-revision-wrapper' )
|
|
|
|
.on( 'click', this.revisionsClickHandler.bind( this ) );
|
2020-11-18 09:11:12 +00:00
|
|
|
},
|
|
|
|
|
2023-10-24 13:45:31 +00:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @param {MouseEvent} event
|
|
|
|
* @param {jQuery} $revisions
|
|
|
|
*/
|
2023-08-25 14:39:18 +00:00
|
|
|
onPointerFocus: function ( event, $revisions ) {
|
|
|
|
const $hoveredRevisionWrapper = this.getRevElementAtPosition(
|
|
|
|
$revisions,
|
|
|
|
this.whichPointer( $( event.target ) ).getPosition()
|
|
|
|
).parent();
|
2023-08-31 10:08:43 +00:00
|
|
|
this.getRevisionListView().setRevisionFocus( $hoveredRevisionWrapper );
|
2023-08-25 14:39:18 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
/**
|
|
|
|
* Build rules for tabbing when `keydown` event triggers on pointers
|
|
|
|
*
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
2020-11-18 09:11:12 +00:00
|
|
|
* @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
|
|
|
|
2024-02-22 15:22:20 +00:00
|
|
|
if ( event.which === ( this.dir === 'rtl' ? OO.ui.Keys.LEFT : 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
|
|
|
}
|
|
|
|
}
|
2024-02-22 15:22:20 +00:00
|
|
|
} else if ( event.which === ( this.dir === 'rtl' ? OO.ui.Keys.RIGHT : 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 ) {
|
|
|
|
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();
|
2023-08-28 13:20:10 +00:00
|
|
|
|
|
|
|
if ( $( '.mw-revslider-revision-tooltip' ).length && event.which === OO.ui.Keys.ENTER ) {
|
2023-08-31 10:08:43 +00:00
|
|
|
this.getRevisionListView().removeCurrentRevisionFocus();
|
2023-08-28 13:20:10 +00:00
|
|
|
} else {
|
2023-08-31 10:08:43 +00:00
|
|
|
this.getRevisionListView().setRevisionFocus( $hoveredRevisionWrapper );
|
2023-08-28 13:20:10 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
2020-11-18 09:11:12 +00:00
|
|
|
* @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
|
|
|
|
2024-02-21 12:56:44 +00:00
|
|
|
const diff = +this.getRevElementAtPosition(
|
2023-08-24 08:58:22 +00:00
|
|
|
$revisions, this.getNewerPointerPos()
|
2024-02-21 12:56:44 +00:00
|
|
|
).attr( 'data-revid' );
|
2017-07-10 16:50:22 +00:00
|
|
|
|
2024-02-21 12:56:44 +00:00
|
|
|
const oldid = +this.getRevElementAtPosition(
|
2023-08-24 08:58:22 +00:00
|
|
|
$revisions, this.getOlderPointerPos()
|
2024-02-21 12:56:44 +00:00
|
|
|
).attr( 'data-revid' );
|
2017-07-10 16:50:22 +00:00
|
|
|
|
2024-02-10 15:10:47 +00:00
|
|
|
this.lastRequest = this.refreshDiffView( diff, oldid );
|
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
|
|
|
|
*
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
2020-11-18 09:11:12 +00:00
|
|
|
* @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;
|
2024-02-20 07:43:15 +00:00
|
|
|
self.getRevisionListView().enableRevisionPreviewHighlights( false );
|
2020-11-18 09:11:12 +00:00
|
|
|
self.setPointerDragCursor();
|
2023-08-25 14:20:35 +00:00
|
|
|
self.fadeOutPointerLines( true );
|
2020-11-18 09:11:12 +00:00
|
|
|
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;
|
2024-02-20 07:43:15 +00:00
|
|
|
self.getRevisionListView().enableRevisionPreviewHighlights();
|
2023-11-29 12:15:08 +00:00
|
|
|
self.setPointerDragCursor( false );
|
2020-11-18 09:11:12 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2024-02-21 12:56:44 +00:00
|
|
|
const diff = +self.getRevElementAtPosition(
|
2020-11-18 09:11:12 +00:00
|
|
|
$revisions, self.getNewerPointerPos()
|
2024-02-21 12:56:44 +00:00
|
|
|
).attr( 'data-revid' );
|
2020-11-18 09:11:12 +00:00
|
|
|
|
2024-02-21 12:56:44 +00:00
|
|
|
const oldid = +self.getRevElementAtPosition(
|
2020-11-18 09:11:12 +00:00
|
|
|
$revisions, self.getOlderPointerPos()
|
2024-02-21 12:56:44 +00:00
|
|
|
).attr( 'data-revid' );
|
2020-11-18 09:11:12 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2024-02-10 15:10:47 +00:00
|
|
|
self.refreshDiffView( diff, oldid );
|
2020-11-18 09:11:12 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2023-10-24 13:45:31 +00:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @param {Element} pointerElement
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
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
|
|
|
|
2023-10-24 13:45:31 +00:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @param {Event} event
|
|
|
|
* @param {Object} ui
|
|
|
|
* @param {Element} pointer
|
|
|
|
* @param {number} lastValidLeftPos
|
|
|
|
* @return {number}
|
|
|
|
*/
|
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();
|
2023-08-31 10:08:43 +00:00
|
|
|
this.getRevisionListView().setRevisionFocus( $hoveredRevisionWrapper );
|
2020-11-18 09:11:12 +00:00
|
|
|
|
|
|
|
return pos;
|
|
|
|
},
|
|
|
|
|
2023-10-24 13:45:31 +00:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @param {number} leftOffset
|
|
|
|
* @return {number}
|
|
|
|
*/
|
2020-11-18 09:11:12 +00:00
|
|
|
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;
|
|
|
|
},
|
|
|
|
|
2023-10-24 13:45:31 +00:00
|
|
|
/**
|
|
|
|
* @private
|
2023-11-29 12:15:08 +00:00
|
|
|
* @param {boolean} [show=true]
|
2023-10-24 13:45:31 +00:00
|
|
|
*/
|
2023-11-29 12:15:08 +00:00
|
|
|
setPointerDragCursor: function ( show ) {
|
2020-11-18 09:11:12 +00:00
|
|
|
$( '.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' )
|
2023-11-29 12:15:08 +00:00
|
|
|
.toggleClass( 'mw-revslider-pointer-grabbing', show !== false );
|
2020-11-18 09:11:12 +00:00
|
|
|
},
|
2017-06-29 14:35:54 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
/**
|
|
|
|
* Get the relative index for a pointer.
|
|
|
|
*
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
2020-11-18 09:11:12 +00:00
|
|
|
* @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
|
|
|
|
*
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
2020-11-18 09:11:12 +00:00
|
|
|
* @param {number} diff
|
|
|
|
* @param {number} oldid
|
2024-02-10 15:10:47 +00:00
|
|
|
* @param {boolean} [pushState=true] False to skip manipulating the browser history
|
2020-11-18 09:11:12 +00:00
|
|
|
* @return {jQuery}
|
|
|
|
*/
|
|
|
|
refreshDiffView: function ( diff, oldid, pushState ) {
|
|
|
|
this.diffPage.refresh( diff, oldid, this );
|
2024-02-10 15:10:47 +00:00
|
|
|
if ( pushState !== false ) {
|
2020-11-18 09:11:12 +00:00
|
|
|
this.diffPage.pushState( diff, oldid, this );
|
|
|
|
}
|
|
|
|
return this.diffPage.lastRequest;
|
|
|
|
},
|
|
|
|
|
|
|
|
showNextDiff: function () {
|
|
|
|
this.updatePointersAndDiffView(
|
|
|
|
this.getNewerPointerPos() + 1,
|
2024-02-10 15:10:47 +00:00
|
|
|
this.getNewerPointerPos()
|
2020-11-18 09:11:12 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
showPrevDiff: function () {
|
|
|
|
this.updatePointersAndDiffView(
|
|
|
|
this.getOlderPointerPos(),
|
2024-02-10 15:10:47 +00:00
|
|
|
this.getOlderPointerPos() - 1
|
2020-11-18 09:11:12 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates and moves pointers to new positions, resets styles and refreshes diff accordingly
|
|
|
|
*
|
|
|
|
* @param {number} newPointerPos
|
|
|
|
* @param {number} oldPointerPos
|
2024-02-10 15:10:47 +00:00
|
|
|
* @param {boolean} [pushState=true] False to skip manipulating the browser history
|
2020-11-18 09:11:12 +00:00
|
|
|
*/
|
|
|
|
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
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
2020-11-18 09:11:12 +00:00
|
|
|
* @param {jQuery} $revs
|
|
|
|
* @param {number} pos
|
|
|
|
* @return {jQuery}
|
|
|
|
*/
|
|
|
|
getRevElementAtPosition: function ( $revs, pos ) {
|
2024-02-12 11:07:53 +00:00
|
|
|
return $revs.find( '.mw-revslider-revision[data-pos="' + pos + '"]' );
|
2020-11-18 09:11:12 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the jQuery element of the older selected revision
|
|
|
|
*
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
2020-11-18 09:11:12 +00:00
|
|
|
* @param {jQuery} $revs
|
|
|
|
* @return {jQuery}
|
|
|
|
*/
|
|
|
|
getOldRevElement: function ( $revs ) {
|
2024-02-12 11:07:53 +00:00
|
|
|
return $revs.find( '.mw-revslider-revision[data-revid="' + mw.config.get( 'wgDiffOldId' ) + '"]' );
|
2020-11-18 09:11:12 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the jQuery element of the newer selected revision
|
|
|
|
*
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
2020-11-18 09:11:12 +00:00
|
|
|
* @param {jQuery} $revs
|
|
|
|
* @return {jQuery}
|
|
|
|
*/
|
|
|
|
getNewRevElement: function ( $revs ) {
|
2024-02-12 11:07:53 +00:00
|
|
|
return $revs.find( '.mw-revslider-revision[data-revid="' + mw.config.get( 'wgDiffNewId' ) + '"]' );
|
2020-11-18 09:11:12 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the Pointer objects based on the selected revisions
|
|
|
|
*
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
2020-11-18 09:11:12 +00:00
|
|
|
* @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' );
|
|
|
|
}
|
2024-02-21 12:56:44 +00:00
|
|
|
this.setOlderPointerPos( $oldRevElement.length ? +$oldRevElement.attr( 'data-pos' ) : -1 );
|
|
|
|
this.setNewerPointerPos( +$newRevElement.attr( 'data-pos' ) );
|
2020-11-18 09:11:12 +00:00
|
|
|
this.resetSliderLines();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resets the slider lines based on the selected revisions
|
2023-10-24 13:45:31 +00:00
|
|
|
*
|
|
|
|
* @private
|
2020-11-18 09:11:12 +00:00
|
|
|
*/
|
|
|
|
resetSliderLines: function () {
|
|
|
|
this.setSliderLineCSS(
|
2024-02-10 15:35:37 +00:00
|
|
|
$( '.mw-revslider-pointer-container-older' ),
|
|
|
|
this.getOlderDistanceToOldest() + this.getDistanceBetweenPointers(),
|
|
|
|
0
|
2020-11-18 09:11:12 +00:00
|
|
|
);
|
|
|
|
this.setSliderLineCSS(
|
2024-02-10 15:35:37 +00:00
|
|
|
$( '.mw-revslider-pointer-container-newer' ),
|
|
|
|
this.getNewerDistanceToNewest() + this.getDistanceBetweenPointers() + 2,
|
|
|
|
this.getOlderDistanceToOldest()
|
2020-11-18 09:11:12 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2023-10-24 13:45:31 +00:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @param {jQuery} $lineContainer
|
2024-02-10 15:35:37 +00:00
|
|
|
* @param {number} widthToSet Total width of the line, in position units
|
|
|
|
* @param {number} marginToSet Start of the line from the left, in position units
|
2023-10-24 13:45:31 +00:00
|
|
|
*/
|
2020-11-18 09:11:12 +00:00
|
|
|
setSliderLineCSS: function ( $lineContainer, widthToSet, marginToSet ) {
|
2024-02-10 15:35:37 +00:00
|
|
|
const maxWidth = this.calculateSliderContainerWidth() + this.revisionWidth;
|
|
|
|
widthToSet = Math.min( widthToSet * this.revisionWidth, maxWidth );
|
|
|
|
marginToSet = Math.max( 0, marginToSet * this.revisionWidth ) - this.revisionWidth / 2;
|
|
|
|
|
2023-08-25 14:23:18 +00:00
|
|
|
$lineContainer.css( 'width', widthToSet );
|
2020-11-18 09:11:12 +00:00
|
|
|
if ( this.dir === 'ltr' ) {
|
2023-08-25 14:23:18 +00:00
|
|
|
$lineContainer.css( 'margin-left', marginToSet );
|
2020-11-18 09:11:12 +00:00
|
|
|
} else {
|
2023-08-25 14:23:18 +00:00
|
|
|
$lineContainer.css( 'margin-right', marginToSet + this.revisionWidth );
|
2020-11-18 09:11:12 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2023-10-24 13:45:31 +00:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @return {number}
|
|
|
|
*/
|
2020-11-18 09:11:12 +00:00
|
|
|
getOlderDistanceToOldest: function () {
|
|
|
|
return this.getOlderPointerPos() - this.slider.getOldestVisibleRevisionIndex();
|
|
|
|
},
|
|
|
|
|
2023-10-24 13:45:31 +00:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @return {number}
|
|
|
|
*/
|
2020-11-18 09:11:12 +00:00
|
|
|
getNewerDistanceToNewest: function () {
|
|
|
|
return this.slider.getNewestVisibleRevisionIndex() - this.getNewerPointerPos();
|
|
|
|
},
|
|
|
|
|
2023-10-24 13:45:31 +00:00
|
|
|
/**
|
|
|
|
* @private
|
2024-02-10 15:35:37 +00:00
|
|
|
* @return {number} difference between the two positions, typically 1
|
2023-10-24 13:45:31 +00:00
|
|
|
*/
|
2020-11-18 09:11:12 +00:00
|
|
|
getDistanceBetweenPointers: function () {
|
|
|
|
return this.getNewerPointerPos() - this.getOlderPointerPos();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Highlights revisions between the pointers
|
|
|
|
*
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
2020-11-18 09:11:12 +00:00
|
|
|
* @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(),
|
2024-02-10 15:22:18 +00:00
|
|
|
// FIXME: Why do these methods return values that are off by one?
|
|
|
|
startPosition = this.slider.getOldestVisibleRevisionIndex() + 1,
|
|
|
|
endPosition = this.slider.getNewestVisibleRevisionIndex() + 1;
|
2020-11-18 09:11:12 +00:00
|
|
|
|
2024-02-10 15:22:18 +00:00
|
|
|
// We need to reset these in case they are outside the visible range
|
2024-02-12 11:07:53 +00:00
|
|
|
$revisions.find( '.mw-revslider-revision' )
|
2020-11-18 09:11:12 +00:00
|
|
|
.removeClass( 'mw-revslider-revision-old mw-revslider-revision-new' );
|
|
|
|
|
|
|
|
this.getRevElementAtPosition( $revisions, olderRevPosition ).addClass( 'mw-revslider-revision-old' );
|
|
|
|
this.getRevElementAtPosition( $revisions, newerRevPosition ).addClass( 'mw-revslider-revision-new' );
|
|
|
|
|
2024-02-10 15:22:18 +00:00
|
|
|
for ( let i = startPosition; i <= endPosition; i++ ) {
|
|
|
|
const older = i <= olderRevPosition;
|
|
|
|
const newer = i >= newerRevPosition;
|
|
|
|
this.getRevElementAtPosition( $revisions, i ).parent()
|
|
|
|
.toggleClass( 'mw-revslider-revision-older', older )
|
|
|
|
.toggleClass( 'mw-revslider-revision-intermediate', !older && !newer )
|
|
|
|
.toggleClass( 'mw-revslider-revision-newer', newer );
|
2020-11-18 09:11:12 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Redraws the lines for the pointers
|
2023-10-24 13:45:31 +00:00
|
|
|
*
|
|
|
|
* @private
|
2020-11-18 09:11:12 +00:00
|
|
|
*/
|
|
|
|
redrawPointerLines: function () {
|
2023-08-25 14:20:35 +00:00
|
|
|
this.fadeOutPointerLines( false );
|
2020-11-18 09:11:12 +00:00
|
|
|
$( '.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();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
2023-08-25 14:20:35 +00:00
|
|
|
* @param {boolean} fade
|
2020-11-18 09:11:12 +00:00
|
|
|
*/
|
2023-08-25 14:20:35 +00:00
|
|
|
fadeOutPointerLines: function ( fade ) {
|
|
|
|
$( '.mw-revslider-pointer-line' ).css( 'opacity', fade ? 0.3 : '' );
|
2020-11-18 09:11:12 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
2020-11-18 09:11:12 +00:00
|
|
|
* @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' );
|
|
|
|
|
2023-08-29 13:18:50 +00:00
|
|
|
this.backwardArrowButton.setDisabled( this.slider.isAtStart() );
|
|
|
|
this.forwardArrowButton.setDisabled( this.slider.isAtEnd() );
|
2020-11-18 09:11:12 +00:00
|
|
|
|
|
|
|
$animatedElement.animate(
|
2024-01-30 14:53:39 +00:00
|
|
|
{ scrollLeft: this.getScrollLeft( $animatedElement ) },
|
2020-11-18 09:11:12 +00:00
|
|
|
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
|
|
|
/**
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
2020-11-18 09:11:12 +00:00
|
|
|
* @param {jQuery} $element
|
|
|
|
* @return {number}
|
|
|
|
*/
|
2024-01-30 14:53:39 +00:00
|
|
|
getScrollLeft: function ( $element ) {
|
|
|
|
const scrollLeft = this.slider.getOldestVisibleRevisionIndex() * this.revisionWidth;
|
|
|
|
if ( this.dir !== 'rtl' || this.rtlScrollLeftType === 'reverse' ) {
|
2020-11-18 09:11:12 +00:00
|
|
|
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
|
|
|
|
*
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
2020-11-18 09:11:12 +00:00
|
|
|
* @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
|
|
|
|
2023-08-25 14:20:35 +00:00
|
|
|
this.fadeOutPointerLines( true );
|
2020-11-18 09:11:12 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
*
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
2020-11-18 09:11:12 +00:00
|
|
|
* @param {jQuery} $e
|
|
|
|
* @return {Pointer}
|
|
|
|
*/
|
|
|
|
whichPointer: function ( $e ) {
|
|
|
|
return $e.hasClass( 'mw-revslider-pointer-older' ) ? this.pointerOlder : this.pointerNewer;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
2020-11-18 09:11:12 +00:00
|
|
|
* @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
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
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
|
|
|
/**
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
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 );
|
2023-11-07 12:08:46 +00:00
|
|
|
this.addClickHandlerToRevisions( $addedRevisions );
|
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
|
|
|
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 );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
2020-11-18 09:11:12 +00:00
|
|
|
* @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 );
|
2023-11-07 12:08:46 +00:00
|
|
|
this.addClickHandlerToRevisions( $addedRevisions );
|
2020-11-18 09:11:12 +00:00
|
|
|
|
|
|
|
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 ) {
|
2024-02-21 12:56:44 +00:00
|
|
|
this.setOlderPointerPos( +$oldRevElement.attr( 'data-pos' ) );
|
2020-11-18 09:11:12 +00:00
|
|
|
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
|
|
|
|
2024-02-21 12:56:44 +00:00
|
|
|
const revIdOld = +this.getRevElementAtPosition( $revisions, this.getOlderPointerPos() ).attr( 'data-revid' );
|
|
|
|
const revIdNew = +this.getRevElementAtPosition( $revisions, this.getNewerPointerPos() ).attr( 'data-revid' );
|
2020-11-18 09:11:12 +00:00
|
|
|
this.diffPage.replaceState( revIdNew, revIdOld, this );
|
2017-08-17 14:08:49 +00:00
|
|
|
|
2024-01-30 14:53:39 +00:00
|
|
|
$revisionContainer.scrollLeft( this.getScrollLeft( $revisionContainer ) );
|
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
|
|
|
/**
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
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
|
|
|
/**
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
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 );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
2020-11-18 09:11:12 +00:00
|
|
|
* @return {RevisionListView}
|
|
|
|
*/
|
|
|
|
getRevisionListView: function () {
|
|
|
|
return this.slider.getRevisionList().getView();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
2020-11-18 09:11:12 +00:00
|
|
|
* @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;
|