Custom sample of paired AntLike buttons



In this example, the AntLike button are paired. On click event fired for one of these buttons. Automatically, the other is update with same value and state. To paired them I bind a second click event on both and I use the update trigger. To use Ajax and paidre, I recommand to use synchronous ajax request like this:


$(".AntLikeButton").AntLike({
    "events": {
        "onClick": { "async": false}
    }
});
            


Source Code


//classical object initialization
var $cible = $(".AntLikeButton");
$cible.AntLike({//Custom parameters
    "nbLikes": 12
});

//Adding a second click event to synchronize AntLikeButton buttons
$cible.click(function () {
    var $$ = $(this);
    //for each AntLikeButton that are not $(this), manually, I fire the AntLike.update trigger
    $("div.AntLikeButton[id!='"+$$.attr("id")+"']").each(function () {
        var val = parseInt($$.find(".AntLikeValue").text());
        $(this).trigger('AntLike.update', { "userLike": !$$.hasClass("unlike"), "nbLikes": val });
    });
});