1
爲了防止跌落到垃圾箱後一種可能,我使用爲什麼this.helper = null? (可排序/可拖動/可棄)
$("#image-ul").sortable('cancel');
,但得到的螢火錯誤。一切都按預期工作,但偏執,我做錯了什麼。我可以通過什麼方式停止可丟棄更新後丟棄垃圾?
$(document).ready(function(){
$(function(){
// make the list of images sortable
$("#image-ul").sortable({
// allow dragging into the trash can
connectWith: '#trash_can',
item: 'li',
// revert causes bugginess in IE, so left out even though cool
//revert: 200,
opacity: 0.6,
cursor: 'move',
// apply this css class to available places to drop within list
placeholder: 'placeholder-border',
// drop available once mouse has touched droppable area
tolerance: 'pointer',
update: function(){
var order = $(this).sortable("serialize");
$.post("/drag_drop/update", order, function(theResponse){
// show the confirmation and fade it away after 2.5 seconds
$('#content').css('display', 'block');
$('#content').html(theResponse).delay(2500).fadeOut('slow');
});
}
});
// allow for deleting images by sending them to the trash can
$("#trash_can").droppable({
accept: '#image-ul > li',
// when the trash can is hovered on by a draggable, set the css class
hoverClass: 'delete-border',
drop: function(event, ui) {
// setTimeout takes care of IE bug where deleted item remains
setTimeout(function() { ui.draggable.remove(); }, 1);
deleteImage(ui.draggable);
}
});
// what to do when an image is dropped into the trash can
function deleteImage($draggable){
// strip out "image_data_" so that only the actual image ID is sent to delete query
var id = $draggable.attr('id');
id = id.replace('image_data_','');
params = {
'id': id,
'path': $draggable.find("img").attr("src")
}
$.ajax({
url: '/drag_drop/delete',
type: 'POST',
data: params,
success: function(delete_response){
$('#content').css('display', 'block');
$('#content').html(delete_response).delay(2500).fadeOut('slow');
}
});
$("#image-ul").sortable('cancel');
}
});
});