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