PluginProbe ʕ •ᴥ•ʔ
WP Popular Posts / 7.0.1
WP Popular Posts v7.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 / assets / js / admin.js
wordpress-popular-posts / assets / js Last commit date
blocks 2 years ago vendor 2 years ago admin-notices.js 2 years ago admin.js 2 years ago chart.js 2 years ago wpp.js 2 years ago wpp.min.js 2 years ago
admin.js
518 lines
1 (function ($) {
2 "use strict";
3 $(function () {
4
5 if ( $('#wpp-chart').length && WPPChart.canRender() ) {
6 $("#wpp-chart p").remove();
7 WPPChart.init('wpp-chart');
8 }
9
10 // Stats config
11 $("#wpp-stats-config-btn, #wpp_stats_options .button-secondary").on("click", function(e){
12 e.preventDefault();
13
14 // Hide custom range modal box
15 if ( $("#wpp-stats-range").is(":visible") ) {
16 $("#wpp-stats-range").hide();
17 }
18
19 if ( $("#wpp-stats-config").is(":visible") ) {
20 $("#wpp-stats-config").hide();
21 }
22 else{
23 $("#wpp-stats-config").show();
24 }
25 });
26
27 // Stats range
28 $("#wpp-stats-range form").on('submit', function(e){
29 e.preventDefault();
30
31 if ( $("#wpp-stats-range").is(":visible") ) {
32 $("#wpp-stats-range").hide();
33 }
34
35 get_chart_data( $("#wpp-time-ranges li a[data-range='custom']") );
36
37 $(".wpp-lightbox-tabs li:eq(0) a").trigger("click");
38 });
39
40 $("#wpp-stats-range form .button-secondary").on('click', function(e){
41 e.preventDefault();
42
43 if ( $("#wpp-stats-range").is(":visible") ) {
44 $("#wpp-stats-range").hide();
45 }
46
47 $("#stats_range_date").val('');
48
49 $(".wpp-lightbox-tabs li:eq(0) a").trigger("click");
50 });
51
52 function get_chart_data(me) {
53 var args = {
54 action: 'wpp_update_chart',
55 nonce: wpp_admin_params.nonce,
56 range: me.data("range"),
57 time_quantity: $("#stats_range_time_quantity").val(),
58 time_unit: $("#stats_range_time_unit").val()
59 };
60
61 if ( '' != $("#stats_range_date").val() ){
62 args.dates = $("#stats_range_date").val();
63 }
64
65 $.get(
66 ajaxurl,
67 args,
68 function( response ){
69 if ( 'ok' == response.status ) {
70 me.parent().addClass("current").siblings().removeClass("current");
71
72 // Update titles
73 $("#wpp-chart-wrapper h4").html( response.data.totals.label_summary );
74 $("#wpp-chart-wrapper h5").html( response.data.totals.label_date_range );
75
76 // Update chart
77 WPPChart.populate(response.data);
78
79 $("#wpp-listing .wpp-tabbed-nav li:eq(0) a").trigger("click");
80
81 // Update lists
82 args = {
83 action: 'wpp_get_most_viewed',
84 nonce: wpp_admin_params.nonce,
85 items: 'most-viewed'
86 };
87
88 if ( '' != $("#stats_range_date").val() ){
89 args.dates = $("#stats_range_date").val();
90 }
91
92 $("#wpp-listing .wpp-tab-content:eq(0)").html('<span class="spinner"></span>');
93
94 $.get(
95 ajaxurl,
96 args,
97 function( response ){
98 $("#wpp-listing .wpp-tab-content:eq(0)").html(response);
99 }
100 );
101
102 args = {
103 action: 'wpp_get_most_commented',
104 nonce: wpp_admin_params.nonce,
105 items: 'most-commented'
106 };
107
108 if ( '' != $("#stats_range_date").val() ){
109 args.dates = $("#stats_range_date").val();
110 }
111
112 $("#wpp-listing .wpp-tab-content:eq(1)").html('<span class="spinner"></span>');
113
114 $.get(
115 ajaxurl,
116 args,
117 function( response ){
118 $("#wpp-listing .wpp-tab-content:eq(1)").html(response);
119 }
120 );
121
122 args = {
123 action: 'wpp_get_trending',
124 nonce: wpp_admin_params.nonce,
125 items: 'trending'
126 };
127
128 if ( '' != $("#stats_range_date").val() ){
129 args.dates = $("#stats_range_date").val();
130 }
131
132 $("#wpp-listing .wpp-tab-content:eq(2)").html('<span class="spinner"></span>');
133
134 $.get(
135 ajaxurl,
136 args,
137 function( response ){
138 $("#wpp-listing .wpp-tab-content:eq(2)").html(response);
139 }
140 );
141
142 // Unset date range
143 $("#stats_range_date").val('');
144 }
145 }
146 );
147
148 }
149
150 $("#wpp-time-ranges li a").on("click", function(e){
151 e.preventDefault();
152
153 var me = $(this);
154
155 // Update chart
156 if ( WPPChart.canRender() ) {
157 if ( 'custom' != me.data("range") ) {
158 get_chart_data(me);
159 }
160 else {
161 // Hide Config modal box
162 if ( $("#wpp-stats-config").is(":visible") ) {
163 $("#wpp-stats-config").hide();
164 }
165
166 if ( !$("#wpp-stats-range").is(":visible") ) {
167 $("#wpp-stats-range").show();
168 }
169 }
170 }
171 });
172
173 $("#wpp-time-ranges li.current a").trigger("click");
174
175 $(".wpp-lightbox-tabs li a").on("click", function(e){
176 e.preventDefault();
177
178 var me = $(this);
179 me.parent().addClass("active").siblings().removeClass("active");
180
181 me.closest(".wpp-lightbox").find(".wpp-lightbox-tab-content").removeClass("wpp-lightbox-tab-content-active").filter(function( index ) {
182 return me.parent().index() == index;
183 }).addClass("wpp-lightbox-tab-content-active");
184 });
185
186 // Datepicker
187 $.datepicker._defaults.onAfterUpdate = null;
188 var datepicker__updateDatepicker = $.datepicker._updateDatepicker;
189
190 $.datepicker._updateDatepicker = function( instance ){
191 datepicker__updateDatepicker.call( this, instance );
192
193 var onAfterUpdate = this._get( instance, 'onAfterUpdate' );
194
195 if ( onAfterUpdate ) {
196 onAfterUpdate.apply( ( instance.input ? instance.input[0] : null ), [( instance.input ? instance.input.val() : '' ), instance] );
197 }
198 };
199
200 var curr = -1,
201 prev = -1;
202
203 var dp_field = $("#stats_range_date");
204
205 var wpp_datepicker = dp_field.datepicker({
206 maxDate: 0,
207 dateFormat: 'yy-mm-dd',
208 showButtonPanel: true,
209 beforeShowDay: function(date){
210 return [true, ( (date.getTime() >= Math.min(prev, curr) && date.getTime() <= Math.max(prev, curr) ) ? 'date-range-selected' : '' )]
211 },
212 onSelect: function(dateText, instance){
213
214 var d1, d2;
215
216 prev = curr;
217
218 curr = ( new Date(instance.selectedYear, instance.selectedMonth, instance.selectedDay) ).getTime();
219
220 if (
221 -1 == prev
222 || prev == curr
223 ) {
224 prev = curr;
225 dp_field.val( dateText );
226 }
227 else {
228
229 d1 = $.datepicker.formatDate('yy-mm-dd', new Date( Math.min(prev, curr) ), {});
230 d2 = $.datepicker.formatDate('yy-mm-dd', new Date( Math.max(prev, curr) ), {});
231
232 dp_field.val( d1 + ' ~ ' + d2 );
233
234 }
235
236 $(this).data('datepicker').inline = true;
237
238 },
239 onClose: function(){
240 $(this).data('datepicker').inline = false;
241 },
242 onAfterUpdate: function( instance ){
243 var calendar = $(this);
244
245 if (
246 prev > -1
247 && curr > -1
248 ){
249
250 $('<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(){
251 dp_field.datepicker('hide');
252 });
253 }
254 }
255 });
256
257 // STATISTICS TABS
258 $("#wpp-listing .wpp-tabbed-nav li a").on("click", function(e){
259 e.preventDefault();
260
261 var me = $(this),
262 target = me.parent().index();
263
264 me.parent().addClass("active").siblings().removeClass("active");
265
266 me.closest("#wpp-listing").children(".wpp-tab-content:eq(" + target + ")").addClass("wpp-tab-content-active").siblings().removeClass("wpp-tab-content-active");
267
268 });
269
270 // TOOLS
271 // thumb source selection
272 $("#thumb_source").change(function() {
273 if ($(this).val() == "custom_field") {
274 $("#lbl_field, #thumb_field, #row_custom_field, #row_custom_field_resize").show();
275 } else {
276 $("#lbl_field, #thumb_field, #row_custom_field, #row_custom_field_resize").hide();
277 }
278 });
279 // file upload
280 $('#upload_thumb_button').click(function(e) {
281 e.preventDefault();
282
283 var custom_uploader = wp.media({
284 title: 'WordPress Popular Posts',
285 library: { type : 'image' },
286 button: { text: wpp_admin_params.label_media_upload_button },
287 id: 'library-' + (Math.random() * 10),
288 multiple: false
289 }).on('select', function() {
290 var attachment = custom_uploader.state().get('selection').first().toJSON();
291 $('#upload_thumb_src').val( attachment.url );
292
293 var img = new Image();
294 img.onload = function() {
295 $("#thumb-review").html( this ).parent().fadeIn();
296 }
297 img.src = attachment.url;
298
299 })
300 .open();
301
302 });
303
304 $('#reset_thumb_button').on('click', function(e) {
305 e.preventDefault();
306 reset_default_thumbnail();
307 });
308
309 $('#wpp-reset-image-cache').on('click', function(e){
310 e.preventDefault();
311 confirm_clear_image_cache();
312 });
313 // log limit
314 $("#log_limit").change(function(){
315 var me = $(this);
316
317 if (me.val() == 1) {
318 me.parent().children("label, .description").show();
319 me.parent().children("br").hide();
320 } else {
321 me.parent().children("label, .description").hide();
322 me.parent().children("br").show();
323 }
324 });
325 // cache interval
326 $("#cache").change(function() {
327 if ($(this).val() == 1) {
328 $("#cache_refresh_interval").show();
329 } else {
330 $("#cache_refresh_interval, #cache_too_long").hide();
331 }
332 });
333 // interval
334 $("#cache_interval_time").change(function() {
335 var value = parseInt( $("#cache_interval_value").val() );
336 var time = $(this).val();
337
338 if ( time == "hour" && value > 72 ) {
339 $("#cache_too_long").show();
340 } else if ( time == "day" && value > 3 ) {
341 $("#cache_too_long").show();
342 } else if ( time == "week" && value > 1 ) {
343 $("#cache_too_long").show();
344 } else if ( time == "month" && value >= 1 ) {
345 $("#cache_too_long").show();
346 } else if ( time == "year" && value >= 1 ) {
347 $("#cache_too_long").show();
348 } else {
349 $("#cache_too_long").hide();
350 }
351 });
352
353 $("#cache_interval_value").change(function() {
354 var value = parseInt( $(this).val() );
355 var time = $("#cache_interval_time").val();
356
357 if ( time == "hour" && value > 72 ) {
358 $("#cache_too_long").show();
359 } else if ( time == "day" && value > 3 ) {
360 $("#cache_too_long").show();
361 } else if ( time == "week" && value > 1 ) {
362 $("#cache_too_long").show();
363 } else if ( time == "month" && value >= 1 ) {
364 $("#cache_too_long").show();
365 } else if ( time == "year" && value >= 1 ) {
366 $("#cache_too_long").show();
367 } else {
368 $("#cache_too_long").hide();
369 }
370 });
371
372 $("#wpp-reset-cache").on("click", function(e){
373 e.preventDefault();
374 confirm_reset_cache();
375 });
376
377 $("#wpp-reset-all").on("click", function(e){
378 e.preventDefault();
379 confirm_reset_all();
380 });
381 });
382
383 // TOOLS
384 function confirm_reset_cache() {
385 if ( confirm(wpp_admin_params.text_confirm_reset_cache_table + " \n\n" + wpp_admin_params.text_continue) ) {
386 jQuery.post(
387 ajaxurl,
388 {
389 action: 'wpp_clear_data',
390 token: wpp_admin_params.nonce_reset_data,
391 clear: 'cache'
392 }, function(data){
393 var response = "";
394
395 switch( data ) {
396 case "1":
397 response = wpp_admin_params.text_cache_table_cleared;
398 break;
399
400 case "2":
401 response = wpp_admin_params.text_cache_table_missing;
402 break;
403
404 case "3":
405 response = wpp_admin_params.text_invalid_action;
406 break;
407
408 case "4":
409 response = wpp_admin_params.text_insufficient_permissions;
410 break;
411
412 default:
413 response = wpp_admin_params.text_invalid_action;
414 break;
415 }
416
417 alert(response);
418 }
419 );
420 }
421 }
422
423 function confirm_reset_all() {
424 if ( confirm(wpp_admin_params.text_confirm_reset_all_tables + " \n\n" + wpp_admin_params.text_continue) ) {
425 jQuery.post(
426 ajaxurl,
427 {
428 action: 'wpp_clear_data',
429 token: wpp_admin_params.nonce_reset_data,
430 clear: 'all'
431 }, function(data){
432 var response = "";
433
434 switch( data ) {
435 case "1":
436 response = wpp_admin_params.text_all_table_cleared;
437 break;
438
439 case "2":
440 response = wpp_admin_params.text_tables_missing;
441 break;
442
443 case "3":
444 response = wpp_admin_params.text_invalid_action;
445 break;
446
447 case "4":
448 response = wpp_admin_params.text_insufficient_permissions;
449 break;
450
451 default:
452 response = wpp_admin_params.text_invalid_action;
453 break;
454 }
455
456 alert(response);
457 }
458 );
459 }
460 }
461
462 function reset_default_thumbnail() {
463 jQuery.post(
464 ajaxurl,
465 {
466 action: 'wpp_reset_thumbnail',
467 token: wpp_admin_params.nonce_reset_default_thumbnail
468 }, function(thumb_url) {
469
470 var img = new Image();
471 img.onload = function() {
472 $("#thumb-review").html( this ).parent().fadeIn();
473 }
474 img.src = thumb_url;
475
476 $('#upload_thumb_src').val(thumb_url);
477 }
478 );
479 }
480
481 function confirm_clear_image_cache() {
482 if ( confirm(wpp_admin_params.text_confirm_image_cache_reset + " \n\n" + wpp_admin_params.text_continue) ) {
483 jQuery.post(
484 ajaxurl,
485 {
486 action: 'wpp_clear_thumbnail',
487 token: wpp_admin_params.nonce_reset_thumbnails
488 }, function(data){
489 var response = "";
490
491 switch( data ) {
492 case "1":
493 response = wpp_admin_params.text_image_cache_cleared;
494 break;
495
496 case "2":
497 response = wpp_admin_params.text_image_cache_already_empty;
498 break;
499
500 case "3":
501 response = wpp_admin_params.text_invalid_action;
502 break;
503
504 case "4":
505 response = wpp_admin_params.text_insufficient_permissions;
506 break;
507
508 default:
509 response = wpp_admin_params.text_invalid_action;
510 break;
511 }
512
513 alert(response);
514 }
515 );
516 }
517 }
518 }(jQuery));