eimg / jquery-voter

A simple jQuery plugin to attach up/down voting facility to selected HTML elements.
10 stars 0 forks source link

How to undo an upvote/downvote? #1

Open msepahvand opened 11 years ago

msepahvand commented 11 years ago

I'm trying to develop a functionality whereby i don't allow a user to vote/undo their vote (like stackoverflow.com) if they are not logged in. I'm aware that we can attach functions to upvote/downvote events but how do we force a vote to be undone? Thanks.

eimg commented 11 years ago

Triggering click() again will do the job. Something like this:

$(selectors).attachVoter({
        "doUpVote": function(id, value) {
            $this = $(this);
            $.post("path/to/auth/check", function(data) {
                if(!data.auth) {
                    $this.trigger("click");
                }
            });
        }
});