{"size": 1960, "ext": "js", "max_stars_repo_path": "app/assets/javascripts/posts.js", "max_stars_repo_name": "cosimaradu/turbulent-duck-chat", "max_stars_repo_stars_event_min_datetime": "2015-11-06T22:06:57.000Z", "max_stars_repo_stars_event_max_datetime": "2015-11-06T22:06:57.000Z", "max_issues_repo_path": "app/assets/javascripts/posts.js", "max_issues_repo_name": "cosimaradu/turbulent-duck-chat", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "app/assets/javascripts/posts.js", "max_forks_repo_name": "cosimaradu/turbulent-duck-chat", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 31.6129032258, "max_line_length": 96, "alphanum_fraction": 0.4785714286}
$(document).ready(function() {
    var wrapper = $('.screen_wrapper');
    var last_id = $('#last_message_id').val();
    $(function () {
        var window_height = $(window).height(),
            content_height = window_height - 200;
        $('.screen_wrapper').height(content_height);
    });

    $(window).resize(function () {
        var window_height = $(window).height(),
            content_height = window_height - 200;
        wrapper.height(content_height);
        wrapper.stop().animate({
            scrollTop: wrapper[0].scrollHeight
        }, 1600);

    });

    wrapper.stop().animate({
        scrollTop: wrapper[0].scrollHeight
    }, 1600);

    var source = new EventSource('/message');
    source.addEventListener("new_message", function(event) {
        var data = JSON.parse(event.data);
        if (data.id !== last_id) {
            last_id = data.id;
            $("#table").find('tbody')
                .append($('<tr><td class="name_column"><h2 class="username shadow">' +
                    data.name +
                    '</h2><div class="timestamp"><i class="fa fa-clock-o"></i><strong>' +
                    data.created + '</strong></div></h2></td><td><div class="message bubble">' +
                    data.message_text + '</div></td></tr>')
            );
            wrapper.stop().animate({
                scrollTop: wrapper[0].scrollHeight
            }, 500);
        }
    });




    $(".submit").click(function() {
        $('.submit').attr("disabled", true);
        var name = $(".name").val();
        var message = $(".message_text").val();
        $.ajax({
            url: '/posts/create',
            cache: false,
            data: {
                message: message,
                name: name
            },
            method: "POST"})
            .done(function (data) {
                $('.submit').attr("disabled", false);
                $('.message_text').val("");
            })
    });
});