examples.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. $(function() {
  2. function ratingEnable() {
  3. $('#example-1to10').barrating('show', {
  4. theme: 'bars-1to10'
  5. });
  6. $('#example-movie').barrating('show', {
  7. theme: 'bars-movie'
  8. });
  9. $('#example-movie').barrating('set', 'Mediocre');
  10. $('#example-square').barrating('show', {
  11. theme: 'bars-square',
  12. showValues: true,
  13. showSelectedRating: false
  14. });
  15. $('#example-pill').barrating('show', {
  16. theme: 'bars-pill',
  17. initialRating: 'A',
  18. showValues: true,
  19. showSelectedRating: false,
  20. allowEmpty: true,
  21. emptyValue: '-- no rating selected --',
  22. onSelect: function(value, text) {
  23. alert('Selected rating: ' + value);
  24. }
  25. });
  26. $('#example-reversed').barrating('show', {
  27. theme: 'bars-reversed',
  28. showSelectedRating: true,
  29. reverse: true
  30. });
  31. $('#example-horizontal').barrating('show', {
  32. theme: 'bars-horizontal',
  33. reverse: true,
  34. hoverState: false
  35. });
  36. $('#example-fontawesome').barrating({
  37. theme: 'fontawesome-stars',
  38. showSelectedRating: false
  39. });
  40. $('#fontawesome').barrating({
  41. theme: 'fontawesome-stars',
  42. showSelectedRating: false
  43. });
  44. $('#fontawesome1').barrating({
  45. theme: 'fontawesome-stars',
  46. showSelectedRating: false
  47. });
  48. $('#fontawesome2').barrating({
  49. theme: 'fontawesome-stars',
  50. showSelectedRating: false
  51. });
  52. $('#fontawesome3').barrating({
  53. theme: 'fontawesome-stars',
  54. showSelectedRating: false
  55. });
  56. $('#fontawesome4').barrating({
  57. theme: 'fontawesome-stars',
  58. showSelectedRating: false
  59. });
  60. $('#fontawesome5').barrating({
  61. theme: 'fontawesome-stars',
  62. showSelectedRating: false
  63. });
  64. $('#fontawesome6').barrating({
  65. theme: 'fontawesome-stars',
  66. showSelectedRating: false
  67. });
  68. $('#fontawesome7').barrating({
  69. theme: 'fontawesome-stars',
  70. showSelectedRating: false
  71. });
  72. $('#fontawesome8').barrating({
  73. theme: 'fontawesome-stars',
  74. showSelectedRating: false
  75. });
  76. $('#fontawesome9').barrating({
  77. theme: 'fontawesome-stars',
  78. showSelectedRating: false
  79. });
  80. $('#example-css').barrating({
  81. theme: 'css-stars',
  82. showSelectedRating: false
  83. });
  84. $('#example-bootstrap').barrating({
  85. theme: 'bootstrap-stars',
  86. showSelectedRating: false
  87. });
  88. var currentRating = $('#example-fontawesome-o').data('current-rating');
  89. $('.stars-example-fontawesome-o .current-rating')
  90. .find('span')
  91. .html(currentRating);
  92. $('.stars-example-fontawesome-o .clear-rating').on('click', function(event) {
  93. event.preventDefault();
  94. $('#example-fontawesome-o')
  95. .barrating('clear');
  96. });
  97. $('#example-fontawesome-o').barrating({
  98. theme: 'fontawesome-stars-o',
  99. showSelectedRating: false,
  100. initialRating: currentRating,
  101. onSelect: function(value, text) {
  102. if (!value) {
  103. $('#example-fontawesome-o')
  104. .barrating('clear');
  105. } else {
  106. $('.stars-example-fontawesome-o .current-rating')
  107. .addClass('hidden');
  108. $('.stars-example-fontawesome-o .your-rating')
  109. .removeClass('hidden')
  110. .find('span')
  111. .html(value);
  112. }
  113. },
  114. onClear: function(value, text) {
  115. $('.stars-example-fontawesome-o')
  116. .find('.current-rating')
  117. .removeClass('hidden')
  118. .end()
  119. .find('.your-rating')
  120. .addClass('hidden');
  121. }
  122. });
  123. }
  124. function ratingDisable() {
  125. $('select').barrating('destroy');
  126. }
  127. $('.rating-enable').click(function(event) {
  128. event.preventDefault();
  129. ratingEnable();
  130. $(this).addClass('deactivated');
  131. $('.rating-disable').removeClass('deactivated');
  132. });
  133. $('.rating-disable').click(function(event) {
  134. event.preventDefault();
  135. ratingDisable();
  136. $(this).addClass('deactivated');
  137. $('.rating-enable').removeClass('deactivated');
  138. });
  139. ratingEnable();
  140. });