I am working on a page that will allow Drag n Drop listview items from one div to another.
I have done moving an item from one to another, but I got stuck in moving an item within a div (i.e. changing position of the item)
The jquery code is shown below:
$("#taskAssigned").droppable({
accept: "#wrapper_taskOpen li, #wrapper_taskAssigned li",
drop: function(event, ui) {
// accepts items from taskOpen
if (ui.draggable.parent().parent().parent().attr("id") == "taskOpen") {
ui.draggable.detach().appendTo($("#taskassignlist")).removeAttr("style").attr("style", "position:relative;");
var linkOffset = ui.draggable.find("a").offset();
ui.draggable.find("a").removeAttr("style").css({left:event.pageX - linkOffset.left, top:event.pageY - linkOffset.top});
}
// accept internal drops (change position of the stickynote)
else if (ui.draggable.parent().parent().parent().attr("id") == "taskAssigned") {
ui.draggable.detach().appendTo($("#taskassignlist")).removeAttr("style").attr("style", "position:relative;");
var linkOffset = ui.draggable.find("a").offset();
ui.draggable.find("a").removeAttr("style").css({left:event.pageX - linkOffset.left, top:event.pageY - linkOffset.top});
}
}
});
HTML code:
<div id="taskOpen">
<div data-role="header" data-theme="e">
<h5>Open Tasks</h5>
</div>
<div id="wrapper_taskOpen">
<ul id="taskopenlist" class="stickynote">
<li id="draggable">
<a href="#" id="pos">
<h3>Title #2</h3>
<p>Text Content #2</p>
</a>
</li>
<li id="draggable">
<a href="#" id="pos1">
<h3>Title #3</h3>
<p>Text Content #3</p>
</a>
</li>
</ul>
</div>
</div>
<div id="taskAssigned">
<div data-role="header" data-theme="e">
<h5>Assigned Tasks</h5>
</div>
<div id="wrapper_taskAssigned">
<ul id="taskassignlist" class="stickynote">
</ul>
</div>
</div>
<div id="taskClosed">
<div data-role="header" data-theme="e">
<h5>Closed Tasks</h5>
</div>
<div id="wrapper_taskClosed">
<ul id="taskcloselist" class="stickynote">
</ul>
</div>
</div>
I created a JSFiddle to demonstrate the problem I have http://jsfiddle.net/lightbringer/SDF4m/
I can move an item from Open Task to Assigned Task (changing position to the position of mouse pointer) I would like to be able to move the tasks in Assigned Task to a different location within that div. However, my code seems to be inaccurate in determining the position, and sometimes it does not capture the droppable event.
If someone could help me on this one I would be very grateful.
Thanks in advance.