$(document).ready(function(){ $('.delete').css({"display":"none"});//initialisation des delete //passage au dessus des notes $('.note').hover(function () { $(this).find('.delete').css({"display":"block"}); }, function () { $(this).find('.delete').css({"display":"none"}); }); //click sur delete $('.delete').click(function(){ var data2 = {'id' : $(this).attr("id")}; $(this).replaceWith(''); /* Sending an AJAX POST request: */ $.post('modules/notes/ajax/delete-notes.php',data2,function(msg2){ if(parseInt(msg2)) { msg2--; //alert(msg2); $(".note:eq("+msg2+")").fadeOut(); } //$(this).parent('.note').hide(); }); }); var tmp; $('.note').each(function(){ /* Finding the biggest z-index value of the notes */ tmp = $(this).css('z-index'); if(tmp>zIndex) zIndex = tmp; }) /* A helper function for converting a set of elements to draggables: */ make_draggable($('.note')); /* Configuring the fancybox plugin for the "Add a note" button: */ $("#addButton").fancybox({ 'zoomSpeedIn' : 600, 'zoomSpeedOut' : 500, 'easingIn' : 'easeOutBack', 'easingOut' : 'easeInBack', 'hideOnContentClick': false, 'padding' : 15 }); /* Listening for keyup events on fields of the "Add a note" form: */ $('.pr-body,.pr-author').live('keyup',function(e){ if(!this.preview) this.preview=$('#previewNote'); /* Setting the text of the preview to the contents of the input field, and stripping all the HTML tags: */ this.preview.find($(this).attr('class').replace('pr-','.')).html($(this).val().replace(/<[^>]+>/ig,'')); }); /* Changing the color of the preview note: */ $('.color').live('click',function(){ $('#previewNote').removeClass('yellow green blue').addClass($(this).attr('class').replace('color','')); }); /* The submit button: */ $('#note-submit').live('click',function(e){ if($('.pr-body').val().length<4) { alert("The note text is too short!") return false; } /*if($('.pr-author').val().length<1) { alert("You haven't entered your name!") return false; }*/ $(this).replaceWith(''); var data = { 'zindex' : ++zIndex, 'body' : $('.pr-body').val(), /*'author' : $('.pr-author').val(),*/ 'color' : $.trim($('#previewNote').attr('class').replace('note','')) }; /* Sending an AJAX POST request: */ $.post('modules/notes/ajax/post-notes.php',data,function(msg){ if(parseInt(msg)) { /* msg contains the ID of the note, assigned by MySQL's auto increment: */ var tmp = $('#previewNote').clone(); //tmp.find('.delete').attr('id',msg); tmp.find('span.data').text(msg).end().css({'z-index':zIndex,top:0,left:0}); tmp.appendTo('body'); make_draggable(tmp) } //$.fn.fancybox.close; $.fancybox.close(); }); e.preventDefault(); }); var zIndex = 0; function make_draggable(elements) { /* Elements is a jquery object: */ elements.draggable({ containment:'parent', start:function(e,ui){ ui.helper.css('z-index',++zIndex); }, stop:function(e,ui){ /* Sending the z-index and positon of the note to update_position.php via AJAX GET: */ $.get('modules/notes/ajax/update_position.php',{ x : ui.position.left, y : ui.position.top, z : zIndex, id : parseInt(ui.helper.find('span.data').html()) }); } });} });