1jQuery(document).ready(function($) { 2 var $rating = $('div.rating'); 3 var currentRating = $rating.data('rating'); 4 var hasVoted = $rating.data('voted') === 1; 5 6 $rating.find('input[name="rating"]').each(function() { 7 if ($(this).val() == currentRating) { 8 $(this).parent().addClass('selected'); 9 } 10 }); 11 12 $rating.find('input[name="rating"]').on('click', function() { 13 if (hasVoted) { 14 $('.feedback').addClass('error').html('You have already voted on this post.'); 15 return false; 16 } 17 18 var post_id = $(this).data('post'); 19 var new_rating = $(this).val(); 20 var label = $(this).parent(); 21 22 $.ajax({ 23 url: star_rating_object.rest_url || '/wp-json/sb/v1/rate', 24 type: 'post', 25 data: { 26 post_id: post_id, 27 new_rating: new_rating 28 }, 29 success: function() { 30 hasVoted = true; 31 $('.feedback').removeClass('error').addClass('success').text('Thanks for voting! Your rating: ' + new_rating); 32 label.addClass('selected'); 33 }, 34 error: function(xhr) { 35 var message = (xhr.responseJSON && xhr.responseJSON.message) || 'An error occurred while submitting your vote. (' + xhr.status + ')'; 36 if (xhr.responseJSON && xhr.responseJSON.code === 'already_voted') { 37 hasVoted = true; 38 } 39 $('.feedback').removeClass('success').addClass('error').text(message); 40 } 41 }); 42 43 return false; 44 }); 45});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.