PluginProbe ʕ •ᴥ•ʔ
WP Popular Posts / 5.2.2
WP Popular Posts v5.2.2
7.4.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
vendor 6 years ago admin.js 6 years ago chart.js 6 years ago wpp.js 6 years ago wpp.min.js 6 years ago
admin.js
357 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 // Stats range
23 $("#wpp-stats-range form").on('submit', function(e){
24 e.preventDefault();
25
26 if ( $("#wpp-stats-range").is(":visible") ) {
27 $("#wpp-stats-range").hide();
28 }
29
30 get_chart_data( $("#wpp-time-ranges li a[data-range='custom']") );
31
32 $(".wpp-lightbox-tabs li:eq(0) a").trigger("click");
33 });
34
35 $("#wpp-stats-range form .button-secondary").on('click', function(e){
36 e.preventDefault();
37
38 if ( $("#wpp-stats-range").is(":visible") ) {
39 $("#wpp-stats-range").hide();
40 }
41
42 $("#stats_range_date").val('');
43
44 $(".wpp-lightbox-tabs li:eq(0) a").trigger("click");
45 });
46
47 function get_chart_data(me) {
48 var args = {
49 action: 'wpp_update_chart',
50 nonce: wpp_admin_params.nonce,
51 range: me.data("range"),
52 time_quantity: $("#stats_range_time_quantity").val(),
53 time_unit: $("#stats_range_time_unit").val()
54 };
55
56 if ( '' != $("#stats_range_date").val() ){
57 args.dates = $("#stats_range_date").val();
58 }
59
60 $.get(
61 ajaxurl,
62 args,
63 function( response ){
64 if ( 'ok' == response.status ) {
65 me.parent().addClass("current").siblings().removeClass("current");
66
67 // Update titles
68 $("#wpp-chart-wrapper h4").html( response.data.totals.label_summary );
69 $("#wpp-chart-wrapper h5").html( response.data.totals.label_date_range );
70
71 // Update chart
72 WPPChart.populate(response.data);
73
74 $("#wpp-listing .wpp-tabbed-nav li:eq(0) a").trigger("click");
75
76 // Update lists
77 args = {
78 action: 'wpp_get_most_viewed',
79 nonce: wpp_admin_params.nonce,
80 items: 'most-viewed'
81 };
82
83 if ( '' != $("#stats_range_date").val() ){
84 args.dates = $("#stats_range_date").val();
85 }
86
87 $("#wpp-listing .wpp-tab-content:eq(0)").html('<span class="spinner"></span>');
88
89 $.get(
90 ajaxurl,
91 args,
92 function( response ){
93 $("#wpp-listing .wpp-tab-content:eq(0)").html(response);
94 }
95 );
96
97 args = {
98 action: 'wpp_get_most_commented',
99 nonce: wpp_admin_params.nonce,
100 items: 'most-commented'
101 };
102
103 if ( '' != $("#stats_range_date").val() ){
104 args.dates = $("#stats_range_date").val();
105 }
106
107 $("#wpp-listing .wpp-tab-content:eq(1)").html('<span class="spinner"></span>');
108
109 $.get(
110 ajaxurl,
111 args,
112 function( response ){
113 $("#wpp-listing .wpp-tab-content:eq(1)").html(response);
114 }
115 );
116
117 args = {
118 action: 'wpp_get_trending',
119 nonce: wpp_admin_params.nonce,
120 items: 'trending'
121 };
122
123 if ( '' != $("#stats_range_date").val() ){
124 args.dates = $("#stats_range_date").val();
125 }
126
127 $("#wpp-listing .wpp-tab-content:eq(2)").html('<span class="spinner"></span>');
128
129 $.get(
130 ajaxurl,
131 args,
132 function( response ){
133 $("#wpp-listing .wpp-tab-content:eq(2)").html(response);
134 }
135 );
136
137 // Unset date range
138 $("#stats_range_date").val('');
139 }
140 }
141 );
142
143 }
144
145 $("#wpp-time-ranges li a").on("click", function(e){
146 e.preventDefault();
147
148 var me = $(this);
149
150 // Update chart
151 if ( WPPChart.canRender() ) {
152 if ( 'custom' != me.data("range") ) {
153 get_chart_data(me);
154 }
155 else {
156 // Hide Config modal box
157 if ( $("#wpp-stats-config").is(":visible") ) {
158 $("#wpp-stats-config").hide();
159 }
160
161 if ( !$("#wpp-stats-range").is(":visible") ) {
162 $("#wpp-stats-range").show();
163 }
164 }
165 }
166 });
167
168 $("#wpp-time-ranges li.current a").trigger("click");
169
170 $(".wpp-lightbox-tabs li a").on("click", function(e){
171 e.preventDefault();
172
173 var me = $(this);
174 me.parent().addClass("active").siblings().removeClass("active");
175
176 me.closest(".wpp-lightbox").find(".wpp-lightbox-tab-content").removeClass("wpp-lightbox-tab-content-active").filter(function( index ) {
177 return me.parent().index() == index;
178 }).addClass("wpp-lightbox-tab-content-active");
179 });
180
181 // Datepicker
182 $.datepicker._defaults.onAfterUpdate = null;
183 var datepicker__updateDatepicker = $.datepicker._updateDatepicker;
184
185 $.datepicker._updateDatepicker = function( instance ){
186 datepicker__updateDatepicker.call( this, instance );
187
188 var onAfterUpdate = this._get( instance, 'onAfterUpdate' );
189
190 if ( onAfterUpdate ) {
191 onAfterUpdate.apply( ( instance.input ? instance.input[0] : null ), [( instance.input ? instance.input.val() : '' ), instance] );
192 }
193 };
194
195 var curr = -1,
196 prev = -1;
197
198 var dp_field = $("#stats_range_date");
199
200 var wpp_datepicker = dp_field.datepicker({
201 maxDate: 0,
202 dateFormat: 'yy-mm-dd',
203 showButtonPanel: true,
204 beforeShowDay: function(date){
205 return [true, ( (date.getTime() >= Math.min(prev, curr) && date.getTime() <= Math.max(prev, curr) ) ? 'date-range-selected' : '' )]
206 },
207 onSelect: function(dateText, instance){
208
209 var d1, d2;
210
211 prev = curr;
212
213 curr = ( new Date(instance.selectedYear, instance.selectedMonth, instance.selectedDay) ).getTime();
214
215 if (
216 -1 == prev
217 || prev == curr
218 ) {
219 prev = curr;
220 dp_field.val( dateText );
221 }
222 else {
223
224 d1 = $.datepicker.formatDate('yy-mm-dd', new Date( Math.min(prev, curr) ), {});
225 d2 = $.datepicker.formatDate('yy-mm-dd', new Date( Math.max(prev, curr) ), {});
226
227 dp_field.val( d1 + ' ~ ' + d2 );
228
229 }
230
231 $(this).data('datepicker').inline = true;
232
233 },
234 onClose: function(){
235 $(this).data('datepicker').inline = false;
236 },
237 onAfterUpdate: function( instance ){
238 var calendar = $(this);
239
240 if (
241 prev > -1
242 && curr > -1
243 ){
244
245 $('<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(){
246 dp_field.datepicker('hide');
247 });
248 }
249 }
250 });
251
252 // STATISTICS TABS
253 $("#wpp-listing .wpp-tabbed-nav li a").on("click", function(e){
254 e.preventDefault();
255
256 var me = $(this),
257 target = me.parent().index();
258
259 me.parent().addClass("active").siblings().removeClass("active");
260
261 me.closest("#wpp-listing").children(".wpp-tab-content:eq(" + target + ")").addClass("wpp-tab-content-active").siblings().removeClass("wpp-tab-content-active");
262
263 });
264
265 // TOOLS
266 // thumb source selection
267 $("#thumb_source").change(function() {
268 if ($(this).val() == "custom_field") {
269 $("#lbl_field, #thumb_field, #row_custom_field, #row_custom_field_resize").show();
270 } else {
271 $("#lbl_field, #thumb_field, #row_custom_field, #row_custom_field_resize").hide();
272 }
273 });
274 // file upload
275 $('#upload_thumb_button').click(function(e) {
276 e.preventDefault();
277
278 var custom_uploader = wp.media({
279 title: 'WordPress Popular Posts',
280 library: { type : 'image' },
281 button: { text: wpp_admin_params.label_media_upload_button },
282 id: 'library-' + (Math.random() * 10),
283 multiple: false
284 }).on('select', function() {
285 var attachment = custom_uploader.state().get('selection').first().toJSON();
286 $('#upload_thumb_src').val( attachment.url );
287
288 var img = new Image();
289 img.onload = function() {
290 $("#thumb-review").html( this ).parent().fadeIn();
291 }
292 img.src = attachment.url;
293
294 })
295 .open();
296
297 });
298 // log limit
299 $("#log_limit").change(function(){
300 var me = $(this);
301
302 if (me.val() == 1) {
303 me.parent().children("label, .description").show();
304 me.parent().children("br").hide();
305 } else {
306 me.parent().children("label, .description").hide();
307 me.parent().children("br").show();
308 }
309 });
310 // cache interval
311 $("#cache").change(function() {
312 if ($(this).val() == 1) {
313 $("#cache_refresh_interval").show();
314 } else {
315 $("#cache_refresh_interval, #cache_too_long").hide();
316 }
317 });
318 // interval
319 $("#cache_interval_time").change(function() {
320 var value = parseInt( $("#cache_interval_value").val() );
321 var time = $(this).val();
322
323 if ( time == "hour" && value > 72 ) {
324 $("#cache_too_long").show();
325 } else if ( time == "day" && value > 3 ) {
326 $("#cache_too_long").show();
327 } else if ( time == "week" && value > 1 ) {
328 $("#cache_too_long").show();
329 } else if ( time == "month" && value >= 1 ) {
330 $("#cache_too_long").show();
331 } else if ( time == "year" && value >= 1 ) {
332 $("#cache_too_long").show();
333 } else {
334 $("#cache_too_long").hide();
335 }
336 });
337
338 $("#cache_interval_value").change(function() {
339 var value = parseInt( $(this).val() );
340 var time = $("#cache_interval_time").val();
341
342 if ( time == "hour" && value > 72 ) {
343 $("#cache_too_long").show();
344 } else if ( time == "day" && value > 3 ) {
345 $("#cache_too_long").show();
346 } else if ( time == "week" && value > 1 ) {
347 $("#cache_too_long").show();
348 } else if ( time == "month" && value >= 1 ) {
349 $("#cache_too_long").show();
350 } else if ( time == "year" && value >= 1 ) {
351 $("#cache_too_long").show();
352 } else {
353 $("#cache_too_long").hide();
354 }
355 });
356 });
357 }(jQuery));