Hi peeps,
Little help need with jquery sortable.
I have a nested list like so:
<div id="tree">
<ul>
<li class="n-1">root
<ul>
<li class="n-2">Academic
<ul>
<li class="n-5">Staff</li>
<li class="n-6">Courses</li>
</ul>
</li>
<li class="n-3">Administration</li>
<li class="n-4">Technical
<ul>
<li class="n-6">Courses</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
and an associated list:
<div id="orphans">
<ul>
<li class="n-47">a</li>
<li class="n-48">b</li>
<li class="n-49">c</li>
<li class="n-50">d</li>
</ul>
</div>
What I need is to create an unordered list when dragging a LI so that when hovering over a li in the target list with no child list that new list is created - and remove it when leaving if the item was not dropped into that list.
Quickest soln would be to get the current element being hovered over but having a spot of bother catching that with sortable.
here is what I have so far:
$('#tree ul li li , #orphans ul li')
.addClass('closed')
.live('click',function(){
$(this).toggleClass( 'open closed');
});
$('#tree ul ul')
.sortable({
items: 'li',
connectWith: '#tree ul ul',
cursor: 'crosshair',
helper: 'clone',
zIndex: 999,
placeholder: 'sort-highlight',
opacity: '0.6',
over: function(event,ui)
{
$(this).children('li.closed').toggleClass( 'open closed');
$(this).children('li:not(:has(ul)').append('<ul><li class="dummy">DADADA</li></ul>');
},
out: function(event,ui)
{
$('li.dummy').remove();
$('ul:empty').remove();
}
})
.disableSelection();
$('#orphans ul')
.sortable({
items: 'li',
connectWith : '#tree ul',
cursor: 'crosshair',
helper: 'clone',
zIndex: 999,
placeholder: 'sort-highlight',
opacity: '0.6'
})
.disableSelection();
any help very much appreciated.