Skip to content

Commit c11cad4

Browse files
briangrinstead@gmail.combriangrinstead@gmail.com
authored andcommitted
Updated references to "document" to the "ownerDocument" to allow dragging of element inside iframe, fixes #5727 (Draggable: cannot drag element inside iframe)
1 parent eb13c01 commit c11cad4

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

ui/jquery.ui.core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ $.fn.extend({
153153
}).eq(0);
154154
}
155155

156-
return (/fixed/).test(this.css('position')) || !scrollParent.length ? $(document) : scrollParent;
156+
return (/fixed/).test(this.css('position')) || !scrollParent.length ? $(this[0].ownerDocument || document) : scrollParent;
157157
},
158158

159159
zIndex: function(zIndex) {

ui/jquery.ui.draggable.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,12 @@ $.widget("ui.draggable", $.ui.mouse, {
284284
// 1. The position of the helper is absolute, so it's position is calculated based on the next positioned parent
285285
// 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't the document, which means that
286286
// the scroll is included in the initial calculation of the offset of the parent, and never recalculated upon drag
287-
if(this.cssPosition == 'absolute' && this.scrollParent[0] != document && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) {
287+
if(this.cssPosition == 'absolute' && this.scrollParent[0] != this.element[0].ownerDocument && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) {
288288
po.left += this.scrollParent.scrollLeft();
289289
po.top += this.scrollParent.scrollTop();
290290
}
291291

292-
if((this.offsetParent[0] == document.body) //This needs to be actually done for all browsers, since pageX/pageY includes this information
292+
if((this.offsetParent[0] == this.element[0].ownerDocument.body) //This needs to be actually done for all browsers, since pageX/pageY includes this information
293293
|| (this.offsetParent[0].tagName && this.offsetParent[0].tagName.toLowerCase() == 'html' && $.browser.msie)) //Ugly IE fix
294294
po = { top: 0, left: 0 };
295295

@@ -360,7 +360,7 @@ $.widget("ui.draggable", $.ui.mouse, {
360360

361361
if(!pos) pos = this.position;
362362
var mod = d == "absolute" ? 1 : -1;
363-
var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
363+
var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != this.element[0].ownerDocument && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
364364

365365
return {
366366
top: (
@@ -381,7 +381,7 @@ $.widget("ui.draggable", $.ui.mouse, {
381381

382382
_generatePosition: function(event) {
383383

384-
var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
384+
var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != this.element[0].ownerDocument && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
385385
var pageX = event.pageX;
386386
var pageY = event.pageY;
387387

@@ -647,13 +647,13 @@ $.ui.plugin.add("draggable", "opacity", {
647647
$.ui.plugin.add("draggable", "scroll", {
648648
start: function(event, ui) {
649649
var i = $(this).data("draggable");
650-
if(i.scrollParent[0] != document && i.scrollParent[0].tagName != 'HTML') i.overflowOffset = i.scrollParent.offset();
650+
if(i.scrollParent[0] != i.element[0].ownerDocument && i.scrollParent[0].tagName != 'HTML') i.overflowOffset = i.scrollParent.offset();
651651
},
652652
drag: function(event, ui) {
653653

654-
var i = $(this).data("draggable"), o = i.options, scrolled = false;
654+
var i = $(this).data("draggable"), o = i.options, scrolled = false, doc = i.element[0].ownerDocument;
655655

656-
if(i.scrollParent[0] != document && i.scrollParent[0].tagName != 'HTML') {
656+
if(i.scrollParent[0] != doc && i.scrollParent[0].tagName != 'HTML') {
657657

658658
if(!o.axis || o.axis != 'x') {
659659
if((i.overflowOffset.top + i.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity)
@@ -672,17 +672,17 @@ $.ui.plugin.add("draggable", "scroll", {
672672
} else {
673673

674674
if(!o.axis || o.axis != 'x') {
675-
if(event.pageY - $(document).scrollTop() < o.scrollSensitivity)
676-
scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed);
677-
else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity)
678-
scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed);
675+
if(event.pageY - $(doc).scrollTop() < o.scrollSensitivity)
676+
scrolled = $(doc).scrollTop($(doc).scrollTop() - o.scrollSpeed);
677+
else if($(window).height() - (event.pageY - $(doc).scrollTop()) < o.scrollSensitivity)
678+
scrolled = $(doc).scrollTop($(doc).scrollTop() + o.scrollSpeed);
679679
}
680680

681681
if(!o.axis || o.axis != 'y') {
682-
if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity)
683-
scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed);
684-
else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity)
685-
scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed);
682+
if(event.pageX - $(doc).scrollLeft() < o.scrollSensitivity)
683+
scrolled = $(doc).scrollLeft($(doc).scrollLeft() - o.scrollSpeed);
684+
else if($(window).width() - (event.pageX - $(doc).scrollLeft()) < o.scrollSensitivity)
685+
scrolled = $(doc).scrollLeft($(doc).scrollLeft() + o.scrollSpeed);
686686
}
687687

688688
}

ui/jquery.ui.mouse.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ $.widget("ui.mouse", {
8282
this._mouseUpDelegate = function(event) {
8383
return self._mouseUp(event);
8484
};
85-
$(document)
85+
$(event.target.ownerDocument)
8686
.bind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
8787
.bind('mouseup.'+this.widgetName, this._mouseUpDelegate);
8888

@@ -116,7 +116,7 @@ $.widget("ui.mouse", {
116116
},
117117

118118
_mouseUp: function(event) {
119-
$(document)
119+
$(event.target.ownerDocument)
120120
.unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
121121
.unbind('mouseup.'+this.widgetName, this._mouseUpDelegate);
122122

0 commit comments

Comments
 (0)