PluginProbe
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI / 7.9.8
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI v7.9.8
8.0.4 8.0.3 8.0.1 8.0.2 8.0.0 7.9.9.7 7.9.9.6 7.9.9.5 7.9.9.4 7.9.9.3 7.9.9.2 7.9.9.1 7.9.9 7.9.8 7.9.7 7.9.6 7.9.5 7.9.4 7.9.3 7.9.2 7.9.1 7.9.0 7.8.9 7.8.8 7.8.7 All 46 releases
gamipress / assets / js / gamipress-admin-widgets.js

gamipress-admin-widgets.js in GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI 7.9.8, at assets/js/gamipress-admin-widgets.js

258 lines 10.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function($) {
2
3 var gamipress_widget_select2_users = {
4 ajax: {
5 url: ajaxurl,
6 dataType: 'json',
7 delay: 250,
8 type: 'POST',
9 data: function( params ) {
10 return {
11 q: params.term,
12 page: params.page || 1,
13 action: 'gamipress_get_users',
14 nonce: gamipress_admin_widgets.nonce,
15 };
16 },
17 processResults: gamipress_select2_users_process_results
18 },
19 escapeMarkup: function ( markup ) { return markup; }, // Let our custom formatter work
20 templateResult: gamipress_select2_users_template_result,
21 theme: 'default gamipress-select2',
22 placeholder: gamipress_admin_widgets.user_placeholder,
23 allowClear: true,
24 multiple: false
25 };
26
27 // User ajax
28 $( '#widgets-right select[id^="widget-gamipress"][id$="[user_id]"]:not(.select2-hidden-accessible)' ).gamipress_select2( gamipress_widget_select2_users );
29
30 // Current user field
31 $('body').on('change', 'input[id^="widget-gamipress"][id$="[current_user]"]', function() {
32 var target = $(this).closest('.cmb-row').next(); // User ID field
33
34 if( $(this).prop('checked') ) {
35 // Hide the target
36 target.slideUp().addClass('cmb2-tab-ignore');
37 } else {
38 if( target.closest('.cmb-tabs-wrap').length ) {
39 // Just show if item tab is active
40 if( target.hasClass('cmb-tab-active-item') ) {
41 target.slideDown();
42 }
43 } else {
44 target.slideDown();
45 }
46
47 target.removeClass('cmb2-tab-ignore');
48 }
49 });
50
51 $('input[id^="widget-gamipress"][id$="[current_user]"]').trigger('change');
52
53 // Earners user field
54 $('body').on('change', 'input[id^="widget-gamipress"][id$="[earners]"]', function() {
55 var target = $(this).closest('.cmb-row').next(); // Earners limit field
56
57 if( ! $(this).prop('checked') ) {
58 // Hide the target
59 target.slideUp().addClass('cmb2-tab-ignore');
60 } else {
61 if( target.closest('.cmb-tabs-wrap').length ) {
62 // Just show if item tab is active
63 if( target.hasClass('cmb-tab-active-item') ) {
64 target.slideDown();
65 }
66 } else {
67 target.slideDown();
68 }
69
70 target.removeClass('cmb2-tab-ignore');
71 }
72 });
73
74 $('input[id^="widget-gamipress"][id$="[earners]"]').trigger('change');
75
76 // Period field
77 $('body').on('change', 'select[id^="widget-gamipress_points"][id$="[period]"], ' +
78 'select[id^="widget-gamipress_user_points"][id$="[period]"], ' +
79 'select[id^="widget-gamipress_site_points"][id$="[period]"]', function() {
80 // Get the period start and end fields
81 var target = $(this).closest('.cmb2-wrap').find(
82 '.cmb-row[class*="period-start"], '
83 + '.cmb-row[class*="period-end"]'
84 );
85
86 if( $(this).val() !== 'custom' ) {
87 // Hide the target
88 target.slideUp().addClass('cmb2-tab-ignore');
89 } else {
90 // Show the target
91 target.slideDown().removeClass('cmb2-tab-ignore');
92 }
93 });
94
95 $('select[id^="widget-gamipress_points"][id$="[period]"]').trigger('change');
96 $('select[id^="widget-gamipress_user_points"][id$="[period]"]').trigger('change');
97 $('select[id^="widget-gamipress_site_points"][id$="[period]"]').trigger('change');
98
99 // Inline field
100 $('body').on('change', 'input[id^="widget-gamipress_points"][id$="[inline]"], ' +
101 'input[id^="widget-gamipress_user_points"][id$="[inline]"], ' +
102 'input[id^="widget-gamipress_site_points"][id$="[inline]"]', function() {
103 // Get the columns and layout fields
104 var target = $(this).closest('.cmb2-wrap').find(
105 '.cmb-row[class*="columns"], '
106 + '.cmb-row[class*="layout"]'
107 );
108
109 if( $(this).prop('checked') ) {
110 target.slideUp().addClass('cmb2-tab-ignore');
111 } else {
112 target.slideDown().removeClass('cmb2-tab-ignore');
113 }
114 });
115
116 // User earnings
117 $('body').on('change', 'input[id^="widget-gamipress_earnings"][id$="[points]"], '
118 + 'input[id^="widget-gamipress_earnings"][id$="[achievements]"], '
119 + 'input[id^="widget-gamipress_earnings"][id$="[ranks]"]', function() {
120
121 var id_parts = $(this).attr('id').split('[');
122 var id = id_parts[id_parts.length - 1].replace(']', '');
123 var n = $(this).closest('form').find('input[name="widget_number"]').val();
124 var target = undefined;
125
126 if( id === 'points' ) {
127 target = $('.cmb2-id-widget-gamipress-earnings-widget' + n + 'points-types, .cmb2-id-widget-gamipress-earnings-widget' + n + 'awards, .cmb2-id-widget-gamipress-earnings-widget' + n + 'deducts');
128 } else if( id === 'achievements' ) {
129 target = $('.cmb2-id-widget-gamipress-earnings-widget' + n + 'achievement-types, .cmb2-id-widget-gamipress-earnings-widget' + n + 'steps');
130 } else if( id === 'ranks' ) {
131 target = $('.cmb2-id-widget-gamipress-earnings-widget' + n + 'rank-types, .cmb2-id-widget-gamipress-earnings-widget' + n + 'rank-requirements');
132 }
133
134 if( $(this).prop('checked') ) {
135 // Just show if current tab active is ours
136 if( $(this).closest('.cmb-tabs-wrap').find('.cmb-tab.active[id$="[' + id + ']"]').length ) {
137 target.slideDown();
138 }
139
140 target.removeClass('cmb2-tab-ignore');
141 } else {
142 target.slideUp().addClass('cmb2-tab-ignore');
143 }
144 });
145
146 $('input[id^="widget-gamipress_earnings"][id$="[points]"], '
147 + 'input[id^="widget-gamipress_earnings"][id$="[achievements]"], '
148 + 'input[id^="widget-gamipress_earnings"][id$="[ranks]"]').trigger('change');
149
150 // Initialize on widgets area
151 $(document).on('widget-updated widget-added', function(e, widget) {
152
153 // User ajax
154 widget.find( 'select[id^="widget-gamipress"][id$="[user_id]"]:not(.select2-hidden-accessible)' ).gamipress_select2( gamipress_widget_select2_users );
155
156 // Current user field
157 var current_user = widget.find( 'input[id^="widget-gamipress"][id$="[current_user]"]');
158 var current_user_target = current_user.closest('.cmb-row').next(); // User ID field
159
160 if( current_user.prop('checked') ) {
161 current_user_target.hide().addClass('cmb2-tab-ignore');
162 } else {
163 if( current_user_target.closest('.cmb-tabs-wrap').length ) {
164 // Just show if item tab is active
165 if( current_user_target.hasClass('cmb-tab-active-item') ) {
166 current_user_target.show();
167 }
168 } else {
169 current_user_target.show();
170 }
171
172 current_user_target.removeClass('cmb2-tab-ignore');
173 }
174
175 // Earners field
176 var earners = widget.find( 'input[id^="widget-gamipress"][id$="[earners]"]');
177 var earners_target = earners.closest('.cmb-row').next(); // Earners limit field
178
179 if( ! earners.prop('checked') ) {
180 earners_target.hide().addClass('cmb2-tab-ignore');
181 } else {
182 if( earners_target.closest('.cmb-tabs-wrap').length ) {
183 // Just show if item tab is active
184 if( earners_target.hasClass('cmb-tab-active-item') ) {
185 earners_target.show();
186 }
187 } else {
188 earners_target.show();
189 }
190
191 earners_target.removeClass('cmb2-tab-ignore');
192 }
193
194 // Period field
195 var period = widget.find( 'input[id^="widget-gamipress_points"][id$="[period]"], ' +
196 'input[id^="widget-gamipress_user_points"][id$="[period]"], ' +
197 'input[id^="widget-gamipress_site_points"][id$="[period]"]');
198
199 // Get the period start and end fields
200 var period_target = period.closest('.cmb2-wrap').find(
201 '.cmb-row[class*="period-start"], '
202 + '.cmb-row[class*="period-end"]'
203 );
204
205 if( period.val() !== 'custom' ) {
206 period_target.hide().addClass('cmb2-tab-ignore');
207 } else {
208 period_target.show().removeClass('cmb2-tab-ignore');
209 }
210
211 // Inline field
212 var inline = widget.find( 'input[id^="widget-gamipress_points"][id$="[inline]"], ' +
213 'input[id^="widget-gamipress_user_points"][id$="[inline]"], ' +
214 'input[id^="widget-gamipress_site_points"][id$="[inline]"]');
215
216 // Get the columns and layout fields
217 var inline_target = inline.closest('.cmb2-wrap').find(
218 '.cmb-row[class*="columns"], '
219 + '.cmb-row[class*="layout"]'
220 );
221
222 if( inline.prop('checked') ) {
223 inline_target.hide().addClass('cmb2-tab-ignore');
224 } else {
225 inline_target.show().removeClass('cmb2-tab-ignore');
226 }
227
228 // User earnings
229 widget.find('change', 'input[id^="widget-gamipress_earnings"][id$="[points]"], '
230 + 'input[id^="widget-gamipress_earnings"][id$="[achievements]"], '
231 + 'input[id^="widget-gamipress_earnings"][id$="[ranks]"]').each(function() {
232
233 var id_parts = $(this).attr('id').split('[');
234 var id = id_parts[id_parts.length - 1].replace(']', '');
235 var n = $(this).closest('form').find('input[name="widget_number"]').val();
236 var target = undefined;
237
238 if( id === 'points' ) {
239 target = $('.cmb2-id-widget-gamipress-earnings-widget' + n + 'points-types, .cmb2-id-widget-gamipress-earnings-widget' + n + 'awards, .cmb2-id-widget-gamipress-earnings-widget' + n + 'deducts');
240 } else if( id === 'achievements' ) {
241 target = $('.cmb2-id-widget-gamipress-earnings-widget' + n + 'achievement-types, .cmb2-id-widget-gamipress-earnings-widget' + n + 'steps');
242 } else if( id === 'ranks' ) {
243 target = $('.cmb2-id-widget-gamipress-earnings-widget' + n + 'rank-types, .cmb2-id-widget-gamipress-earnings-widget' + n + 'rank-requirements');
244 }
245
246 if( $(this).prop('checked') ) {
247 // Just show if current tab active is ours
248 if( $(this).closest('.cmb-tabs-wrap').find('.cmb-tab.active[id$="[' + id + ']"]').length ) {
249 target.slideDown();
250 }
251
252 target.removeClass('cmb2-tab-ignore');
253 } else {
254 target.slideUp().addClass('cmb2-tab-ignore');
255 }
256 });
257 });
258 })(jQuery);