mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/RevisionSlider
synced 2024-11-15 03:33:45 +00:00
Move scrollType detection to utils
Change-Id: I465e0b74a7d7a6682b22bdd6e7aafb794bce9b24
This commit is contained in:
parent
ada6498b81
commit
553e48e65a
|
@ -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
|
||||
|
|
|
@ -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 );
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue