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

Размер файла: 4.56Kb
function show_user_menu (elm_id)
{
$('#'+elm_id).show ();
}

function hide_user_menu (elm_id)
{
$('#'+elm_id).hide ();
}

/** 
* Send_quick_msg
*
* Отправляет квик сообщение и удаляет его
*/
function send_quick_msg (user_id, msg_id)
{
var msg = $('#quick_msg_answer').val ();
$.post("quick_msg.php?user_id="+user_id+"&read_quick_msg="+msg_id, { 'quick_msg': msg }, $('#quick_msg').fadeOut ('normal', delete_quick_msg));
}

/** 
* Read_quick_msg
*
* Отмечает квик сообщение как прочитанное
*/
function read_quick_msg (msg_id)
{
	if (msg_id > 0)
	$.get("simple.php", { read_quick_msg: msg_id }, $('#quick_msg').fadeOut ('normal', delete_quick_msg));
}

/**
* Delete_quick_msg
*
* Удаляет квие сообщение с экрана
*/

function delete_quick_msg ()
{
$('#quick_msg').remove ();
	if (chat_page != 'undefined')
	msgs_area_size_control ();
}

/* Заглушка, если не чат */
function msgs_area_size_control (){}

function show_quick_msg_form ()
{
$('#quick_msg_answer_form').fadeIn (200);
msgs_area_size_control ();
}

/**
* Add_text
*
* Добавляем текст в форму ввода
*/

function add_text (section2)
{
input_area = document.getElementById('text_input');
section1 = input_area.value.substr (0, input_area.selectionStart);
section3 = input_area.value.substr (input_area.selectionEnd); 
input_area.value = section1 + section2 + section3;
input_area.selectionStart = section1.length + section2.length;
input_area.selectionEnd = input_area.selectionStart;
input_area.focus();
}

/**
* Insert_smile
*
* Вставляет смайлы в текст
*/

function insert_smile (smile)
{
add_text (' :'+smile);
}


/**
* Insert_bb_code
*
* Вставляет BB-коды в текст
*/

function insert_bb_code (Open, Close) {
CursorEnd = false;
    var doc = document.getElementById('text_input');
    doc.focus();
    if (window.attachEvent && navigator.userAgent.indexOf('Opera') === -1) {                                        
        var s = doc.sel;
        if (s){                                  
            var l = s.text.length;
            s.text = Open + s.text + Close;
            s.moveEnd("character", -Close.length);
            s.moveStart("character", -l);                                           
            s.select();                
        }
    } else {                                              
        var ss = doc.scrollTop;
        var sel1 = doc.value.substr(0, doc.selectionStart);
        var sel2 = doc.value.substr(doc.selectionEnd);
        var sel = doc.value.substr(doc.selectionStart, doc.selectionEnd - doc.selectionStart);  
        
        
        doc.value = sel1 + Open + sel + Close + sel2;
        if (CursorEnd){
            doc.selectionStart = sel1.length + Open.length + sel.length + Close.length;
            doc.selectionEnd = doc.selectionStart;
        }else{            
            doc.selectionStart = sel1.length + Open.length;
            doc.selectionEnd = doc.selectionStart + sel.length;            
        }
        doc.scrollTop = ss; 
                                                    
    }
    return false;
}


/**
* Hide_accelerators
*
* Скрывает ускорители
*/

function hide_accelerators ()
{
$('#smiles_window').hide ();
$('#bb_codes_window').hide ();
$('#phrases_designer_window').hide ();
auto_scrolling_status_toggle (1);
}

function num_rand (min_random, max_random) {
    var range = max_random - min_random + 1;
    return Math.floor(Math.random()*range) + min_random;
}


function insert_quick_phrase (type)
{
var phrases =
{'hellow' : ['Привет', 'Добрый день', 'Здарова', 'Хай', 'Салют', 'Приветик'],
'how' : ['Как ты?', 'Как поживаешь?', 'Как жизнь?', 'Как день прошел?', 'Как погода?'],
'what' : ['Что делаешь?', 'Чем занимаешься?', 'Что нового?'],
'bye' : ['Пока', 'До скорого', 'Всего доброго', 'Пока, пока', 'Всего хорошего', 'Счастливо', 'Еще спишемся']};

var phrases_emotions =
{'hellow' : ['.', '))', ')', ':smile', ':wink', ':beer', ':sure'],
'bye' : ['', ':sure', ':smile', ':wink']};

add_text (phrases[type][num_rand (0, phrases[type].length - 1)]+' ');
	if (type == 'hellow' || type == 'bye')
	add_text (phrases_emotions[type][num_rand (0, phrases_emotions[type].length - 1)]+' ');
}