mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Droppable: Answered TODO comment about Math.round
This commit is contained in:
parent
2799b4a67f
commit
da1b946e66
50
ui/jquery.ui.draggable.js
vendored
50
ui/jquery.ui.draggable.js
vendored
@ -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 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
3
ui/jquery.ui.droppable.js
vendored
3
ui/jquery.ui.droppable.js
vendored
@ -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,
|
||||||
|
Loading…
Reference in New Issue
Block a user