be_comp_rating.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Document : be_comp_rating.js
  3. * Author : pixelcave
  4. * Description: Custom JS code used in Rating Page
  5. */
  6. var BeCompRating = function() {
  7. // jQuery Raty, for more examples you can check out https://github.com/wbotelhos/raty
  8. // Init Rating
  9. var initRating = function(){
  10. // Set Default options
  11. jQuery.fn.raty.defaults.starType = 'i';
  12. jQuery.fn.raty.defaults.hints = ['Just Bad!', 'Almost There!', 'It’s ok!', 'That’s nice!', 'Incredible!'];
  13. // Init Raty on .js-rating class
  14. jQuery('.js-rating').each(function(){
  15. var ratingEl = jQuery(this);
  16. ratingEl.raty({
  17. score: ratingEl.data('score') || 0,
  18. number: ratingEl.data('number') || 5,
  19. cancel: ratingEl.data('cancel') || false,
  20. target: ratingEl.data('target') || false,
  21. targetScore: ratingEl.data('target-score') || false,
  22. precision: ratingEl.data('precision') || false,
  23. cancelOff: ratingEl.data('cancel-off') || 'fa fa-fw fa-times-circle text-danger',
  24. cancelOn: ratingEl.data('cancel-on') || 'fa fa-fw fa-times-circle',
  25. starHalf: ratingEl.data('star-half') || 'fa fa-fw fa-star-half-o text-warning',
  26. starOff: ratingEl.data('star-off') || 'fa fa-fw fa-star text-muted',
  27. starOn: ratingEl.data('star-on') || 'fa fa-fw fa-star text-warning',
  28. click: function(score, evt) {
  29. // Here you could add your logic on rating click
  30. // console.log('ID: ' + this.id + "\nscore: " + score + "\nevent: " + evt);
  31. }
  32. });
  33. });
  34. };
  35. return {
  36. init: function () {
  37. // Init all Ratings
  38. initRating();
  39. }
  40. };
  41. }();
  42. // Initialize when page loads
  43. jQuery(function(){ BeCompRating.init(); });