Advertisement
orksnork

Untitled

Jul 24th, 2014
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function starReplace1() {
  2.     var rateStar = $(this).attr("id");
  3.         reRatedrop();
  4.     for (i = rateStar; i > -1; i--) {
  5.         $('#' + i).removeClass('fa-star-o fa-lg');
  6.         $('#' + i).addClass('fa-star fa-2x');
  7.         }
  8.     }
  9. function starReplace2() {
  10.     var rateStar = $(this).attr("id");
  11.     for (i = rateStar; i > -2; i--) {
  12.         $('#' + i).removeClass('fa-star fa-2x');
  13.         $('#' + i).addClass('fa-star-o fa-lg');
  14.         }
  15.     reRatedrop();
  16.     reRateadd();
  17.     }  
  18.  
  19. // The default rating for the question.
  20.    
  21. rateId = 0
  22.  
  23. // function ran when CLICKING a star
  24.  
  25. function setRateid () {
  26.     rateId = $(this).attr("id");
  27. }
  28.  
  29. function reRatedrop() {
  30.     for (i = rateId; i > -1; i--) {
  31.         $('#' + i).removeClass('fa-star fa-2x');
  32.         $('#' + i).addClass('fa-star-o fa-lg');
  33.         }
  34. }
  35.  
  36. function reRateadd() {
  37.     for (j = rateId; j > -1; j--) {
  38.             $('#' + j).removeClass('fa-star-o fa-lg');
  39.             $('#' + j).addClass('fa-star fa-2x');
  40.             }
  41.         }
  42.  
  43.  
  44. function starRate() {
  45.     if (rateId < $(this).attr("id")){
  46.         rateId = $(this).attr("id");
  47.         for (i = rateId; i > -1; i--) {
  48.             $('#' + i).removeClass('fa-star-o fa-lg');
  49.             $('#' + i).addClass('fa-star fa-2x');       }
  50.         }
  51.     else if (rateId > $(this).attr("id")){
  52.         rateId = $(this).attr("id");
  53.         reRatedrop();
  54.         reRateadd();
  55.         }
  56.     else {
  57.         rateId = 0
  58.         for (i = rateId; i > -1; i--) {
  59.             reRatedrop();
  60.                     }
  61.         }      
  62. }
  63.  
  64. function writeRatingstars() {
  65.         for (i = 1; i < 6; i++) {
  66.             $('.ratings-inner').append('<i id="' + i + '" class="fa fa-star-o fa-lg ratingglow"></i>');
  67.         }
  68.     }
  69.  
  70. // on document ready
  71.  
  72. $('body').on('mouseenter', '.ratingglow', starReplace1 );
  73. $('body').on('mouseleave', '.ratingglow', starReplace2 );
  74. $('body').on('click', '.ratingglow', starRate );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement