PluginProbe ʕ •ᴥ•ʔ
WP Popular Posts / 4.0.1
WP Popular Posts v4.0.1
4.0.8 4.0.9 4.1.0 4.1.1 4.1.2 4.2.0 4.2.1 4.2.2 5.0.0 5.0.1 5.0.2 5.1.0 5.2.0 5.2.1 5.2.2 5.2.3 5.2.4 5.3.0 5.3.1 5.3.2 5.3.3 5.3.4 5.3.5 5.3.6 5.4.0 5.4.1 5.4.2 5.5.0 5.5.1 6.0.0 6.0.1 6.0.2 6.0.3 6.0.4 6.0.5 6.1.0 6.1.1 6.1.2 6.1.3 6.1.4 6.2.0 6.2.1 6.3.0 6.3.1 6.3.2 6.3.3 6.3.4 6.4.0 6.4.1 6.4.2 7.0.0 7.0.1 7.1.0 7.2.0 7.3.0 7.3.1 7.3.2 7.3.3 7.3.4 7.3.5 7.3.6 7.3.7 7.3.8 7.4.0 trunk 2.3.7 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.2 4.0.3 4.0.5 4.0.6
wordpress-popular-posts / admin / js / admin.js
wordpress-popular-posts / admin / js Last commit date
vendor 8 years ago admin.js 8 years ago chart.js 8 years ago
admin.js
386 lines
1 (function ($) {
2 "use strict";
3 $(function () {
4
5 // Stats config
6 $("#wpp-stats-config-btn, #wpp_stats_options .button-secondary").on("click", function(e){
7 e.preventDefault();
8
9 // Hide custom range modal box
10 if ( $("#wpp-stats-range").is(":visible") ) {
11 $("#wpp-stats-range").hide();
12 }
13
14 if ( $("#wpp-stats-config").is(":visible") ) {
15 $("#wpp-stats-config").hide();
16 }
17 else{
18 $("#wpp-stats-config").show();
19 }
20
21 });
22
23 // Stats range
24 $("#wpp-stats-range form").on('submit', function(e){
25 e.preventDefault();
26
27 if ( $("#wpp-stats-range").is(":visible") ) {
28 $("#wpp-stats-range").hide();
29 }
30
31 get_chart_data( $("#wpp-time-ranges li a[data-range='custom']") );
32
33 $(".wpp-lightbox-tabs li:eq(0) a").trigger("click");
34
35 });
36
37 $("#wpp-stats-range form .button-secondary").on('click', function(e){
38 e.preventDefault();
39
40 if ( $("#wpp-stats-range").is(":visible") ) {
41 $("#wpp-stats-range").hide();
42 }
43
44 $("#stats_range_date").val('');
45
46 $(".wpp-lightbox-tabs li:eq(0) a").trigger("click");
47
48 });
49
50 function get_chart_data( me ) {
51
52 var args = {
53 action: 'wpp_update_chart',
54 nonce: wpp_admin_params.nonce,
55 range: me.data("range"),
56 time_quantity: $("#stats_range_time_quantity").val(),
57 time_unit: $("#stats_range_time_unit").val()
58 };
59
60 if ( '' != $("#stats_range_date").val() ){
61 args.dates = $("#stats_range_date").val();
62 }
63
64 $.get(
65 ajaxurl,
66 args,
67 function( response ){
68
69 if ( 'ok' == response.status ) {
70
71 me.parent().addClass("current").siblings().removeClass("current");
72
73 var labels = [],
74 dataset_views = [],
75 dataset_comments = [];
76
77 for ( var date in response.data.dates ) {
78
79 labels.push( response.data.dates[date].nicename );
80
81 if ( !$.isEmptyObject( response.data.dates[date] ) ) {
82
83 if ( 'undefined' != typeof response.data.dates[date].views ) {
84 dataset_views.push( response.data.dates[date].views );
85 }
86 else {
87 dataset_views.push( 0 );
88 }
89
90 if ( 'undefined' != typeof response.data.dates[date].comments ) {
91 dataset_comments.push( response.data.dates[date].comments );
92 }
93 else {
94 dataset_comments.push( 0 );
95 }
96
97 }
98 else {
99 dataset_views.push( 0 );
100 dataset_comments.push( 0 );
101 }
102
103 }
104
105 // Update titles
106 $("#wpp-chart-wrapper h4").html( response.data.totals.label_summary );
107 $("#wpp-chart-wrapper h5").html( response.data.totals.label_date_range );
108
109 // Update chart
110 WPPChart.populate({
111 labels: labels,
112 datasets: [
113 {
114 label: 'Comments',
115 data: dataset_comments,
116 },
117 {
118 label: 'Views',
119 data: dataset_views,
120 },
121 ]
122 });
123
124 $("#wpp-listing .wpp-tabbed-nav li:eq(0) a").trigger("click");
125
126 // Update lists
127 args = {
128 action: 'wpp_get_most_viewed',
129 nonce: wpp_admin_params.nonce
130 };
131
132 if ( '' != $("#stats_range_date").val() ){
133 args.dates = $("#stats_range_date").val();
134 }
135
136 $.get(
137 ajaxurl,
138 args,
139 function( response ){
140 $("#wpp-listing .wpp-tab-content:eq(0)").html(response);
141 }
142 );
143
144 args = {
145 action: 'wpp_get_most_commented',
146 nonce: wpp_admin_params.nonce
147 };
148
149 if ( '' != $("#stats_range_date").val() ){
150 args.dates = $("#stats_range_date").val();
151 }
152
153 $.get(
154 ajaxurl,
155 args,
156 function( response ){
157 $("#wpp-listing .wpp-tab-content:eq(1)").html(response);
158 }
159 );
160
161 // Unset date range
162 $("#stats_range_date").val('');
163
164 }
165
166 }
167 );
168
169 }
170
171 $("#wpp-time-ranges li a").on("click", function(e){
172 e.preventDefault();
173
174 var me = $(this);
175
176 // Update chart
177 if ( WPPChart.canRender() ) {
178
179 if ( 'custom' != me.data("range") ) {
180 get_chart_data( me );
181 }
182 else {
183 // Hide Config modal box
184 if ( $("#wpp-stats-config").is(":visible") ) {
185 $("#wpp-stats-config").hide();
186 }
187
188 if ( !$("#wpp-stats-range").is(":visible") ) {
189 $("#wpp-stats-range").show();
190 }
191 }
192
193 }
194
195 });
196
197 $(".wpp-lightbox-tabs li a").on("click", function(e){
198 e.preventDefault();
199
200 var me = $(this);
201
202 me.parent().addClass("active").siblings().removeClass("active");
203
204 me.closest(".wpp-lightbox").find(".wpp-lightbox-tab-content").removeClass("wpp-lightbox-tab-content-active").filter(function( index ) {
205 return me.parent().index() == index;
206 }).addClass("wpp-lightbox-tab-content-active");
207
208 });
209
210 // Datepicker
211 $.datepicker._defaults.onAfterUpdate = null;
212 var datepicker__updateDatepicker = $.datepicker._updateDatepicker;
213
214 $.datepicker._updateDatepicker = function( instance ){
215
216 datepicker__updateDatepicker.call( this, instance );
217
218 var onAfterUpdate = this._get( instance, 'onAfterUpdate' );
219
220 if ( onAfterUpdate ) {
221 onAfterUpdate.apply( ( instance.input ? instance.input[0] : null ), [( instance.input ? instance.input.val() : '' ), instance] );
222 }
223 };
224
225 var curr = -1,
226 prev = -1;
227
228 var dp_field = $("#stats_range_date");
229
230 var wpp_datepicker = dp_field.datepicker({
231 maxDate: 0,
232 dateFormat: 'yy-mm-dd',
233 showButtonPanel: true,
234 beforeShowDay: function(date){
235 return [true, ( (date.getTime() >= Math.min(prev, curr) && date.getTime() <= Math.max(prev, curr) ) ? 'date-range-selected' : '' )]
236 },
237 onSelect: function(dateText, instance){
238
239 var d1, d2;
240
241 prev = curr;
242
243 curr = ( new Date(instance.selectedYear, instance.selectedMonth, instance.selectedDay) ).getTime();
244
245 if (
246 -1 == prev
247 || prev == curr
248 ) {
249 prev = curr;
250 dp_field.val( dateText );
251 }
252 else {
253
254 d1 = $.datepicker.formatDate('yy-mm-dd', new Date( Math.min(prev, curr) ), {});
255 d2 = $.datepicker.formatDate('yy-mm-dd', new Date( Math.max(prev, curr) ), {});
256
257 dp_field.val( d1 + ' ~ ' + d2 );
258
259 }
260
261 $(this).data('datepicker').inline = true;
262
263 },
264 onClose: function(){
265 $(this).data('datepicker').inline = false;
266 },
267 onAfterUpdate: function( instance ){
268
269 var calendar = $(this);
270
271 if (
272 prev > -1
273 && curr > -1
274 ){
275
276 $('<button type="button" class="ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all" data-handler="hide" data-event="click">OK</button>').appendTo( $(".ui-datepicker-buttonpane") ).on('click', function(){
277 dp_field.datepicker('hide');
278 });
279
280 }
281 }
282 });
283
284 // STATISTICS TABS
285 $("#wpp-listing .wpp-tabbed-nav li a").on("click", function(e){
286 e.preventDefault();
287
288 var me = $(this),
289 target = me.parent().index();
290
291 me.parent().addClass("active").siblings().removeClass("active");
292
293 me.closest("#wpp-listing").children(".wpp-tab-content:eq(" + target + ")").addClass("wpp-tab-content-active").siblings().removeClass("wpp-tab-content-active");
294
295 });
296
297 // TOOLS
298 // thumb source selection
299 $("#thumb_source").change(function() {
300 if ($(this).val() == "custom_field") {
301 $("#lbl_field, #thumb_field, #row_custom_field, #row_custom_field_resize").show();
302 } else {
303 $("#lbl_field, #thumb_field, #row_custom_field, #row_custom_field_resize").hide();
304 }
305 });
306 // file upload
307 $('#upload_thumb_button').click(function(e) {
308 tb_show('Upload a thumbnail', 'media-upload.php?referer=wpp_admin&type=image&TB_iframe=true&post_id=0', false);
309 e.preventDefault();
310 });
311 window.send_to_editor = function(html) {
312 var regex = /<img[^>]+src="(http:\/\/[^">]+)"/g;
313 var result = regex.exec(html);
314
315 if ( null != result ) {
316 $('#upload_thumb_src').val(result[1]);
317
318 var img = new Image();
319 img.onload = function() {
320 $("#thumb-review").html( this ).parent().fadeIn();
321 }
322 img.src = result[1];
323 }
324
325 tb_remove();
326 };
327 // log limit
328 $("#log_limit").change(function(){
329 var me = $(this);
330
331 if (me.val() == 1) {
332 me.parent().children("label, .description").show();
333 me.parent().children("br").hide();
334 } else {
335 me.parent().children("label, .description").hide();
336 me.parent().children("br").show();
337 }
338 });
339 // cache interval
340 $("#cache").change(function() {
341 if ($(this).val() == 1) {
342 $("#cache_refresh_interval").show();
343 } else {
344 $("#cache_refresh_interval, #cache_too_long").hide();
345 }
346 });
347 // interval
348 $("#cache_interval_time").change(function() {
349 var value = parseInt( $("#cache_interval_value").val() );
350 var time = $(this).val();
351
352 if ( time == "hour" && value > 72 ) {
353 $("#cache_too_long").show();
354 } else if ( time == "day" && value > 3 ) {
355 $("#cache_too_long").show();
356 } else if ( time == "week" && value > 1 ) {
357 $("#cache_too_long").show();
358 } else if ( time == "month" && value >= 1 ) {
359 $("#cache_too_long").show();
360 } else if ( time == "year" && value >= 1 ) {
361 $("#cache_too_long").show();
362 } else {
363 $("#cache_too_long").hide();
364 }
365 });
366
367 $("#cache_interval_value").change(function() {
368 var value = parseInt( $(this).val() );
369 var time = $("#cache_interval_time").val();
370
371 if ( time == "hour" && value > 72 ) {
372 $("#cache_too_long").show();
373 } else if ( time == "day" && value > 3 ) {
374 $("#cache_too_long").show();
375 } else if ( time == "week" && value > 1 ) {
376 $("#cache_too_long").show();
377 } else if ( time == "month" && value >= 1 ) {
378 $("#cache_too_long").show();
379 } else if ( time == "year" && value >= 1 ) {
380 $("#cache_too_long").show();
381 } else {
382 $("#cache_too_long").hide();
383 }
384 });
385 });
386 }(jQuery));