rating.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. var $stars;
  2. jQuery(document).ready(function ($) {
  3. // Custom whitelist to allow for using HTML tags in popover content
  4. var myDefaultWhiteList = $.fn.tooltip.Constructor.Default.whiteList
  5. myDefaultWhiteList.textarea = [];
  6. myDefaultWhiteList.button = [];
  7. $stars = $('.rate-popover');
  8. $stars.on('mouseover', function () {
  9. var index = $(this).attr('data-index');
  10. markStarsAsActive(index);
  11. });
  12. function markStarsAsActive(index) {
  13. unmarkActive();
  14. for (var i = 0; i <= index; i++) {
  15. $($stars.get(i)).addClass('amber-text');
  16. }
  17. }
  18. function unmarkActive() {
  19. $stars.removeClass('amber-text');
  20. }
  21. $stars.on('click', function () {
  22. $stars.popover('hide');
  23. });
  24. // Submit, you can add some extra custom code here
  25. // ex. to send the information to the server
  26. $('#rateMe').on('click', '#voteSubmitButton', function () {
  27. $stars.popover('hide');
  28. });
  29. // Cancel, just close the popover
  30. $('#rateMe').on('click', '#closePopoverButton', function () {
  31. $stars.popover('hide');
  32. });
  33. });
  34. $(function () {
  35. $('.rate-popover').popover({
  36. // Append popover to #rateMe to allow handling form inside the popover
  37. container: '#rateMe',
  38. // Custom content for popover
  39. content: `<div class="my-0 py-0"> <textarea type="text" style="font-size: 0.78rem" class="md-textarea form-control py-0" placeholder="Write us what can we improve" rows="3"></textarea> <button id="voteSubmitButton" type="submit" class="btn btn-sm btn-primary">Submit!</button> <button id="closePopoverButton" class="btn btn-flat btn-sm">Close</button> </div>`
  40. });
  41. $('.rate-popover').tooltip();
  42. });