Codice HTML:
$(function()
{
$('#chat').load('chat.php');
setInterval(function(){
$('#online').load('online.php');
$('#countnum').load('countnum.php');
},1000);
var scroll = setInterval(function(){
$('#chat').scrollTop($("#chat")[0].scrollHeight);
},0);
setTimeout(function(){clearInterval(scroll);},2000);
$('#name').live('keyup',function(e)
{
if(this.value.length >= 3)
{
$.ajax({
url:'changename.php',
type:'post',
data:{name:name}
});
$('#finame').fadeOut('3000',function()
{
$('#finame').html("Nome cambiato");
});
}
else
{
$('#finame').fadeOut('3000',function()
{
$('#finame').html("Usa almeno 3 caratteri.");
});
}
});
$('#commento').live('keyup',function(e)
{
$.ajax({url:'setuseronline.php'});
if(e.keyCode == 13)
{
if(this.value.length > 0)
{
var name = document.getElementById('name').value;
$.ajax({
url:'input.php',
type:'post',
data:{name:name,commento:this.value}
});
}
this.value = null;
}
});
$('div#mfont').live('click',function()
{
$('div#impostations').toggle(function()
{
$(this).load("listfonts.php");
});
});
$('#font').live('click',function()
{
var font = $(this).attr('class');
$.ajax({
url:'updatefont.php',
type:'post',
data:{font:font}
});
$('#chat').load('chat.php');
});
$('#size').live('click',function()
{
var size= this.value;
$.ajax({
url:'updatefont.php',
type:'post',
data:{size:size}
});
});
size.value = '16';
$('div#setuserinfo').live('click',function()
{
var text = $(this).text();
var cla = $(this).attr('class');
if(cla == 'you')
{
$('div#infouseronline').addClass('you');
$('div#infouseronline div#sidecontent div#gotoprivate').show();
}
else
{
$('div#infouseronline div#sidecontent div#gotoprivate').html('Chatta in privato');
}
$('div#infouseronline div#sidename').html(text);
$('div#infouseronline').show();
});
$('div#gotoprivate').live('click',function()
{
var cas = $('div#infouseronline').attr('class');
if(cas == '' || cas == 'undefined' || cas == ' ')
{
var name = $('#sidename').text();
$('div#listchat').append("<div id='pvtchat' class='col'>"+name+"</div>");
$('div#infouseronline').hide();
$('div#infouseronline').removeClass('you');
}
});
$('div#changename').live('click',function()
{
$('div#showname').toggle();
});
$('div#chat .overflowmode').live('click',function()
{
var idm = $(this).attr('idm');
$('div#optionmessages').slideToggle();
$('div#optionmessages').html("<button onclick=optionmex("+idm+",'eliminazione')>Elimina messaggio</button> <button id='modmex'onclick=changemex("+idm+",'modificazione')>Correggi messaggio</button><button id='modmexhide' style='display:none' onclick=savetext('"+idm+"')>Salva messaggio</button> <button class='close' onclick=chiudioptionmex('idm')>X</button>");
});
$('div#username username').live('click', function()
{
$(this).attr('contentEditable',true).focus();
}).live('keyup',function()
{
var nome = $(this).text();
if(nome.length >= 3)
{
$.ajax({
url:'changename.php',
method:'post',
data:{nome:nome},
success:function(ritorno)
{
$('div#username.showoutput').html(ritorno);
}
});
}
else
{
$('div#username.showoutput').html("Nome troppo corto, minimo 3 caratteri");
}
});
});
function optionmex(id,method,testo)
{
$.ajax({
type:'POST',
url:'optionmessages.php',
data:{id:id,method:method,testo:testo},
success:function(r)
{
$('div#optionmessages').slideToggle();
ricaricalachat();
},
error:function()
{
alert('Non è stato possibile cancellare il messaggio');
}
});
}
function savetext(id)
{
var thistext = $(".right[idm='"+id+"']").text();
optionmex(id,'modificazione',thistext);
}
function chiudioptionmex(id)
{
$('div#optionmessages').slideToggle();
$('[contenteditable]').removeAttr('contenteditable');
$(".right").addClass('overflowmode');
}
function changemex(id,method)
{
$('#modmex').hide();
$('#modmexhide').show();
$(".right[idm='"+id+"']").attr('contentEditable',true).removeClass('overflowmode').focus();
}
function ricaricalachat()
{
$('#chat').load('chat.php');
}