1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| var myId, myCheck, myEat, myPage, origin;
$('.drag').draggable({
revert:"invalid",
helper: 'clone',
start:function(ui){
myId =$(this).parent().prev().html();
myCheck=$(this).parent().parent().find(':checked').length >0 ;
myEat= $(this).parent().parent().find('div.eat').html();
myPage=$(this).parents('[id^="page"]').attr('id');
$(this).data('myjson',{
"Id_drag" : myId,
"Check_drag":myCheck,
"Eat_drag" : myEat,
"Page_drag" : myPage
});
}
});
$('.player').droppable({
accept : function(obj){ return obj.hasClass('drag') && $(this).is(':empty')},
drop: function(event,ui){
ui.draggable.appendTo( this );
origin=$('#'+(ui.draggable).data('myjson').Page_drag)
.find('td')
.filter(function(){ return $(this).html()==$(ui.draggable).data('myjson').Id_drag})
.parent();
$(this).parent().find('div.eat').html( $(ui.draggable).data('myjson').Eat_drag );
$(this).parent().find(':checkbox').attr("checked", $(ui.draggable).data('myjson').Check_drag) ;
origin.find('.eat, .player').empty();
origin.find(':checkbox').attr('checked',false);
}
}); |
Partager