Skip to content

Commit a240251

Browse files
bleshikjzaefferer
authored andcommitted
Selectable: Proper handling of inner scrolling
Fixes #13359 Closes jquerygh-1570
1 parent 2e77015 commit a240251

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

ui/widgets/selectable.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,16 @@ return $.widget( "ui.selectable", $.ui.mouse, {
5757

5858
// Cache selectee children based on filter
5959
this.refresh = function() {
60+
that.elementPos = $( that.element[ 0 ] ).offset();
6061
that.selectees = $( that.options.filter, that.element[ 0 ] );
6162
that._addClass( that.selectees, "ui-selectee" );
6263
that.selectees.each( function() {
6364
var $this = $( this ),
64-
pos = $this.offset();
65+
selecteeOffset = $this.offset(),
66+
pos = {
67+
left: selecteeOffset.left - that.elementPos.left,
68+
top: selecteeOffset.top - that.elementPos.top
69+
};
6570
$.data( this, "selectable-item", {
6671
element: this,
6772
$element: $this,
@@ -94,6 +99,7 @@ return $.widget( "ui.selectable", $.ui.mouse, {
9499
options = this.options;
95100

96101
this.opos = [ event.pageX, event.pageY ];
102+
this.elementPos = $( this.element[ 0 ] ).offset();
97103

98104
if ( this.options.disabled ) {
99105
return;
@@ -183,19 +189,25 @@ return $.widget( "ui.selectable", $.ui.mouse, {
183189

184190
this.selectees.each( function() {
185191
var selectee = $.data( this, "selectable-item" ),
186-
hit = false;
192+
hit = false,
193+
offset = {};
187194

188195
//prevent helper from being selected if appendTo: selectable
189196
if ( !selectee || selectee.element === that.element[ 0 ] ) {
190197
return;
191198
}
192199

200+
offset.left = selectee.left + that.elementPos.left;
201+
offset.right = selectee.right + that.elementPos.left;
202+
offset.top = selectee.top + that.elementPos.top;
203+
offset.bottom = selectee.bottom + that.elementPos.top;
204+
193205
if ( options.tolerance === "touch" ) {
194-
hit = ( !( selectee.left > x2 || selectee.right < x1 || selectee.top > y2 ||
195-
selectee.bottom < y1 ) );
206+
hit = ( !( offset.left > x2 || offset.right < x1 || offset.top > y2 ||
207+
offset.bottom < y1 ) );
196208
} else if ( options.tolerance === "fit" ) {
197-
hit = ( selectee.left > x1 && selectee.right < x2 && selectee.top > y1 &&
198-
selectee.bottom < y2 );
209+
hit = ( offset.left > x1 && offset.right < x2 && offset.top > y1 &&
210+
offset.bottom < y2 );
199211
}
200212

201213
if ( hit ) {

0 commit comments

Comments
 (0)