-
Notifications
You must be signed in to change notification settings - Fork 0
/
new.js
82 lines (71 loc) · 2.4 KB
/
new.js
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
$(document).ready(function() {
var $messages = $('.messages-content'),
d, m,
i = 0;
function updateScrollbar() {
$messages.mCustomScrollbar("update").mCustomScrollbar('scrollTo', 'bottom', {
scrollInertia: 10,
timeout: 0
});
}
function setDate() {
d = new Date();
if (m !== d.getMinutes()) {
m = d.getMinutes();
var $lastMessage = $('.message').last();
$('<div class="timestamp">' + d.getHours() + ':' + m + '</div>').appendTo($lastMessage);
$('<div class="checkmark-sent-delivered">✓</div>').appendTo($lastMessage);
$('<div class="checkmark-read">✓</div>').appendTo($lastMessage);
}
}
function insertMessage() {
var msg = $('.message-input').val();
if ($.trim(msg) === '') {
return false;
}
$('<div class="message message-personal">' + msg + '</div>').appendTo($('.messages-content')).addClass('new');
setDate();
$('.message-input').val(null);
updateScrollbar();
setTimeout(function() {
fakeMessage();
}, 1000 + (Math.random() * 20) * 100);
}
$('.message-submit').click(function() {
insertMessage();
});
$(window).on('keydown', function(e) {
if (e.which === 13) {
insertMessage();
return false;
}
});
var Fake = [
'Hi there, I\'m Jesse and you?',
'Nice to meet you',
':)'
];
function fakeMessage() {
if ($('.message-input').val() !== '') {
return false;
}
$('<div class="message loading new"><figure class="avatar"><img src="http://askavenue.com/img/17.jpg" /></figure><span></span></div>').appendTo($('.messages-content'));
updateScrollbar();
setTimeout(function() {
$('.message.loading').remove();
$('<div class="message new"><figure class="avatar"><img src="http://askavenue.com/img/17.jpg" /></figure>' + Fake[i] + '</div>').appendTo($('.messages-content')).addClass('new');
setDate();
updateScrollbar();
i++;
}, 1000 + (Math.random() * 20) * 100);
}
$('.button').click(function() {
$('.menu .items span').toggleClass('active');
$('.menu .button').toggleClass('active');
});
// Initialize scrollbar after content is loaded
$messages.mCustomScrollbar();
setTimeout(function() {
fakeMessage();
}, 100);
});