Jquery raty, second click - reload

946 views Asked by At

I've created script where during click on star - record is send by ajax. And the reload action link, which reload love.raty. I wish to reload after second click on star, not on the run link. Any ideas? Thanks!

<input id="reload-function-demo" type="text" value="true" disabled="disabled" />
<a id="reload-action" href="javascript:void(0);" title="reload" class="run">run</a>

<script type="text/javascript">
    $(function() {
        $('#love').raty({
              //instructions//
            click: function(score, evt) {
                $(this).fadeOut(function() { $(this).fadeIn(); });
                var book = $('#book_id').val();
                var user = $('#user_id').val();
                var token = $('#token').val();
                var ip = $('#ip').val();
                $.ajax({
                    type: 'POST',
                    url: 'http://www.booksface.pl/content/elements/love_book_db.php',
                    data: {'score':score, 'book_id': book, 'user_id': user, 'token': token, 'ip': ip},
                    success: function(name,value,exdays) {
                    }
                });
            }
        }); 
        $('#reload-action').on('click', function() {
        $('#love').raty('click');
        $('#love').raty('reload');
      });
    });
</script>
1

There are 1 answers

0
Joe On BEST ANSWER

You could use a custom data attribute like this:

var love = $("#love");
$('#reload-action').on('click', function(){
    if(typeof love.data("clicked") === "undefined" || !love.data("clicked")){
         love.data("clicked", "true").raty('click');
    }else{
        love.data("clicked", "false").raty('reload');
    }
});

You might want to look at why you want to reload on the second click, there's probably a better way to accomplish what you want.