{"size": 1324, "ext": "js", "max_stars_repo_path": "assets/source/js/Ajax/likeButton.js", "max_stars_repo_name": "ikoncept/Municipio", "max_stars_repo_stars_event_min_datetime": "2016-08-25T13:11:28.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-24T08:57:47.000Z", "max_issues_repo_path": "assets/source/js/Ajax/likeButton.js", "max_issues_repo_name": "ikoncept/Municipio", "max_issues_repo_issues_event_min_datetime": "2016-09-01T14:24:55.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T11:48:50.000Z", "max_forks_repo_path": "assets/source/js/Ajax/likeButton.js", "max_forks_repo_name": "ikoncept/Municipio", "max_forks_repo_forks_event_min_datetime": "2016-09-01T12:51:46.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-19T09:42:03.000Z"}
{"max_stars_count": 23, "max_issues_count": 75, "max_forks_count": 19, "avg_line_length": 25.9607843137, "max_line_length": 58, "alphanum_fraction": 0.4425981873}
var Muncipio = Muncipio || {};
Muncipio.Ajax = Muncipio.Ajax || {};

Muncipio.Ajax.LikeButton = (function($) {
    function Like() {
        this.init();
    }

    Like.prototype.init = function() {
        $('a.like-button').on(
            'click',
            function(e) {
                this.ajaxCall(e.target);
                return false;
            }.bind(this)
        );
    };

    Like.prototype.ajaxCall = function(likeButton) {
        var comment_id = $(likeButton).data('comment-id');
        var counter = $('span#like-count', likeButton);
        var button = $(likeButton);

        $.ajax({
            url: likeButtonData.ajax_url,
            type: 'post',
            data: {
                action: 'ajaxLikeMethod',
                comment_id: comment_id,
                nonce: likeButtonData.nonce,
            },
            beforeSend: function() {
                var likes = counter.html();

                if (button.hasClass('active')) {
                    likes--;
                    button.toggleClass('active');
                } else {
                    likes++;
                    button.toggleClass('active');
                }

                counter.html(likes);
            },
            success: function(response) {},
        });
    };

    return new Like();
})($);
