Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In its current setup, the <code>set_votes(widget)</code> method does not <em>know</em>, whether the user actually voted.<br> You can add this quite easily by modifying your 'click' event handler and adding a piece of data in your AJAX success callback:</p> <pre><code>... function(INFO) { widget.data( 'fsr', INFO ); // Add user's voting to data: widget.data('fsr').own_voting = count; set_votes(widget); $('#msg').hide().html("you have rated this product with "+count+" stars.").fadeIn(1500); //alert("you have rated this product with"+count); } ... </code></pre> <p>Then, you have to also modify the <code>set_votes(widget)</code> method to use this information:</p> <pre><code>function set_votes(widget) { var avg = $(widget).data('fsr').whole_avg; var votes = $(widget).data('fsr').number_votes; var exact = $(widget).data('fsr').dec_avg; var own = $(widget).data('fsr').own_voting; // set voting to own if it is defined, else to avg // also set class to distinguish avg from own if(typeof own != 'undefined') { voting = own; class = 'ratings_over'; } else { voting = avg; class = 'ratings_vote'; } window.console &amp;&amp; console.log('and now in set_votes, it thinks the fsr is ' + $(widget).data('fsr').number_votes); // replaced avg with voting // remove all classes to make sure nothing bugs $(widget).find('.star_' + voting).nextAll() .removeClass('ratings_vote').removeClass('ratings_over'); $(widget).find('.star_' + voting).prevAll().andSelf() .removeClass('ratings_vote').removeClass('ratings_over').addClass(class); $(widget).find('.total_votes').text( votes + ' votes recorded (' + exact + ' rating)' ); } </code></pre> <p>I'm not really familiar with JS, so the <code>undefined</code> part might be wrong - but AFAIK it should work like this.</p> <hr> <p>If you want the widget to display the user's voting even after the page has been reloaded, you will have to add the <code>own_voting</code> field to your server's response to the fetching AJAX call.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload