4

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?

5

2 Answers 2

5

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

  • 4
    • Thanks @JoDev I would like to let you know that I updated that solution to avoid that the draggable stuf be overlapped from the sortable content when you scroll Commented Jun 13, 2013 at 11:49
    • when i run this code i get this error: TypeError: undefined is not an object (evaluating 'this.overflowOffset.top') Commented Nov 10, 2014 at 17:37
    • yes this code gives the error i mentioned when using jquery-ui-1.11.2 Commented Nov 10, 2014 at 17:58
    • Thats a bug. See bugs.jqueryui.com/ticket/15047 This project solves that for droppables: github.com/maxazan/jquery-ui-droppable-iframe. But it doesn't work for sortables (github.com/maxazan/jquery-ui-droppable-iframe/issues/2) and the author doesn't seem to maintain this project. I think a solution could be similar and one would need to fix something in jQueryUi within sortable.refreshPositions();
      – Sandro
      Commented Sep 21, 2016 at 13:53
    0

    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 } 
    });
    });
    

    Not the answer you're looking for? Browse other questions tagged or ask your own question.