mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Draggable: Removed scrollSpeed/Sensitivity options. Consolidated scrolling code for different scrollParents
This commit is contained in:
parent
da1b946e66
commit
5d029ffab0
91
ui/jquery.ui.draggable.js
vendored
91
ui/jquery.ui.draggable.js
vendored
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* jQuery UI Draggable @VERSION
|
* 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.
|
* Dual licensed under the MIT or GPL Version 2 licenses.
|
||||||
* http://jquery.org/license
|
* http://jquery.org/license
|
||||||
*
|
*
|
||||||
@ -71,53 +71,66 @@ $.widget( "ui.draggable", $.ui.interaction, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
_handleScrolling: function( event ) {
|
_handleScrolling: function( event ) {
|
||||||
var distances = {},
|
var xScrollSpeed, yScrollSpeed,
|
||||||
|
distances = {},
|
||||||
scrollTop = this.scrollParent.scrollTop(),
|
scrollTop = this.scrollParent.scrollTop(),
|
||||||
scrollLeft = this.scrollParent.scrollLeft(),
|
scrollLeft = this.scrollParent.scrollLeft(),
|
||||||
scrollSensitivity = 20,
|
scrollSensitivity = 20,
|
||||||
xScrollSpeed = 20,
|
baseSpeed = 5,
|
||||||
yScrollSpeed = 20;
|
speed = function( distance ) {
|
||||||
|
|
||||||
|
return baseSpeed + Math.round( distance / 2 );
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
// 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
|
|
||||||
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.xRight = ( this.overflow.width + scrollLeft ) - event.pageX;
|
||||||
distances.xLeft = event.pageX - scrollLeft;
|
distances.xLeft = event.pageX - scrollLeft;
|
||||||
|
distances.yBottom = ( this.overflow.height + scrollTop ) - event.pageY;
|
||||||
|
distances.yTop = event.pageY - scrollTop;
|
||||||
|
|
||||||
// Handle horizontal scrolling
|
|
||||||
if ( distances.xRight < scrollSensitivity ) {
|
|
||||||
this.scrollParent.scrollLeft( scrollLeft + xScrollSpeed );
|
|
||||||
}
|
|
||||||
else if ( distances.xLeft < scrollSensitivity ) {
|
|
||||||
this.scrollParent.scrollLeft( scrollLeft - xScrollSpeed );
|
|
||||||
}
|
|
||||||
} else {
|
} 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
|
distances.xRight = ( this.overflow.width + this.overflowOffset.left ) - event.pageX;
|
||||||
if ( ( event.pageX + scrollSensitivity ) > ( this.overflow.width + this.overflowOffset.left ) ) {
|
distances.xLeft = event.pageX - this.overflowOffset.left;
|
||||||
this.scrollParent.scrollLeft( scrollLeft + xScrollSpeed );
|
distances.yBottom = ( this.overflow.height + this.overflowOffset.top ) - event.pageY;
|
||||||
}
|
distances.yTop = event.pageY - this.overflowOffset.top;
|
||||||
else if ( ( event.pageX - scrollSensitivity ) < this.overflowOffset.left ) {
|
|
||||||
this.scrollParent.scrollLeft( scrollLeft - xScrollSpeed );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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 );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_start: function( event ) {
|
_start: function( event ) {
|
||||||
@ -253,13 +266,13 @@ $.widget( "ui.draggable", $.ui.interaction, {
|
|||||||
// Get the difference of automatic coordinates vs what user overrode
|
// Get the difference of automatic coordinates vs what user overrode
|
||||||
oTop = this.position.top - this.tempPosition.top;
|
oTop = this.position.top - this.tempPosition.top;
|
||||||
oLeft = this.position.left - this.tempPosition.left;
|
oLeft = this.position.left - this.tempPosition.left;
|
||||||
|
|
||||||
// Reset offset based on math
|
// Reset offset based on math
|
||||||
this.offset.top = this.offset.top + oTop;
|
this.offset.top = this.offset.top + oTop;
|
||||||
this.offset.left = this.offset.left + oLeft;
|
this.offset.left = this.offset.left + oLeft;
|
||||||
|
|
||||||
this.offset = this.dragEl.offset();
|
this.offset = this.dragEl.offset();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
newLeft = this.position.left;
|
newLeft = this.position.left;
|
||||||
|
Loading…
Reference in New Issue
Block a user