From da1b946e662851ba7d48fe471e44fc9e9277d2ad Mon Sep 17 00:00:00 2001 From: Dave Stein Date: Sun, 27 Nov 2011 17:55:04 -0500 Subject: [PATCH] Droppable: Answered TODO comment about Math.round --- ui/jquery.ui.draggable.js | 50 ++++++++++++++++++++++----------------- ui/jquery.ui.droppable.js | 3 ++- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/ui/jquery.ui.draggable.js b/ui/jquery.ui.draggable.js index b2eae1804..2fdaf0032 100644 --- a/ui/jquery.ui.draggable.js +++ b/ui/jquery.ui.draggable.js @@ -18,10 +18,7 @@ $.widget( "ui.draggable", $.ui.interaction, { widgetEventPrefix: "drag", options: { - helper: null, - // TODO: remove scroll options - scrollSensitivity: 20, - scrollSpeed: 20 + helper: null }, // dragEl: element being dragged (original or helper) @@ -74,42 +71,51 @@ $.widget( "ui.draggable", $.ui.interaction, { }, _handleScrolling: function( event ) { - var scrollTop = this.scrollParent.scrollTop(), - scrollLeft = this.scrollParent.scrollLeft(); + var distances = {}, + scrollTop = this.scrollParent.scrollTop(), + scrollLeft = this.scrollParent.scrollLeft(), + scrollSensitivity = 20, + xScrollSpeed = 20, + yScrollSpeed = 20; // overflowOffset is only set when scrollParent is not doc/html if ( !this.overflowOffset ) { // Handle vertical scrolling - if ( ( ( this.overflow.height + scrollTop ) - event.pageY ) < this.options.scrollSensitivity ) { - this.scrollParent.scrollTop( scrollTop + this.options.scrollSpeed ); + if ( ( ( this.overflow.height + scrollTop ) - event.pageY ) < scrollSensitivity ) { + this.scrollParent.scrollTop( scrollTop + yScrollSpeed ); } - else if ( event.pageY < ( scrollTop + this.options.scrollSensitivity ) ) { - this.scrollParent.scrollTop( scrollTop - this.options.scrollSpeed ); + else if ( event.pageY < ( scrollTop + scrollSensitivity ) ) { + this.scrollParent.scrollTop( scrollTop - yScrollSpeed ); } + + distances.xRight = ( this.overflow.width + scrollLeft ) - event.pageX; + distances.xLeft = event.pageX - scrollLeft; + + // Handle horizontal scrolling - if ( ( ( this.overflow.width + scrollLeft ) - event.pageX ) < this.options.scrollSensitivity ) { - this.scrollParent.scrollLeft( scrollLeft + this.options.scrollSpeed ); + if ( distances.xRight < scrollSensitivity ) { + this.scrollParent.scrollLeft( scrollLeft + xScrollSpeed ); } - else if ( event.pageX < ( scrollLeft + this.options.scrollSensitivity ) ) { - this.scrollParent.scrollLeft( scrollLeft - this.options.scrollSpeed ); + else if ( distances.xLeft < scrollSensitivity ) { + this.scrollParent.scrollLeft( scrollLeft - xScrollSpeed ); } } else { // Handle vertical scrolling - if ( ( event.pageY + this.options.scrollSensitivity ) > ( this.overflow.height + this.overflowOffset.top ) ) { - this.scrollParent.scrollTop( scrollTop + this.options.scrollSpeed ); + if ( ( event.pageY + scrollSensitivity ) > ( this.overflow.height + this.overflowOffset.top ) ) { + this.scrollParent.scrollTop( scrollTop + yScrollSpeed ); } - else if ( ( event.pageY - this.options.scrollSensitivity ) < this.overflowOffset.top ) { - this.scrollParent.scrollTop( scrollTop - this.options.scrollSpeed ); + else if ( ( event.pageY - scrollSensitivity ) < this.overflowOffset.top ) { + this.scrollParent.scrollTop( scrollTop - yScrollSpeed ); } // Handle horizontal scrolling - if ( ( event.pageX + this.options.scrollSensitivity ) > ( this.overflow.width + this.overflowOffset.left ) ) { - this.scrollParent.scrollLeft( scrollLeft + this.options.scrollSpeed ); + if ( ( event.pageX + scrollSensitivity ) > ( this.overflow.width + this.overflowOffset.left ) ) { + this.scrollParent.scrollLeft( scrollLeft + xScrollSpeed ); } - else if ( ( event.pageX - this.options.scrollSensitivity ) < this.overflowOffset.left ) { - this.scrollParent.scrollLeft( scrollLeft - this.options.scrollSpeed ); + else if ( ( event.pageX - scrollSensitivity ) < this.overflowOffset.left ) { + this.scrollParent.scrollLeft( scrollLeft - xScrollSpeed ); } } }, diff --git a/ui/jquery.ui.droppable.js b/ui/jquery.ui.droppable.js index c49e75c8b..202b438d0 100644 --- a/ui/jquery.ui.droppable.js +++ b/ui/jquery.ui.droppable.js @@ -92,7 +92,8 @@ $.widget( "ui.droppable", { _handleIntersect: function( event, edges, ui ) { var xDiff = edges.draggableRight - this.offset.left, 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 ), yHalfway = Math.round( this.proportions.height / 2 ), xOverlap = false,