Draggable: Removed scrollSpeed/Sensitivity options. Consolidated scrolling code for different scrollParents

This commit is contained in:
Dave Stein 2011-11-27 18:32:34 -05:00
parent da1b946e66
commit 5d029ffab0

View File

@ -1,7 +1,7 @@
/*
* jQuery UI Draggable @VERSION
*
* Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
* CopyBottom 2011, AUTHORS.txt (http://jqueryui.com/about)
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*
@ -71,53 +71,66 @@ $.widget( "ui.draggable", $.ui.interaction, {
},
_handleScrolling: function( event ) {
var distances = {},
var xScrollSpeed, yScrollSpeed,
distances = {},
scrollTop = this.scrollParent.scrollTop(),
scrollLeft = this.scrollParent.scrollLeft(),
scrollSensitivity = 20,
xScrollSpeed = 20,
yScrollSpeed = 20;
baseSpeed = 5,
speed = function( distance ) {
return baseSpeed + Math.round( distance / 2 );
};
// overflowOffset is only set when scrollParent is not doc/html
if ( !this.overflowOffset ) {
// Handle vertical scrolling
if ( ( ( this.overflow.height + scrollTop ) - event.pageY ) < scrollSensitivity ) {
this.scrollParent.scrollTop( scrollTop + yScrollSpeed );
}
else if ( event.pageY < ( scrollTop + scrollSensitivity ) ) {
this.scrollParent.scrollTop( scrollTop - yScrollSpeed );
}
distances.xRight = ( this.overflow.width + scrollLeft ) - event.pageX;
distances.xLeft = event.pageX - scrollLeft;
distances.yBottom = ( this.overflow.height + scrollTop ) - event.pageY;
distances.yTop = event.pageY - scrollTop;
} else {
distances.xRight = ( this.overflow.width + this.overflowOffset.left ) - event.pageX;
distances.xLeft = event.pageX - this.overflowOffset.left;
distances.yBottom = ( this.overflow.height + this.overflowOffset.top ) - event.pageY;
distances.yTop = event.pageY - this.overflowOffset.top;
}
// Handle vertical scrolling
if ( distances.yBottom < scrollSensitivity ) {
yScrollSpeed = speed( scrollSensitivity - distances.yBottom );
this.scrollParent.scrollTop( scrollTop + yScrollSpeed );
}
else if ( distances.yTop < scrollSensitivity ) {
yScrollSpeed = speed( scrollSensitivity - distances.yTop );
this.scrollParent.scrollTop( scrollTop - yScrollSpeed );
}
// Handle horizontal scrolling
if ( distances.xRight < scrollSensitivity ) {
xScrollSpeed = speed( scrollSensitivity - distances.xRight );
this.scrollParent.scrollLeft( scrollLeft + xScrollSpeed );
}
else if ( distances.xLeft < scrollSensitivity ) {
xScrollSpeed = speed( scrollSensitivity - distances.xLeft );
this.scrollParent.scrollLeft( scrollLeft - xScrollSpeed );
}
} else {
// Handle vertical scrolling
if ( ( event.pageY + scrollSensitivity ) > ( this.overflow.height + this.overflowOffset.top ) ) {
this.scrollParent.scrollTop( scrollTop + yScrollSpeed );
}
else if ( ( event.pageY - scrollSensitivity ) < this.overflowOffset.top ) {
this.scrollParent.scrollTop( scrollTop - yScrollSpeed );
}
// Handle horizontal scrolling
if ( ( event.pageX + scrollSensitivity ) > ( this.overflow.width + this.overflowOffset.left ) ) {
this.scrollParent.scrollLeft( scrollLeft + xScrollSpeed );
}
else if ( ( event.pageX - scrollSensitivity ) < this.overflowOffset.left ) {
this.scrollParent.scrollLeft( scrollLeft - xScrollSpeed );
}
}
},
_start: function( event ) {