aboutsummaryrefslogtreecommitdiffstats
path: root/app/assets/javascripts/application.js.erb
blob: a6b09944ea559f724a6e24726f3c62ce3f21f23f (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
39
40
41
42
43
44
45
46
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require _widgets
//= require _define_application
//= require_tree .

$(function() {
    // Layout: User jump
    $("#jump_to_dropdown_toggle").click(function() {
        setTimeout(function() { $("#jump_to_textbox").focus(); }, 0);
    });

    var previous_jump_to_text;
    $("#jump_to_textbox").on("keyup", function() {
        if ($(this).val() != previous_jump_to_text) {
            previous_jump_to_text = $(this).val();
            $("#jump_to_user .jump_to_user_suggestion").remove();
            if ($(this).val().length > 0) {
                $.getJSON("/i/user_jump_suggest.json", { head: $(this).val() }, function(json) {
                    json.forEach(function(s) {
                        $("#jump_to_user").append($("<li />").addClass("jump_to_user_suggestion")
                            .append($("<a />").attr("href", "/" + s.screen_name).attr("title", s.name + " (@" + s.screen_name + ")")
                                .append($("<img />").addClass("twitter-icon").attr("src", s.profile_image_url).attr("alt", "@" + s.screen_name).attr("onerror", "this.src = '<%= image_path("profile_image_missing.png") %>'"))
                                .append($("<span />").text("@" + s.screen_name))));
                    });
                });
            }
        }
    });
    $("#jump_to_form").on("submit", function() {
        $(this).attr("action", "/" + $("#jump_to_textbox").val());
    });
});

$(function() {
    var controller = $("body").data("controller");
    var action = $("body").data("action");

    var ac = Application[controller];
    if (ac !== undefined) {
        if (ac["_"] !== undefined) { ac["_"](); }
        if (ac[action] !== undefined) { ac[action](); }
    }
});