Droppable: Answered TODO comment about Math.round

This commit is contained in:
Dave Stein 2011-11-27 17:55:04 -05:00
parent 2799b4a67f
commit da1b946e66
2 changed files with 30 additions and 23 deletions

View File

@ -18,10 +18,7 @@ $.widget( "ui.draggable", $.ui.interaction, {
widgetEventPrefix: "drag", widgetEventPrefix: "drag",
options: { options: {
helper: null, helper: null
// TODO: remove scroll options
scrollSensitivity: 20,
scrollSpeed: 20
}, },
// dragEl: element being dragged (original or helper) // dragEl: element being dragged (original or helper)
@ -74,42 +71,51 @@ $.widget( "ui.draggable", $.ui.interaction, {
}, },
_handleScrolling: function( event ) { _handleScrolling: function( event ) {
var scrollTop = this.scrollParent.scrollTop(), var distances = {},
scrollLeft = this.scrollParent.scrollLeft(); scrollTop = this.scrollParent.scrollTop(),
scrollLeft = this.scrollParent.scrollLeft(),
scrollSensitivity = 20,
xScrollSpeed = 20,
yScrollSpeed = 20;
// overflowOffset is only set when scrollParent is not doc/html // overflowOffset is only set when scrollParent is not doc/html
if ( !this.overflowOffset ) { if ( !this.overflowOffset ) {
// Handle vertical scrolling // Handle vertical scrolling
if ( ( ( this.overflow.height + scrollTop ) - event.pageY ) < this.options.scrollSensitivity ) { if ( ( ( this.overflow.height + scrollTop ) - event.pageY ) < scrollSensitivity ) {
this.scrollParent.scrollTop( scrollTop + this.options.scrollSpeed ); this.scrollParent.scrollTop( scrollTop + yScrollSpeed );
} }
else if ( event.pageY < ( scrollTop + this.options.scrollSensitivity ) ) { else if ( event.pageY < ( scrollTop + scrollSensitivity ) ) {
this.scrollParent.scrollTop( scrollTop - this.options.scrollSpeed ); this.scrollParent.scrollTop( scrollTop - yScrollSpeed );
} }
distances.xRight = ( this.overflow.width + scrollLeft ) - event.pageX;
distances.xLeft = event.pageX - scrollLeft;
// Handle horizontal scrolling // Handle horizontal scrolling
if ( ( ( this.overflow.width + scrollLeft ) - event.pageX ) < this.options.scrollSensitivity ) { if ( distances.xRight < scrollSensitivity ) {
this.scrollParent.scrollLeft( scrollLeft + this.options.scrollSpeed ); this.scrollParent.scrollLeft( scrollLeft + xScrollSpeed );
} }
else if ( event.pageX < ( scrollLeft + this.options.scrollSensitivity ) ) { else if ( distances.xLeft < scrollSensitivity ) {
this.scrollParent.scrollLeft( scrollLeft - this.options.scrollSpeed ); this.scrollParent.scrollLeft( scrollLeft - xScrollSpeed );
} }
} else { } else {
// Handle vertical scrolling // Handle vertical scrolling
if ( ( event.pageY + this.options.scrollSensitivity ) > ( this.overflow.height + this.overflowOffset.top ) ) { if ( ( event.pageY + scrollSensitivity ) > ( this.overflow.height + this.overflowOffset.top ) ) {
this.scrollParent.scrollTop( scrollTop + this.options.scrollSpeed ); this.scrollParent.scrollTop( scrollTop + yScrollSpeed );
} }
else if ( ( event.pageY - this.options.scrollSensitivity ) < this.overflowOffset.top ) { else if ( ( event.pageY - scrollSensitivity ) < this.overflowOffset.top ) {
this.scrollParent.scrollTop( scrollTop - this.options.scrollSpeed ); this.scrollParent.scrollTop( scrollTop - yScrollSpeed );
} }
// Handle horizontal scrolling // Handle horizontal scrolling
if ( ( event.pageX + this.options.scrollSensitivity ) > ( this.overflow.width + this.overflowOffset.left ) ) { if ( ( event.pageX + scrollSensitivity ) > ( this.overflow.width + this.overflowOffset.left ) ) {
this.scrollParent.scrollLeft( scrollLeft + this.options.scrollSpeed ); this.scrollParent.scrollLeft( scrollLeft + xScrollSpeed );
} }
else if ( ( event.pageX - this.options.scrollSensitivity ) < this.overflowOffset.left ) { else if ( ( event.pageX - scrollSensitivity ) < this.overflowOffset.left ) {
this.scrollParent.scrollLeft( scrollLeft - this.options.scrollSpeed ); this.scrollParent.scrollLeft( scrollLeft - xScrollSpeed );
} }
} }
}, },

View File

@ -92,7 +92,8 @@ $.widget( "ui.droppable", {
_handleIntersect: function( event, edges, ui ) { _handleIntersect: function( event, edges, ui ) {
var xDiff = edges.draggableRight - this.offset.left, var xDiff = edges.draggableRight - this.offset.left,
yDiff = edges.draggableBottom - this.offset.top, yDiff = edges.draggableBottom - this.offset.top,
// TODO: is there really any need to round here?
// Round to normalize between browsers since some handle non-integer values
xHalfway = Math.round( this.proportions.width / 2 ), xHalfway = Math.round( this.proportions.width / 2 ),
yHalfway = Math.round( this.proportions.height / 2 ), yHalfway = Math.round( this.proportions.height / 2 ),
xOverlap = false, xOverlap = false,