Просмотр файла globalchat/plugins/ajax_chat.js

Размер файла: 11.19Kb
$("head").append("<link rel='stylesheet' type='text/css' href='plugins/style.css' />");$("body").attr("onresize","msgs_area_size_control (); scroll_msgs_list ();");tmp_msgs_count=chat_page=1;tmp_msgs=[];get_new_data_process=connect_error=0;function htmlspecialchars(a){a=a.replace(/&/g,"&amp;");a=a.replace(/</g,"&lt;");a=a.replace(/>/g,"&gt;");return a=a.replace(/"/g,"&quot;")}function delete_bad_symbols(a){return a=a.replace(/&/g,"AND")}function hide_icon(a){$("#"+a).css("opacity","0")}
function show_icon(a){$("#"+a).css("opacity","0.8")}function process_smiles(a){return a.replace(/\:([a-zA-Z]{2,10})/g,"<img src='smiles/$1.gif' alt='' />")}
function bbcodes_replacer(a,d,c){result=a;c=process_bbcodes(c);switch(d){case "b":result="<strong>"+c+"</strong>";break;case "i":result="<em>"+c+"</em>";break;case "u":result="<span style='text-decoration: underline;'>"+c+"</span>";break;case "s":result="<del>"+c+"</del>";break;case "small":result="<span style='font-size: 8px;'>"+c+"</span>";break;case "big":result="<span style='font-size: 20px;'>"+c+"</span>";break;case "code":result="<code style='white-space: pre;'>"+c+"</code>";break;case "quote":result=
"<div class='quote' style='font-size: 10px;'>"+c+"</div>";break;case "red":result="<span style='color: darkred;'>"+c+"</span>";break;case "green":result="<span style='color: darkgreen;'>"+c+"</span>";break;case "blue":result="<span style='color: darkblue;'>"+c+"</span>";break;case "orange":result="<span style='color: darkorange;'>"+c+"</span>"}return result}function process_bbcodes(a){return a.replace(/\[([a-zA-Z]{1,10})\](.*?)\[\/\1\]/g,bbcodes_replacer)}
function process_text(a){return process_smiles(process_bbcodes(a))}function scroll_msgs_list(){1==$.cookie("auto_scrolling")&&$("#msgs_list").scrollTop(100*$("#msgs_list").height())}function clear_chat_msgs(){$("#msgs_list").empty()}
function set_navigation_panel(){1==$.cookie("sound")?$("#sound_toggle").attr("src","icons/sound_on.png"):2==$.cookie("sound")?$("#sound_toggle").attr("src","icons/sound_off.png"):$.cookie("sound",1);1==$.cookie("window_attach")?($(document.body).css("overflow","hidden"),$("#window_attach_toggle").attr("src","icons/attach_on.png")):2==$.cookie("window_attach")?($(document.body).css("overflow","auto"),$("#window_attach_toggle").attr("src","icons/attach_off.png")):$.cookie("window_attach",2);$.cookie("auto_scrolling",
1)}function sound_status_toggle(){"1"==$.cookie("sound")?($.cookie("sound","2",{expires:364}),$("#sound_toggle").attr("src","icons/sound_off.png")):($.cookie("sound","1",{expires:364}),$("#sound_toggle").attr("src","icons/sound_on.png"))}
function auto_scrolling_status_toggle(a){1==$.cookie("auto_scrolling")&&1!==a?($.cookie("auto_scrolling","2",{expires:364}),$("#auto_scrolling_toggle").attr("src","icons/scrolling_off.png")):($.cookie("auto_scrolling","1",{expires:364}),$("#auto_scrolling_toggle").attr("src","icons/scrolling_on.png"))}
function window_attach_status_toggle(){$("#text_input").focus();"hidden"==$(document.body).css("overflow")?($.cookie("window_attach","2",{expires:364}),$(document.body).css("overflow","auto"),$("#window_attach_toggle").attr("src","icons/attach_off.png")):($.cookie("window_attach","1",{expires:1}),$(document.body).css("overflow","hidden"),$("#window_attach_toggle").attr("src","icons/attach_on.png"))}
function load_smiles(){$("#smiles_window").text()||($("#smiles_window").text("\u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0441\u043c\u0430\u0439\u043b\u043e\u0432..."),$.ajax({url:"ajax_chat_router.php",type:"POST",data:{get_smiles:1},dataType:"text",success:function(a){$("#smiles_window").val("");$("#smiles_window").html(a)}}))}
function smiles_window_toggle(){$("#phrases_designer_window").hide();$("#bb_codes_window").hide();load_smiles();$("#smiles_window").toggle();text_input_coordinates=$("#text_input").offset();$("#smiles_window").offset({top:text_input_coordinates.top-134-2-42,left:text_input_coordinates.left+90})}
function phrases_designer_window_toggle(){$("#smiles_window").hide();$("#bb_codes_window").hide();$("#phrases_designer_window").toggle();text_input_coordinates=$("#text_input").offset();phrases_designer_window_size=$("#phrases_designer_window").height()+2;$("#phrases_designer_window").offset({top:text_input_coordinates.top-phrases_designer_window_size-42,left:text_input_coordinates.left+120})}
function bbcodes_window_toggle(){$("#smiles_window").hide();$("#phrases_designer_window").hide();$("#bb_codes_window").toggle();text_input_coordinates=$("#text_input").offset();bb_codes_window_size=$("#bb_codes_window").height()+2;$("#bb_codes_window").offset({top:text_input_coordinates.top-bb_codes_window_size-42,left:text_input_coordinates.left+150})}
function insert_nick(a,d){add_text(a+" [ID"+d+"], ");$("#last_selected_user").hide();$("#last_selected_user").html("<a href='#' onclick='insert_nick (\""+a+'", '+d+");'>"+a+"</a> <span onmouseover='show_user_menu (\"last_selected_user_menu\");' onmouseout='hide_user_menu (\"last_selected_user_menu\");'><a class='"+DIV_C_USER_ID+"' href='user_menu.php?user_id="+d+"'>[ID"+d+"]</a> <span id='last_selected_user_menu' style='display: none;'><a href='user_profile.php?user_id="+d+"'><img src='icons/user_info.png' alt='' /></a> <a href='quick_msg.php?user_id="+
d+"'><img src='icons/msgs.png' alt='' /></a> <img src='icons/delete.png' alt='' onclick='delete_selected_user ();' style='cursor: pointer;' /></span></span>");$("#last_selected_user").fadeIn("normal")}function delete_selected_user(){$("#last_selected_user").empty()}
function add_msgs(a,d){var c=document.getElementById("msgs_list");$.each(a,function(a,b){c.innerHTML+="<div id='chat_msg_"+b.id+"' class='"+DIV_C_MSGS_LIST+"' onmouseover='show_icon (\"delete_icon_"+b.id+"\");' onmouseout='hide_icon (\"delete_icon_"+b.id+"\");'><a href='#' onclick='insert_nick (\""+b.user_nick+'", '+b.user_id+"); return false;'><img src='icons/sex_"+b.user_sex+".png' alt='' /> <span class='"+gc.div_c_user_nick+"'>"+b.user_nick+"</span></a> <span id='user_quick_menu_block"+b.id+"_"+
b.user_id+"_back' onmouseover='show_user_menu (\"user_quick_menu_block"+b.id+"_"+b.user_id+"\");' onmouseout='hide_user_menu (\"user_quick_menu_block"+b.id+"_"+b.user_id+"\");'><a class='"+DIV_C_USER_ID+"' href='user_menu.php?user_id="+b.user_id+"'>[ID"+b.user_id+"]</a> <span id='user_quick_menu_block"+b.id+"_"+b.user_id+"' style='display: none;'> <a href='user_profile.php?user_id="+b.user_id+"'><img src='icons/user_info.png' alt='' /></a> <a href='quick_msg.php?user_id="+b.user_id+"'><img src='icons/msgs.png' alt='' /></a> </span></span> "+
process_text(b.msg)+(1<=gc_user.rights_group&&!d?"<a href='http://chatmix.ru/gc_control/delete_msg.php?msg_id="+b.id+"&amp;location="+gc.current_location_base64+"'><img style='opacity: 0; float: right;' id='delete_icon_"+b.id+"' src='icons/delete.png' alt='delete' title='\u0423\u0434\u0430\u043b\u0438\u0442\u044c' /></a>":"")+"</div>"});scroll_msgs_list()}
function send_message(){hide_accelerators();var a=delete_bad_symbols($("#text_input").val());$("#text_input").focus();if(""!=a){a=a.replace(/(^ *)|( *$)/,"");if(a.match(/\S(?=(\.ru\b)|(\.ua\b)|(\.com\b)|(\.kom\b)|(\.biz\b)|(\.info\b)|(\.mobi\b)|(\.su\b)|(\.us\b)|(\.tk\b))/ig,""))return alert("\u0421\u043f\u0430\u043c \u0437\u0430\u043f\u0440\u0435\u0449\u0435\u043d"),!1;if(1E3<a.length)return alert("\u0421\u043b\u0438\u0448\u043a\u043e\u043c \u0434\u043b\u0438\u043d\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435. \u041c\u0430\u043a\u0441\u0438\u043c\u0443\u043c 1000 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432"),
!1;if(3>tmp_msgs.length)tmp_msgs[tmp_msgs.length]=a.replace(/^.{2,20} ?\[ID([0-9]{1,6})\]/g,"@$1");else return alert("\u041f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0439\u0442\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043d\u0435 \u0442\u0430\u043a \u0447\u0430\u0441\u0442\u043e"),!1;$("#text_input").val("");tmp_msg={msg_content:{id:"tmp_"+tmp_msgs_count,user_id:gc_user.id,user_nick:htmlspecialchars(gc_user.nick),
user_sex:gc_user.sex,msg:htmlspecialchars(a.replace(/^(.{2,20}) ?\[ID[0-9]{1,6}\]/g,"[b]$1[/b]"))}};add_msgs(tmp_msg,1);tmp_msgs_count+=1;0==last_chat_msg_id&&(last_chat_msg_id=1)}}function play_sound(a){1==$.cookie("sound")&&$("body").append('<object><embed src="sound/'+a+'.swf" autostart="1" width="0" height="0" type="application/x-flashplayer"></embed></object>')}msgs_area_size_control_i=0;
function msgs_area_size_control(){main_area_coordinates=$("#main_area").offset();input_area_panel_size=$("#input_panel").height();msgs_list_size=$(window).height()-main_area_coordinates.top-$("#input_panel").height()-16;$("#msgs_list").height(msgs_list_size-GC_C_FORM_POSITION_CORRECTION);0==msgs_area_size_control_i&&(scroll_msgs_list(),msgs_area_size_control_i=1)}
$(document).ready(function(){function a(a,c,f,b,e,g){if(1==get_new_data_process)return!1;get_new_data_process=1;msgs_to_send=tmp_msgs;tmp_msgs=[];""!=$("#quick_msg").text()&&(e=0);$.ajax({url:"ajax_chat_router.php",type:"POST",data:{room_id:room_id,last_chat_msg_id:last_chat_msg_id,get_new_msgs:a,msgs:msgs_to_send,get_users_online:c,get_rating_info:f,get_room_data:b,get_quick_msgs:e,get_friends_number:g},dataType:"json",error:function(){connect_error||(play_sound("error"),$("#msgs_list").append("<div class='"+
DIV_C_ERROR+"'><img src='icons/important.png' alt='' /> <a href='javascript:location.reload();'>\u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f. \u0420\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u043c \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443</a></div>"),msgs_area_size_control(),scroll_msgs_list());connect_error=1;get_new_data_process=0;scroll_msgs_list()},success:function(a){connect_error=
0;a.room_data&&$("#room_data").html(a.room_data);a.quick_msg&&(play_sound("msg"),$("#chat_area_left_column").prepend(process_text(a.quick_msg)),msgs_area_size_control(),scroll_msgs_list());a.msgs&&(0<last_chat_msg_id&&play_sound("msg"),add_msgs(a.msgs),0<a.max_msg_id&&(last_chat_msg_id=a.max_msg_id),msgs_area_size_control());a.users_in_the_room&&$("#users_in_the_room").html(a.users_in_the_room);a.users_in_the_rooms_counters&&$.each(a.users_in_the_rooms_counters,function(a,b){$("#room_"+b.id+"_users_counter").text(b.counter)});
a.leader&&($("#chat_leader_nick").html(a.leader.nick),$("#chat_leader_rating").text(a.leader.points));a.friends_number&&$("#friends_number").text(a.friends_number);if(a.user){$("#user_rating").text(a.user.points);$("#user_rank").text(a.user.rank);var b="no";1==a.user.rank?b="gold":2==a.user.rank?b="silver":3==a.user.rank&&(b="bronze");$("#user_medal").html("<img src='icons/medal_"+b+"_24.png' alt='' align='middle' />")}get_new_data_process=0}})}last_chat_msg_id=0;room_id=$("#room_id").text();set_navigation_panel();
800>parseInt($("body").css("max-width"))&&$("body").css("max-width","900px");20==room_id&&($("html").attr("oncopy","return false;"),$("html").attr("onmousedown","return false;"),$("html").attr("onclick","return true;"));a(1,1,1,0,1,1);$("#text_input").focus();$("#text_input").keydown(function(a){if(13==a.which)return send_message(),!1;if(9==a.which)return smiles_window_toggle(),!1});setInterval(function(){a(1,0,0,1,1)},2E3);setInterval(function(){a(0,1,1,0,0,1)},11E3)});