Drop RTL scroll type detection, obsolete since 2023

According to https://www.mediawiki.org/wiki/Compatibility we can:
* Ignore Internet Explorer as well as "Edge legacy" (before it
  switched to Chromium) entirely.
* Ignore old Opera (Presto, before it switched to Chromium).
* Ignore Chrome and Chromium-based browsers that are more than
  3 years old.

According to https://github.com/othree/jquery.rtl-scroll-type
* Firefox and Safari always followed the web standard.
* The "reverse" type was only ever relevant in IE.
* The "default" type was only relevant in old Chrome and
  Chromium-based browsers, before the engine was changed to follow
  the web standard.

According to https://chromestatus.com/feature/5759578031521792 this
happened in version 85, June 2020.

The only edge-case I can think of is that we want to support some
niche browser that – for some reason – still uses Chromium 84 or
older. But according to https://www.mediawiki.org/wiki/Compatibility
we are at 88+ already, everywhere.

It appears like we can safely remove two types, which means only
the web standard behavior (a.k.a. "negative") is left.

No pressure merging this. This patch can as well sit here for
another year. ;-)

Bug: T352169
Change-Id: Ifdedfd6d16abc87576df9807a55cd1b8a7d185db
This commit is contained in:
thiemowmde 2024-03-12 17:41:38 +01:00
parent c75ba6880b
commit c45b92209c
2 changed files with 7 additions and 63 deletions

View file

@ -41,18 +41,6 @@ $.extend( SliderView.prototype, {
backwardArrowButton: null,
/** @type {OO.ui.ButtonWidget} */
forwardArrowButton: null,
/**
* @type {string}
*
* 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
*/
rtlScrollLeftType: 'default',
/** @type {boolean} */
noMoreNewerRevisions: false,
/** @type {boolean} */
@ -73,11 +61,7 @@ $.extend( SliderView.prototype, {
$revisions = this.getRevisionListView().render( this.revisionWidth ),
sliderArrowView = new SliderArrowView( this );
this.dir = $container.css( 'direction' ) || 'ltr';
if ( this.dir === 'rtl' ) {
this.rtlScrollLeftType = utils.determineRtlScrollType();
}
this.dir = $container.css( 'direction' );
this.pointerOlder = this.pointerOlder || new Pointer( 'mw-revslider-pointer-older' );
this.pointerNewer = this.pointerNewer || new Pointer( 'mw-revslider-pointer-newer' );
@ -891,7 +875,7 @@ $.extend( SliderView.prototype, {
this.forwardArrowButton.setDisabled( this.slider.isAtEnd() );
$animatedElement.animate(
{ scrollLeft: this.getScrollLeft( $animatedElement ) },
{ scrollLeft: this.getScrollLeft() },
duration,
null,
function () {
@ -916,18 +900,13 @@ $.extend( SliderView.prototype, {
/**
* @private
* @param {jQuery} $element
* @return {number}
*/
getScrollLeft: function ( $element ) {
getScrollLeft: function () {
const scrollLeft = this.slider.getOldestVisibleRevisionIndex() * this.revisionWidth;
if ( this.dir !== 'rtl' || this.rtlScrollLeftType === 'reverse' ) {
return scrollLeft;
}
if ( this.rtlScrollLeftType === 'negative' ) {
return -scrollLeft;
}
return $element.prop( 'scrollWidth' ) - $element.width() - scrollLeft;
// See https://github.com/othree/jquery.rtl-scroll-type for why we don't need anything else
// anymore.
return this.dir === 'rtl' ? -scrollLeft : scrollLeft;
},
/**
@ -1124,7 +1103,7 @@ $.extend( SliderView.prototype, {
const revIdNew = +this.getRevElementAtPosition( $revisions, this.getNewerPointerPos() ).attr( 'data-revid' );
this.diffPage.replaceState( revIdNew, revIdOld, this );
$revisionContainer.scrollLeft( this.getScrollLeft( $revisionContainer ) );
$revisionContainer.scrollLeft( this.getScrollLeft() );
if ( this.shouldExpandSlider( $slider ) ) {
this.expandSlider( $slider );

View file

@ -68,40 +68,6 @@ function correctElementOffsets( offset ) {
return offset;
}
/**
* Based on jQuery RTL Scroll Type Detector plugin by othree: https://github.com/othree/jquery.rtl-scroll-type
*
* @return {string} - 'default', 'negative' or 'reverse'
*/
function determineRtlScrollType() {
const $dummy = $( '<div>' )
.css( {
dir: 'rtl',
width: '4px',
height: '1px',
position: 'absolute',
top: '-1000px',
overflow: 'scroll'
} )
.text( 'ABCDE' )
.appendTo( 'body' );
const definer = $dummy[ 0 ];
let type = 'reverse';
if ( definer.scrollLeft > 0 ) {
type = 'default';
} else {
definer.scrollLeft = 1;
// T352169: While Chrome ignores the +1 above (as it should), there are strange rounding
// errors with many (not all) of the possible zoom factors >100%
if ( definer.scrollLeft < 1 ) {
type = 'negative';
}
}
$dummy.remove();
return type;
}
function calculateRevisionsPerWindow( margin, revisionWidth ) {
return Math.floor( ( $( '#mw-content-text' ).width() - margin ) / revisionWidth );
}
@ -109,6 +75,5 @@ function calculateRevisionsPerWindow( margin, revisionWidth ) {
module.exports = {
calculateRevisionsPerWindow: calculateRevisionsPerWindow,
correctElementOffsets: correctElementOffsets,
determineRtlScrollType: determineRtlScrollType,
touchEventConverter: touchEventConverter
};