Problem I'm facing is the position of Cursor and Element during drag, it works fine in most of the operation but failed on one case where I add new row on droppable over function. jsFiddle link http://jsfiddle.net/rainbow99984/QbZrN/5/ just try to move item 2 over item 0 a new row will be created with item Over, at this point cursor is at Over but element is not.
I already have checked few previous suggestion on SO (1) jQuery draggable shows helper in wrong place after page scrolled and (2) JqueryUI Drag: Cursor not at the same position as draggable element but it still have the problem, Can anyone look into the codes and give some advice
Thank you all !
$.fn.dragInit=function(){
$(this).each(function(){
if($(this).data("drag_Enable")==true){
$.noop();
}else{
$(this).draggable({
containment: "#canvas",
cursor:"move",
zIndex:99,
delay:100,
revert:"invalid",
opacity:0.7,
stop:function(event,ui){
if(ui.helper.hasClass("dummy-remove")){
var emptyDrop1=$("<div class='e'>Stop</div>");
emptyDrop1.dropInit();
$(ui.helper).replaceWith(emptyDrop1);//replace original place with Empty cell
}
$(".dummy").remove();
$("#canvas li").filter(function(){
return $(this).children(":not('.e')").length==0;
}).remove();
},
drag:function(event,ui){
var msg = "Handler for .mousemove() called at ";
msg += ui.position.top +":"+ui.position.left+ ", " + ui.offset.top+":"+ui.offset.left;
$("#pos1").html( msg );
var elm=$(".dummy");
if(elm.length==1){
ui.helper.css("top", ui.position.top);
ui.helper.css("left", ui.position.left);
var top=elm.css("height")-ui.helper.css("top");
ui.position.top += top;
}
}
});
$(this).data("drag_enable",true);
}
});
return this;
}
$.fn.dropInit=function(){
$(this).each(function(){
if($(this).data("drop_enable")==true){
$.noop();
}else{
$(this).droppable({
tolerance:"pointer",
accept:"div",
drop:function(event,ui){
var drop2=ui.draggable.clone();
$(drop2).removeAttr("style");
var ne=$(".dummy");//Helper li.
var pos=$(this).parent().children().index($(this));
if($(this).hasClass("e") && $(drop2).hasClass("a") ){
//drop on empty cell
$(this).replaceWith(drop2);
}else if(drop2.hasClass("b")){
// drop on existing cell, add it in new row.
ne.html(drop2);
}else{
ne.children(":eq("+pos+")").replaceWith(drop2);
}
drop2.parent().removeClass("dummy").addClass("c");
drop2.dragInit().dropInit();
ui.draggable.addClass("dummy-remove");
},
over:function(ev,ui){
if($(this).hasClass("e")){
$.noop();
}else{
$(".dummy").remove();
var elm=$("<li class='dummy'>");
var emptyDrop=$("<div class='e'>over</div>");
var emptyDrop1=$("<div class='e'>over</div>");
elm.append(emptyDrop).append(emptyDrop1);
if($(this).parent().is(":last-child")){
elm.insertAfter($(this).parent());
}else{
elm.insertBefore($(this).parent());
}