-
Notifications
You must be signed in to change notification settings - Fork 0
/
footer.php
92 lines (75 loc) · 3.5 KB
/
footer.php
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
88
89
90
91
92
<?php
?>
</div><!-- #content -->
<div id="chat-container">
<script>
var loading = false;
function open_chat(target_user_id) {
event.preventDefault();
$('#main').css({ "cursor": "wait" });
if (!$('#chat-'+target_user_id).length) {
$.post('ajax/get_chat.php', {id: target_user_id, res: 'get_chat'}, function (data) {
// Callback function
if (data != 'failed') {
$('#chat-container').append(data);
scroll_to_message(target_user_id, 0);
var message_unseen_count = $('#message-'+target_user_id+' .profile-notification-counter p').html();
var total_message_unseen_count = $('#messages-unseen-counter p').html();
var new_total_message_unseen_count = total_message_unseen_count - message_unseen_count;
if (message_unseen_count > 0)
$('#messages-unseen-counter p').html(new_total_message_unseen_count);
if ((new_total_message_unseen_count == 0) || (new_total_message_unseen_count = "0"))
$('#messages-unseen-counter').remove();
$('#message-'+target_user_id+' .profile-notification-counter').remove();
setInterval(function() { get_new_chat_messages(target_user_id); }, 10000);
}
$('#main').css({ "cursor": "" });
});
}
}
function get_new_chat_messages(target_user_id) {
if (loading) return;
loading = true;
// TODO improve efficiency
$.post('ajax/get_chat.php', {id: target_user_id, res: 'get_chat_messages'}, function (data) {
// Callback function
if (data != 'failed') {
$('#chat-messages-'+target_user_id).html(data);
}
loading = false;
});
}
function close_chat(id) {
$('#chat-'+id).remove();
}
function send_message(el, target_user_id) {
event.preventDefault();
$('#chat-'+target_user_id).css({ "cursor": "wait" });
var msg_input = $(el).find('.message-input');
$.post('ajax/get_chat.php', {id:target_user_id, action:'send', message:msg_input.val()}, function(data) {
// Callback function
if (data != 'failed') {
get_new_chat_messages(target_user_id);
msg_input.val('');
}
msg_input.focus();
scroll_to_message(target_user_id, 500);
$('#chat-'+target_user_id).css({ "cursor": "" });
});
return false;
}
function scroll_to_message(id, speed){
var element = $('#chat-messages-'+id);
$(element).animate({ scrollTop: $(element).prop("scrollHeight")}, speed);
}
</script>
</div>
<footer id="main-footer" class="site-footer" role="contentinfo">
<div class="site-wrapper">
<div class="site-info">
</div>
</div>
</footer>
</div><!-- #page -->
</body>
</html>