Skip to content

Commit c7bec85

Browse files
committed
Draggable: append divs to iframe parent for iframefix
This allows the blocking div to move with the iframe in most situations, whereas appending to the body wouldn't. Fixes #9671
1 parent df7e32f commit c7bec85

File tree

2 files changed

+64
-13
lines changed

2 files changed

+64
-13
lines changed

tests/unit/draggable/draggable_options.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,4 +1334,46 @@ test( "zIndex, default, switching after initialization", function() {
13341334

13351335
});
13361336

1337+
test( "iframeFix", function() {
1338+
expect( 5 );
1339+
1340+
var element = $( "<div>" ).appendTo( "#qunit-fixture" ).draggable({ iframeFix: true }),
1341+
element2 = $( "<div>" ).appendTo( "#qunit-fixture" ).draggable({ iframeFix: ".iframe" }),
1342+
iframe = $( "<iframe>" ).appendTo( element );
1343+
1344+
element2
1345+
.append( "<iframe class='iframe'></iframe>" )
1346+
.append( "<iframe>" );
1347+
1348+
iframe.css({
1349+
width: 1,
1350+
height: 1
1351+
});
1352+
1353+
element.one( "drag", function() {
1354+
var div = $( this ).children().not( "iframe" );
1355+
// http://bugs.jqueryui.com/ticket/9671
1356+
// iframeFix doesn't handle iframes that move
1357+
equal( div.length, 1, "blocking div added as sibling" );
1358+
equal( div.outerWidth(), iframe.outerWidth(), "blocking div is wide enough" );
1359+
equal( div.outerHeight(), iframe.outerHeight(), "blocking div is tall enough" );
1360+
deepEqual( div.offset(), iframe.offset(), "blocking div is tall enough" );
1361+
});
1362+
1363+
element.simulate( "drag", {
1364+
dx: 1,
1365+
dy: 1
1366+
});
1367+
1368+
element2.one( "drag", function() {
1369+
var div = $( this ).children().not( "iframe" );
1370+
equal( div.length, 1, "blocking div added as sibling only to matching selector" );
1371+
});
1372+
1373+
element2.simulate( "drag", {
1374+
dx: 1,
1375+
dy: 1
1376+
});
1377+
});
1378+
13371379
})( jQuery );

ui/draggable.js

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,20 +109,32 @@ $.widget("ui.draggable", $.ui.mouse, {
109109
return false;
110110
}
111111

112-
$(o.iframeFix === true ? "iframe" : o.iframeFix).each(function() {
113-
$("<div class='ui-draggable-iframeFix' style='background: #fff;'></div>")
114-
.css({
115-
width: this.offsetWidth + "px", height: this.offsetHeight + "px",
116-
position: "absolute", opacity: "0.001", zIndex: 1000
117-
})
118-
.css($(this).offset())
119-
.appendTo("body");
120-
});
112+
this._blockFrames( o.iframeFix === true ? "iframe" : o.iframeFix );
121113

122114
return true;
123115

124116
},
125117

118+
_blockFrames: function( selector ) {
119+
this.iframeBlocks = this.document.find( selector ).map(function() {
120+
var iframe = $( this );
121+
122+
return $( "<div>" )
123+
.css( "position", "absolute" )
124+
.appendTo( iframe.parent() )
125+
.outerWidth( iframe.outerWidth() )
126+
.outerHeight( iframe.outerHeight() )
127+
.offset( iframe.offset() )[ 0 ];
128+
});
129+
},
130+
131+
_unblockFrames: function() {
132+
if ( this.iframeBlocks ) {
133+
this.iframeBlocks.remove();
134+
delete this.iframeBlocks;
135+
}
136+
},
137+
126138
_blurActiveElement: function( event ) {
127139
var document = this.document[ 0 ];
128140

@@ -297,10 +309,7 @@ $.widget("ui.draggable", $.ui.mouse, {
297309
},
298310

299311
_mouseUp: function( event ) {
300-
//Remove frame helpers
301-
$("div.ui-draggable-iframeFix").each(function() {
302-
this.parentNode.removeChild(this);
303-
});
312+
this._unblockFrames();
304313

305314
//If the ddmanager is used for droppables, inform the manager that dragging has stopped (see #5003)
306315
if ( $.ui.ddmanager ) {

0 commit comments

Comments
 (0)