Skip to content

Commit fa460f3

Browse files
marcuswarrencascottgonzalez
authored andcommitted
Sortable: Add support for iframes
Fixes #9604 Closes jquerygh-1443 (cherry picked from commit 17c7f69)
1 parent 0a0db09 commit fa460f3

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

ui/sortable.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ return $.widget("ui.sortable", $.ui.mouse, {
276276
}
277277

278278
//Prepare scrolling
279-
if(this.scrollParent[0] !== document && this.scrollParent[0].tagName !== "HTML") {
279+
if(this.scrollParent[0] !== this.document[0] && this.scrollParent[0].tagName !== "HTML") {
280280
this.overflowOffset = this.scrollParent.offset();
281281
}
282282

@@ -328,7 +328,7 @@ return $.widget("ui.sortable", $.ui.mouse, {
328328

329329
//Do scrolling
330330
if(this.options.scroll) {
331-
if(this.scrollParent[0] !== document && this.scrollParent[0].tagName !== "HTML") {
331+
if(this.scrollParent[0] !== this.document[0] && this.scrollParent[0].tagName !== "HTML") {
332332

333333
if((this.overflowOffset.top + this.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity) {
334334
this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop + o.scrollSpeed;
@@ -344,16 +344,16 @@ return $.widget("ui.sortable", $.ui.mouse, {
344344

345345
} else {
346346

347-
if(event.pageY - $(document).scrollTop() < o.scrollSensitivity) {
348-
scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed);
349-
} else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity) {
350-
scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed);
347+
if(event.pageY - this.document.scrollTop() < o.scrollSensitivity) {
348+
scrolled = this.document.scrollTop(this.document.scrollTop() - o.scrollSpeed);
349+
} else if(this.window.height() - (event.pageY - this.document.scrollTop()) < o.scrollSensitivity) {
350+
scrolled = this.document.scrollTop(this.document.scrollTop() + o.scrollSpeed);
351351
}
352352

353-
if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity) {
354-
scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed);
355-
} else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity) {
356-
scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed);
353+
if(event.pageX - this.document.scrollLeft() < o.scrollSensitivity) {
354+
scrolled = this.document.scrollLeft(this.document.scrollLeft() - o.scrollSpeed);
355+
} else if(this.window.width() - (event.pageX - this.document.scrollLeft()) < o.scrollSensitivity) {
356+
scrolled = this.document.scrollLeft(this.document.scrollLeft() + o.scrollSpeed);
357357
}
358358

359359
}
@@ -452,10 +452,10 @@ return $.widget("ui.sortable", $.ui.mouse, {
452452
animation = {};
453453

454454
if ( !axis || axis === "x" ) {
455-
animation.left = cur.left - this.offset.parent.left - this.margins.left + (this.offsetParent[0] === document.body ? 0 : this.offsetParent[0].scrollLeft);
455+
animation.left = cur.left - this.offset.parent.left - this.margins.left + (this.offsetParent[0] === this.document[0].body ? 0 : this.offsetParent[0].scrollLeft);
456456
}
457457
if ( !axis || axis === "y" ) {
458-
animation.top = cur.top - this.offset.parent.top - this.margins.top + (this.offsetParent[0] === document.body ? 0 : this.offsetParent[0].scrollTop);
458+
animation.top = cur.top - this.offset.parent.top - this.margins.top + (this.offsetParent[0] === this.document[0].body ? 0 : this.offsetParent[0].scrollTop);
459459
}
460460
this.reverting = true;
461461
$(this.helper).animate( animation, parseInt(this.options.revert, 10) || 500, function() {
@@ -648,7 +648,7 @@ return $.widget("ui.sortable", $.ui.mouse, {
648648

649649
if(connectWith && connected) {
650650
for (i = connectWith.length - 1; i >= 0; i--){
651-
cur = $(connectWith[i]);
651+
cur = $(connectWith[i], this.document[0]);
652652
for ( j = cur.length - 1; j >= 0; j--){
653653
inst = $.data(cur[j], this.widgetFullName);
654654
if(inst && inst !== this && !inst.options.disabled) {
@@ -698,7 +698,7 @@ return $.widget("ui.sortable", $.ui.mouse, {
698698

699699
if(connectWith && this.ready) { //Shouldn't be run the first time through due to massive slow-down
700700
for (i = connectWith.length - 1; i >= 0; i--){
701-
cur = $(connectWith[i]);
701+
cur = $(connectWith[i], this.document[0]);
702702
for (j = cur.length - 1; j >= 0; j--){
703703
inst = $.data(cur[j], this.widgetFullName);
704704
if(inst && inst !== this && !inst.options.disabled) {
@@ -990,14 +990,14 @@ return $.widget("ui.sortable", $.ui.mouse, {
990990
// 1. The position of the helper is absolute, so it's position is calculated based on the next positioned parent
991991
// 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't the document, which means that
992992
// the scroll is included in the initial calculation of the offset of the parent, and never recalculated upon drag
993-
if(this.cssPosition === "absolute" && this.scrollParent[0] !== document && $.contains(this.scrollParent[0], this.offsetParent[0])) {
993+
if(this.cssPosition === "absolute" && this.scrollParent[0] !== this.document[0] && $.contains(this.scrollParent[0], this.offsetParent[0])) {
994994
po.left += this.scrollParent.scrollLeft();
995995
po.top += this.scrollParent.scrollTop();
996996
}
997997

998998
// This needs to be actually done for all browsers, since pageX/pageY includes this information
999999
// with an ugly IE fix
1000-
if( this.offsetParent[0] === document.body || (this.offsetParent[0].tagName && this.offsetParent[0].tagName.toLowerCase() === "html" && $.ui.ie)) {
1000+
if( this.offsetParent[0] === this.document[0].body || (this.offsetParent[0].tagName && this.offsetParent[0].tagName.toLowerCase() === "html" && $.ui.ie)) {
10011001
po = { top: 0, left: 0 };
10021002
}
10031003

@@ -1047,8 +1047,8 @@ return $.widget("ui.sortable", $.ui.mouse, {
10471047
this.containment = [
10481048
0 - this.offset.relative.left - this.offset.parent.left,
10491049
0 - this.offset.relative.top - this.offset.parent.top,
1050-
$(o.containment === "document" ? document : window).width() - this.helperProportions.width - this.margins.left,
1051-
($(o.containment === "document" ? document : window).height() || document.body.parentNode.scrollHeight) - this.helperProportions.height - this.margins.top
1050+
o.containment === "document" ? this.document.width() : this.window.width() - this.helperProportions.width - this.margins.left,
1051+
(o.containment === "document" ? this.document.width() : this.window.height() || this.document[0].body.parentNode.scrollHeight) - this.helperProportions.height - this.margins.top
10521052
];
10531053
}
10541054

@@ -1073,7 +1073,7 @@ return $.widget("ui.sortable", $.ui.mouse, {
10731073
pos = this.position;
10741074
}
10751075
var mod = d === "absolute" ? 1 : -1,
1076-
scroll = this.cssPosition === "absolute" && !(this.scrollParent[0] !== document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent,
1076+
scroll = this.cssPosition === "absolute" && !(this.scrollParent[0] !== this.document[0] && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent,
10771077
scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
10781078

10791079
return {
@@ -1099,13 +1099,13 @@ return $.widget("ui.sortable", $.ui.mouse, {
10991099
o = this.options,
11001100
pageX = event.pageX,
11011101
pageY = event.pageY,
1102-
scroll = this.cssPosition === "absolute" && !(this.scrollParent[0] !== document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
1102+
scroll = this.cssPosition === "absolute" && !(this.scrollParent[0] !== this.document[0] && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
11031103

11041104
// This is another very weird special case that only happens for relative elements:
11051105
// 1. If the css position is relative
11061106
// 2. and the scroll parent is the document or similar to the offset parent
11071107
// we have to refresh the relative offset during the scroll so there are no jumps
1108-
if(this.cssPosition === "relative" && !(this.scrollParent[0] !== document && this.scrollParent[0] !== this.offsetParent[0])) {
1108+
if(this.cssPosition === "relative" && !(this.scrollParent[0] !== this.document[0] && this.scrollParent[0] !== this.offsetParent[0])) {
11091109
this.offset.relative = this._getRelativeOffset();
11101110
}
11111111

0 commit comments

Comments
 (0)