Move scrollType detection to utils

Change-Id: I465e0b74a7d7a6682b22bdd6e7aafb794bce9b24
This commit is contained in:
WMDE-Fisch 2017-07-11 13:51:56 +02:00
parent ada6498b81
commit 553e48e65a
2 changed files with 38 additions and 38 deletions

View file

@ -93,7 +93,7 @@
this.dir = $container.css( 'direction' ) || 'ltr';
if ( this.dir === 'rtl' ) {
this.rtlScrollLeftType = this.determineRtlScrollType();
this.rtlScrollLeftType = mw.libs.revisionSlider.determineRtlScrollType();
}
this.pointerOlder = this.pointerOlder || new mw.libs.revisionSlider.Pointer( 'mw-revslider-pointer-older' );
@ -706,43 +706,6 @@
this.alignPointers( duration );
},
/**
* Based on jQuery RTL Scroll Type Detector plugin by othree: https://github.com/othree/jquery.rtl-scroll-type
*
* @return {string} - 'default', 'negative' or 'reverse'
*/
determineRtlScrollType: function () {
var isChrome = /chrom(e|ium)/.test( navigator.userAgent.toLowerCase() ),
$dummy;
// in Chrome V8 5.8.283 and 5.9.211 the detection below gives wrong results leading to strange behavior
// Chrome V8 6.0 seems to fix that issue so this workaround can be removed then
if ( isChrome ) {
return 'default';
}
$dummy = $( '<div>' )
.css( {
dir: 'rtl',
width: '1px',
height: '1px',
position: 'absolute',
top: '-1000px',
overflow: 'scroll'
} )
.text( 'A' )
.appendTo( 'body' )[ 0 ];
if ( $dummy.scrollLeft > 0 ) {
return 'default';
} else {
$dummy.scrollLeft = 1;
if ( $dummy.scrollLeft === 0 ) {
return 'negative';
}
}
return 'reverse';
},
/**
* @param {jQuery} $element
* @param {number} scrollLeft

View file

@ -77,6 +77,43 @@
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'
*/
mw.libs.revisionSlider.determineRtlScrollType = function () {
var isChrome = /chrom(e|ium)/.test( navigator.userAgent.toLowerCase() ),
$dummy;
// in Chrome V8 5.8.283 and 5.9.211 the detection below gives wrong results leading to strange behavior
// Chrome V8 6.0 seems to fix that issue so this workaround can be removed then
if ( isChrome ) {
return 'default';
}
$dummy = $( '<div>' )
.css( {
dir: 'rtl',
width: '1px',
height: '1px',
position: 'absolute',
top: '-1000px',
overflow: 'scroll'
} )
.text( 'A' )
.appendTo( 'body' )[ 0 ];
if ( $dummy.scrollLeft > 0 ) {
return 'default';
} else {
$dummy.scrollLeft = 1;
if ( $dummy.scrollLeft === 0 ) {
return 'negative';
}
}
return 'reverse';
};
mw.libs.revisionSlider.calculateRevisionsPerWindow = function ( margin, revisionWidth ) {
return Math.floor( ( $( '#mw-content-text' ).width() - margin ) / revisionWidth );
};