Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Working with jQuery UI "Accordion and Droppable"

I have a question with jQuery UI Accordion and Droppable. How can I Drag an item from #tab-1 to #tab-2? I have view the demo in jqueryui.com "Sortable - Connect lists with Tabs", but I can't use this for Accordion :(

HTML:

<div id="tabs">
<div id="tabs-1">
    <h3>A</h3>
    <div>
    <ul id="sortable1" class="connectedSortable ui-helper-reset">
        <li class="ui-state-default">Item 1</li>
        <li class="ui-state-default">Item 2</li>
        <li class="ui-state-default">Item 3</li>
        <li class="ui-state-default">Item 4</li>
        <li class="ui-state-default">Item 5</li>
    </ul>
    </div>
</div>
<div id="tabs-2">
    <h3>B</h3>
    <div>
    <ul id="sortable2" class="connectedSortable ui-helper-reset">
        <li class="ui-state-highlight">Item 1</li>
        <li class="ui-state-highlight">Item 2</li>
        <li class="ui-state-highlight">Item 3</li>
        <li class="ui-state-highlight">Item 4</li>
        <li class="ui-state-highlight">Item 5</li>
    </ul>
    </div>
</div>

Script:

$(function() {
    $( "#sortable1, #sortable2" ).sortable().disableSelection();

    var $tabs = $( "#tabs" ).accordion({
        heightStyle: "content",
        collapsible: true,
        header: "> div > h3",
        beforeActivate: function( event, ui ) {
            $("#maps").width( $("#tabsMap").innerWidth() - $("#mapList").width() - 34 );
        },
        activate: function( event, ui ) {
            $("#maps").width( $("#tabsMap").innerWidth() - $("#mapList").width() - 32 );
        }
    }).sortable({
        axis: "y",
        handle: "h3",
        stop: function( event, ui ) {
            ui.item.children( "h3" ).triggerHandler( "focusout" );
        }
    });
});
like image 345
Pun Pun M Avatar asked Jun 18 '13 09:06

Pun Pun M


1 Answers

You can connect the lists by changing the line:

$( "#sortable1, #sortable2" ).sortable().disableSelection();

To:

$( "#sortable1, #sortable2").sortable({connectWith['.connectedSortable']}).disableSelection();

But then you have the issue how to get the other one open to drop it into the other list.

If you add event: "mouseover" as an accordian option it won't trigger the mouseover while you're still dragging.

To achieve multiple panels open at once, you need a rather unsightly workaround, but hey, it works!:

http://jsfiddle.net/ZjvWN/2/

Credit for the beforeActivate function to the member Boaz from this answer: jQuery UI accordion: open multiple panels at once

like image 197
Matt Harrison Avatar answered Nov 11 '22 04:11

Matt Harrison