aboutsummaryrefslogtreecommitdiffstats
path: root/app/assets/javascripts/tweets.js
blob: e4f5ddaf8b4b1cd7135fdab7acd9109bd560bb13 (plain)
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
Application.tweets = {
    _: function() {
        if ($("#statuses")) {
            var format_tweet = function(d) {
                $("time", d).each(
                    function() {
                        $(this).text(new Date($(this).attr("datetime"))
                                     .toLocaleString());
                    });
            };
            format_tweet($(".statuses"));

            if ($("link[rel=next]")) {
                $.autopager({
                    content: $(".statuses"),
                    link: $("link[rel=next]"),
                    onStart: function() {
                        $(".loading").show();
                    },
                    onReceived: function(obj) {
                        format_tweet(obj);
                    },
                    onComplete: function() {
                        $(".loading").hide();
                    }
                });
            }
        }

        $(".statuses").on("click", ".expand-responses-button", function() {
            var id = $(this).attr("data-id");
            var type = $(this).attr("data-type");
            $.getJSON("/i/" + id + "/" + type + ".json", function(json) {
                $(".status[data-id=\"" + id + "\"] .status-responses-" + type).html(json.html);
            });
        });
    }
};