The source:
<ul class="supercategory">
<li>
<div class="supcat">
<h4>
<a class="new" href="/header1.html">header 1</a>
</h4>
<ul class="category">
<li><a href="item1.html">Item 1</a></li>
<li><a href="item2.html">Item 2</a></li>
</ul>
</div>
</li>
<li style="" class="">
<div class="supcat">
<h4>
<a class="new" href="/header2.html">Header 2</a>
</h4>
<ul class="category">
<li><a href="item1.html">Item 1</a></li>
<li><a href="item2.html">Item 2</a></li>
</ul>
</div>
</li>
</ul>
<div id="test">
</div>
a lit bit of css:
ul.supercategory { background: lightblue; }
.new{ background: yellow; }
and a jQuery UI force:
$('.supercategory').sortable({
cursor: 'move',
axis: 'y',
revert: true,
stop: function (event, ui) { }
});
I know that to get an object of the current dragged element I simply must to make something this:
stop: function(event, ui) { var obj = ui.item; }
But how to get an object of placed element instead of I dragged to new position?
For example, if I dragged first li on the new position (it will 2nd li) the second li was placed on the place instead of my, how to get this element as object in jQuery UI sortable?
Watch my fiddle: http://jsfiddle.net/Stasonix/jCMuQ/1/
upd 1. First of all a fiddle. http://jsfiddle.net/Stasonix/jCMuQ/5/
Than code:
var is_received = false;
$('.supercategory').sortable({
cursor: 'move',
axis: 'y',
revert: true,
receive: function(event, ui){ is_received = true; },
stop: function (event, ui) {
is_received = true;
},
deactivate: function(event, ui) {
if (is_received){
$('#test').text(ui.item.find('.new').attr('href'));
is_received=false;
}
}
});
Well… still need a solution, it’s not works seems.
You can try this to get the new object you dragged by keeping track of your object’s index / position, and by using the events
startanddeactivatelike this:The thing is,
Make sure to add the class
.mydragto your draggablelielements:I’m not sure if this solution is what you were exactly looking for…
You can ask me question if I was not clear.