Mint: A Fresh Look at your Site Minted
  1. 1
  2. 2 (function($){
  3. 3
  4. 4 /**
  5. 5 * AIOSRS Frontend
  6. 6 *
  7. 7 * @class WP_Schema_Pro_Frontend
  8. 8 * @since 1.0
  9. 9 */
  10. 10 WP_Schema_Pro_Frontend = {
  11. 11
  12. 12 /**
  13. 13 * Initializes a AIOSRS Frontend.
  14. 14 *
  15. 15 * @since 1.0
  16. 16 * @method init
  17. 17 */
  18. 18 container: '',
  19. 19
  20. 20
  21. 21 init: function() {
  22. 22
  23. 23 var self = this;
  24. 24 jQuery(document).on( 'click', '.aiosrs-rating-wrap .aiosrs-star-rating', function(e) {
  25. 25 e.preventDefault();
  26. 26
  27. 27 self.star_rating(this);
  28. 28 });
  29. 29
  30. 30 jQuery(document).on( 'mouseover', '.aiosrs-rating-wrap .aiosrs-star-rating', function(e) {
  31. 31 e.preventDefault();
  32. 32 self.hover_star_rating(this);
  33. 33 });
  34. 34
  35. 35 jQuery(document).on( 'mouseout', '.aiosrs-rating-wrap .aiosrs-star-rating-wrap', function(e) {
  36. 36 e.preventDefault();
  37. 37 if ( ! $(this).hasClass('disabled') ) {
  38. 38 index = parseInt( $(this).parent().find('.aiosrs-rating').text() );
  39. 39 self.update_stars( $(this), index );
  40. 40 }
  41. 41 });
  42. 42 },
  43. 43
  44. 44 hover_star_rating: function( field ) {
  45. 45 var self = this,
  46. 46 parent = $(field).closest('.aiosrs-star-rating-wrap'),
  47. 47 index = $(field).data('index');
  48. 48
  49. 49 if ( ! parent.hasClass('disabled') ) {
  50. 50 self.update_stars( parent, index );
  51. 51 }
  52. 52 },
  53. 53
  54. 54 update_stars: function( wrap, rating ) {
  55. 55
  56. 56 var filled = ( rating > 5 ) ? 5 : ( ( rating < 0 ) ? 0 : parseInt(rating) ),
  57. 57 half = ( rating == filled || rating > 5 || rating < 0 ) ? 0 : 1;
  58. 58
  59. 59 wrap.find('span').each(function(index, el) {
  60. 60 $(this).removeClass('dashicons-star-filled dashicons-star-half dashicons-star-empty');
  61. 61 if( index < filled ) {
  62. 62 $(this).addClass('dashicons-star-filled');
  63. 63 } else if( index == filled && half == 1 ) {
  64. 64 $(this).addClass('dashicons-star-half');
  65. 65 } else {
  66. 66 $(this).addClass('dashicons-star-empty');
  67. 67 }
  68. 68 });
  69. 69 },
  70. 70
  71. 71 star_rating: function( field ) {
  72. 72 var self = this,
  73. 73 schema_id = $(field).closest('.aiosrs-rating-wrap').data( 'schema-id' ),
  74. 74 parent = $(field).closest('.aiosrs-star-rating-wrap'),
  75. 75 index = $(field).data('index');
  76. 76
  77. 77 if ( ! parent.hasClass('disabled') ) {
  78. 78
  79. 79 self.update_stars( parent, index );
  80. 80 parent.addClass('disabled');
  81. 81
  82. 82 $.ajax({
  83. 83 url: AIOSRS_Frontend.ajaxurl,
  84. 84 type: 'POST',
  85. 85 data: {
  86. 86 action: 'aiosrs_user_rating',
  87. 87 rating: index,
  88. 88 schema_id: schema_id,
  89. 89 post_id: AIOSRS_Frontend.post_id,
  90. 90 nonce: AIOSRS_Frontend.user_rating_nonce
  91. 91 }
  92. 92 }).success(function( response ) {
  93. 93 if( response['success'] == true ) {
  94. 94 var summary_wrap = parent.next('.aiosrs-rating-summary-wrap'),
  95. 95 rating = response['rating'],
  96. 96 avg_rating = response['rating-avg'],
  97. 97 review_count = response['review-count'];
  98. 98
  99. 99 summary_wrap.find('.aiosrs-rating').text(avg_rating);
  100. 100 summary_wrap.find('.aiosrs-rating-count').text(review_count);
  101. 101 if( parent.next('.success-msg').length == 0 ) {
  102. 102 parent.after('<span class="success-msg">'+ AIOSRS_Frontend.success_msg +'</span>');
  103. 103 }
  104. 104 setTimeout(function(){
  105. 105 parent.parent().find('.success-msg').remove();
  106. 106 parent.removeClass('disabled');
  107. 107 }, 5000);
  108. 108 self.update_stars( parent, rating );
  109. 109 }
  110. 110 });
  111. 111 }
  112. 112 }
  113. 113 }
  114. 114
  115. 115 /* Initializes the AIOSRS Frontend. */
  116. 116 $(function(){
  117. 117
  118. 118 WP_Schema_Pro_Frontend.init();
  119. 119 });
  120. 120
  121. 121 })(jQuery);
Bookmark: javascript:location='http://shauninman.com/vs/?url='+escape(location)