We are currently trying to accomplish cross-frame dragging between draggables and sortables provided by jQuery UI. This is working properly now. However, the mouse offset seems off when dragging from the parent to the child frame--please see this fiddle: http://jsfiddle.net/r5nfe/6/.
Code in the parent:
$('#my-frame').load(function () {
$('.draggable').draggable({
appendTo: 'body',
helper: 'clone',
iframeFix: true,
revert: 'invalid',
connectToSortable: $('#my-frame').contents().find('.sortable'),
cursorAt: { top: 0, left: 0 }
});
$('#my-frame').contents().find('.sortable').sortable({
iframeFix: true,
cursorAt: { top: 0, left: 0 }
});
});
Code in the child frame:
var containers = $('.sortable');
containers.sortable({
connectWith: containers,
cursor: 'move',
revert: true,
cursorAt: { top: 0, left: 0 }
});
Can someone please tell us how to fix the mouse offset?
solution 2 update
I added this js function because when you add too many draggable element to the iframe, the drag elements can be overlapped by the sortable elements if you scroll down
$('.draggable').on('dragstop',autoResize);
function autoResize(){
var newheight;
if(document.getElementById){
newheight=document.getElementById('my-frame').contentWindow.document .body.scrollHeight;
}
newheight=newheight+100;
$('#my-frame').css('height',newheight);
}
here the new jsfiddle
end solution 2 update
This problem appear to be a bug and someone have made his solution ( basically a workaround): trasparent div solution
1
My first solution, without changing the code, could be in placing the iframe before of the draggable stuff, as shown here, the code:
<iframe id="my-frame" src="/VqxGf/3/show"></iframe>
<ul>
<li class="draggable">Drag me</li>
<li class="draggable">Drag me 2</li>
<li class="draggable">Drag me 3</li>
</ul>
2
Another solution that seems to work is to play with the style property: position absolute for the ul in which contain the draggable
s, a bit of margin-top for the sortable stuff in the frame and, maybe, a frameborder=0. jsfiddle
The main page:
<ul style="position:absolute">
<li class="draggable">Drag me</li>
<li class="draggable">Drag me 2</li>
<li class="draggable">Drag me 3</li>
</ul>
<iframe frameborder="0" id="my-frame" src="/ATu6F/30/show"></iframe>
The iframe page:
<ul id="sortable" style="margin-top:100px" class="sortable idle">
<li>Sortable</li>
<li>Sortable 2</li>
<li>Sortable 3</li>
</ul>
<ul id="sortable2" class="sortable idle">
<li>Sortable</li>
<li>Sortable 2</li>
<li>Sortable 3</li>
</ul>
Hope this helps.
Please see the edit at the beginning of this post
I've tried this for my part. But it doesn't work perfectly.
I change the appendTo
with parent.body, and the cursorAt
with 100 on top param.
$('#my-frame').load(function () {
$('.draggable').draggable({
appendTo: 'parent.body',
helper: 'clone',
iframeFix: true,
revert: 'invalid',
connectToSortable: $('#my-frame').contents().find('.sortable'),
cursorAt: { top: 100, left: 0 }
});
$('#my-frame').contents().find('.sortable').sortable({
iframeFix: true,
cursorAt: { top: 0, left: 0 }
});
});