{"size": 2731, "ext": "js", "max_stars_repo_path": "assets/js/category/follow.js", "max_stars_repo_name": "answeropedia/answeropedia", "max_stars_repo_stars_event_min_datetime": "2019-09-04T23:03:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-26T14:51:13.000Z", "max_issues_repo_path": "assets/js/category/follow.js", "max_issues_repo_name": "answeropedia/answeropedia", "max_issues_repo_issues_event_min_datetime": "2019-08-18T08:43:40.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:19:25.000Z", "max_forks_repo_path": "assets/js/category/follow.js", "max_forks_repo_name": "answers-wtf/answers-wtf", "max_forks_repo_forks_event_min_datetime": "2020-04-11T05:48:12.000Z", "max_forks_repo_forks_event_max_datetime": "2020-04-11T05:48:12.000Z"}
{"max_stars_count": 4, "max_issues_count": 386, "max_forks_count": 1, "avg_line_length": 34.5696202532, "max_line_length": 87, "alphanum_fraction": 0.5162943977}

$("button.follow_category_button").click(function (e) {

    e.preventDefault();
    $button = $(this);

    var api_key = $.cookie('u_api_key');

    $button.addClass('disabled');

    var form_data = {
        "api_key": api_key,
    };

    var lang = $('html').attr('lang');
    var categoryID = $(this).data("category-id");
    var request_type = ($button.hasClass('followed') ? "DELETE" : "POST");
    var request_url = '/api/v1/' + lang + '/categories/' + categoryID + '/follow.json';

    console.log("request_type: " + request_type + "\n");
    console.log("request_url: " + request_url + "\n");

    $.ajax({
        type: request_type,
        url: request_url,
        data: form_data,
        dataType: 'json',
        encode: true
    })
        .done(function (data) {
            $button.removeClass('disabled');

            if (data.error_code || data.error_message) {
                console.log("DONE error: " + JSON.stringify(data, undefined, 2));
            } else {
                if ($button.hasClass('followed')) {
                    console.log("DONE succes unfollow\n");
                    $button.removeClass('followed');
                    $button.removeClass('btn-danger').addClass('btn-outline-primary');
                    var follow_title = $(this).data("follow-title");
                    $button.html(follow_title);
                    $button.blur();
                } else {
                    console.log("DONE succes follow\n");
                    $button.addClass('followed');
                    $button.removeClass('btn-outline-primary').addClass('btn-success');
                    var followed_title = $(this).data("followed-title");
                    $button.text(followed_title);
                    $button.blur();
                }
            }
        })
        .fail(function (data) {
            $button.removeClass('disabled');
            console.log("\nFAIL: " + JSON.stringify(data, undefined, 2));
        });
});

$("button.follow_category_button")
    .mouseenter(function () {
        $button = $(this);
        if ($button.hasClass('followed')) {
            var unfollow_title = $(this).data("unfollow-title");
            $button.removeClass('btn-success').addClass('btn-danger');
            $button.text(unfollow_title);
        }
    })
    .mouseleave(function () {
        $button = $(this);
        if ($button.hasClass('followed')) {
            var followed_title = $(this).data("followed-title");
            $button.removeClass('btn-danger').addClass('btn-success');
            $button.text(followed_title);
        } else {
            var follow_title = $(this).data("follow-title");
            $button.text(follow_title);
        }
    });
