Skip to content

Instantly share code, notes, and snippets.

@pradeeprjth
Created August 5, 2021 05:56
Show Gist options
  • Save pradeeprjth/16ca1f87e1d6c9787302c33d75abee17 to your computer and use it in GitHub Desktop.
Save pradeeprjth/16ca1f87e1d6c9787302c33d75abee17 to your computer and use it in GitHub Desktop.
$(document).on('click', '.ratenowbutton', function() {
$("#ratingModel").modal();
rating();
});
var ratedIndex = -1;
function rating(){
localStorage.removeItem('ratedIndex');
resetStarColors();
if(localStorage.getItem('ratedIndex') != null)
setStars(parseInt(localStorage.getItem('ratedIndex')));
$('.fa-star').on('click',function(){
ratedIndex = parseInt($(this).data('index'));
localStorage.setItem('ratedIndex', ratedIndex);
});
$(".fa-star").mouseover(function (){
$("#saveChanges").prop("disabled", false);
$(".ratingmsg").empty();
resetStarColors();
var currentindex = parseInt($(this).data('index'));
setStars(currentindex);
});
$(".fa-star").mouseleave(function (){
resetStarColors();
if(ratedIndex != -1)
setStars(ratedIndex);
});
function setStars(max){
for (var i=0; i <= max; i++)
$('.fa-star:eq('+i+')').css('color','orange');
}
function resetStarColors(){
$(".fa-star").css('color','black');
};
}
$('#saveChanges').on('click',function(){
if(ratedIndex != -1 && $("#reviewinput").val() != ''){
var review = $("#reviewinput").val();
var orderid = $("#orderid").val();
$.ajax({
type: "POST",
url: "URL",
data: {'rating': ratedIndex+1,
'review':review,},
headers: {
"Authorization": "Bearer " + localStorage.getItem('a_u_a_b_t')
},
success: function(data)
{
$("#ratingModel").modal('hide');
location.reload();
}
});
}else{
$("#saveChanges").prop("disabled", true);
$(".ratingmsg").html("Rating and review can't be empty");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment