File size: 1,138 Bytes
a47067a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
var messages = $(".messages-content");

function insertMessage() {
    var msgText = $(".action-box-input").val();
    if ($.trim(msgText) == "") {
        return false;
    }
    var msg = $("<div>").addClass("message personal").text(msgText);
    $("<div>").addClass("timestamp").text(getTimestamp()).appendTo(msg);
    msg.appendTo($('.messages-content'));
    $(".action-box-input").val(null);

    $.post("/get_abbreviation", { acronym: msgText }, function (data) {
        var responseMsg = $("<div>").addClass("message").text(data.response);
        $("<div>").addClass("timestamp").text(getTimestamp()).appendTo(responseMsg);
        responseMsg.appendTo($('.messages-content'));
        updateScrollbar();
    });
}

function updateScrollbar() {
    messages.scrollTop(messages[0].scrollHeight);
}

function getTimestamp() {
    var d = new Date();
    return d.getHours() + ":" + (d.getMinutes() < 10 ? '0' : '') + d.getMinutes();
}

$(window).on('keydown', function (e) {
    if (e.which == 13) {
        insertMessage();
        return false;
    }
});

$(window).on('load', function () {
    messages.mCustomScrollbar();
});