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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| $(document).ready(function(){
$('#nscrol').on('click','#dnd',function(e){
e.preventDefault();
$(this).fadeOut('slow',function(){
$(this).siblings().fadeIn('slow').css("display", "inline-block");
});
// ajoute la propriété pour le drop et le transfert de données
$.event.props.push('dataTransfer');
$('.block').attr('draggable',true).css('outline','1px solid green').find('*').attr('draggable',false);
var i, dragged, class_name;
var traitement = false;
$('.block').on({
dragstart:function(e){
if(!traitement){
dragged = $(this);
i = dragged.index();
class_name = dragged.attr('class');
dragged.css('opacity', '0.5');
e.dataTransfer.setData('text/html',dragged.html());
}
},
dragenter:function(e){
e.preventDefault();
},
dragleave:function(){
},
dragover:function(e){
e.preventDefault();
},
drop:function(e){
var dropzone = $(this);
if(typeof(dropzone)=='undefined'||dropzone.get(0)==dragged.get(0)){
e.preventDefault();
return false;
}
if(!traitement){
var data = e.dataTransfer.getData('text/html');
if(dropzone.index()<=i){
dropzone.before(dragged);
}else{
dropzone.after(dragged);
}
}
},
dragend:function(){
$(this).css('opacity','1');
},
click:function(e){
e.preventDefault();
}
});
}).on('click','#cancel',function(){
$('.block').off().css('outline','none');
$('[draggable]').removeAttr('draggable');
$('#dnd').siblings().fadeOut('slow', function(){
$('#dnd').fadeIn('slow');
});
}).on('click','#record',function(){
var len = $('.block').length;
var ordre = [];
var me = $(this);
for(var j=0;j<len;j++){
ordre.push({id:$('.entree_block').eq(j).data("id"),rang:$('.entree_block').eq(j).index('.entree_block')});
}
$.ajax({
type: "POST",
url: window.location.origin+"/news/orderUpdate.php",
data: {ordre:JSON.stringify(ordre)},
beforeSend:function(){
var img = '<img id="load" src="'+window.location.origin+'/news/iconLoading.gif" style="height:22px;margin-left:15px;margin-right:118px;vertical-align:middle;">';
($('#msg').length)?$('#msg').replaceWith(img):me.after(img);
},
success:function(){
$('#load').replaceWith('<b id="msg" style="margin-left:5px;">Changements enregistrés.</b>');
}
});
}).on('click','#reset',function(){
$.ajax({
type: "POST",
url: window.location.origin+"//orderUpdate.php",
data: {reset:true},
success:function(){
window.location.reload();
}
});
});
}); |
Partager