PluginProbe
Code Profiler – WordPress Performance Profiling and Debugging Made Easy / 1.6
Code Profiler – WordPress Performance Profiling and Debugging Made Easy v1.6
1.9.5 1.9.4 1.9.3 trunk 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.6 1.6.1 1.6.10 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 All 40 releases
← All changes | static/code-profiler.js +147 -48 1.51.6 View file →
@@ -15,9 +15,9 @@
15 15
16 16 // TipTip tooltip
17 17 jQuery( document ).ready(function( $ ) {
18 18 'use strict';
19 - $( '.code-profiler-tip' ).tipTip( {
19 + $('.code-profiler-tip').tipTip( {
20 20 'attribute': 'data-tip',
21 21 'fadeIn': 50,
22 22 'fadeOut': 50,
23 23 'delay': 100,
@@ -28,9 +28,9 @@
28 28 // if the user reloaded the page that would throw an error:
29 29 var url = window.location.href;
30 30 window.history.replaceState({},
31 31 document.title,
32 - url.replace( /&action=delete_profiles&.+/, '' )
32 + url.replace( /&action=delete_profiles&.+/, '')
33 33 );
34 34
35 35 });
36 36
@@ -44,21 +44,21 @@
44 44 // Case sensitivity
45 45 if ( jQuery('#case-search-input').is(':checked') === true ) {
46 46 query += '&c=1';
47 47 }
48 - jQuery("#profile-form").attr('action', jQuery("#profile-form").attr('action')+ query );
48 + jQuery('#profile-form').attr('action', jQuery('#profile-form').attr('action')+ query );
49 49
50 50 } else {
51 - jQuery("#profile-form").attr('action','' );
51 + jQuery('#profile-form').attr('action','');
52 52 var url = window.location.href;
53 53 window.history.replaceState({},
54 54 document.title,
55 - url.replace( /&s=[^&$]+/, '' )
55 + url.replace( /&s=[^&$]+/, '')
56 56 );
57 57 var url = window.location.href;
58 58 window.history.replaceState({},
59 59 document.title,
60 - url.replace( /&c=1/, '' )
60 + url.replace( /&c=1/, '')
61 61 );
62 62 }
63 63 }
64 64
@@ -81,9 +81,9 @@
81 81 jQuery('#p-custom').hide();
82 82 jQuery('#id-backend').focus();
83 83 jQuery('#user-unauthenticated').prop('disabled', true);
84 84 jQuery('#user-authenticated').prop('checked', true);
85 - jQuery("#user-name").prop('disabled', false);
85 + jQuery('#user-name').prop('disabled', false);
86 86 } else {
87 87 jQuery('#p-custom').show();
88 88 jQuery('#p-frontend').hide();
89 89 jQuery('#p-backend').hide();
@@ -93,26 +93,26 @@
93 93 }
94 94
95 95 function cpjs_authenticated( id ) {
96 96 if ( id == 1 ) {
97 - jQuery("#user-name").prop('disabled', false);
98 - jQuery("#user-name").focus();
97 + jQuery('#user-name').prop('disabled', false);
98 + jQuery('#user-name').focus();
99 99 } else {
100 - jQuery("#user-name").prop('disabled', true);
100 + jQuery('#user-name').prop('disabled', true);
101 101 }
102 102 }
103 103
104 104 function cpjs_show_adv_settings() {
105 - jQuery("#cp-advanced-settings").slideDown();
106 - jQuery("#button-adv-settings").prop('disabled', true);
105 + jQuery('#cp-advanced-settings').slideDown();
106 + jQuery('#button-adv-settings').prop('disabled', true);
107 107 }
108 108
109 109 function cpjs_get_post( id ) {
110 110 if ( id == 1 ) {
111 - jQuery("#post-value").prop('disabled', false);
112 - jQuery("#post-value").focus();
111 + jQuery('#post-value').prop('disabled', false);
112 + jQuery('#post-value').focus();
113 113 } else {
114 - jQuery("#post-value").prop('disabled', true);
114 + jQuery('#post-value').prop('disabled', true);
115 115 }
116 116 }
117 117
118 118 // =====================================================================
@@ -124,8 +124,9 @@
124 124 var bitmask = 0;
125 125 if ( document.cplogform.info.checked == true ) { bitmask += 1; }
126 126 if ( document.cplogform.warn.checked == true ) { bitmask += 2; }
127 127 if ( document.cplogform.error.checked == true ) { bitmask += 4; }
128 + if ( document.cplogform.debug.checked == true ) { bitmask += 8; }
128 129
129 130 // Clear the textarea
130 131 document.cplogform.cptxtlog.value = '';
131 132
@@ -133,9 +134,9 @@
133 134 var cp_count = 0;
134 135 var i = 0;
135 136 for ( i = 0; i < cplog_array.length; ++i ) {
136 137 var line = decodeURIComponent( cplog_array[i] );
137 - var line_array = line.split( '~~', 2 );
138 + var line_array = line.split('~~', 2 );
138 139 if ( line_array[0] & bitmask ) {
139 140 document.cplogform.cptxtlog.value += line_array[1];
140 141 ++cp_count;
141 142 }
@@ -158,9 +159,9 @@
158 159 function cpjs_start_profiler() {
159 160 'use strict';
160 161 // Get the nonce
161 162 var cp_nonce = jQuery('#cp_nonce').val();
162 - if ( cp_nonce == '' ) {
163 + if ( cp_nonce == '') {
163 164 alert( cpi18n.missing_nonce );
164 165 return;
165 166 }
166 167
@@ -166,15 +167,15 @@
166 167
167 168 // Get the scan type (frontend/backend)
168 169 var post;
169 170 var where = jQuery('input[name="where"]:checked').val();
170 - if ( where == 'frontend' ) {
171 + if ( where == 'frontend') {
171 172 post = jQuery('#id-frontend').val();
172 173
173 - } else if ( where == 'backend' ) {
174 + } else if ( where == 'backend') {
174 175 post = jQuery('#id-backend').val();
175 176
176 - } else if ( where == 'custom' ) {
177 + } else if ( where == 'custom') {
177 178 post = jQuery('#id-custom').val().trim(); // Trim user input
178 179
179 180 } else {
180 181 alert( cpi18n.missing_frontbackend );
@@ -179,9 +180,9 @@
179 180 } else {
180 181 alert( cpi18n.missing_frontbackend );
181 182 return;
182 183 }
183 - if ( post == '' ) {
184 + if ( post == '') {
184 185 alert( cpi18n.missing_post );
185 186 return;
186 187 }
187 188
@@ -186,9 +187,9 @@
186 187 }
187 188
188 189 // Get the profile's name
189 190 var profile = jQuery('input[name="profile"]').val();
190 - if ( profile == '' ) {
191 + if ( profile == '') {
191 192 alert( cpi18n.missing_profilename );
192 193 jQuery('input[name="profile"]').focus();
193 194 return;
194 195 }
@@ -193,16 +194,16 @@
193 194 return;
194 195 }
195 196
196 197 var user = jQuery('input[name="user"]:checked').val();
197 - if ( user == '' ) {
198 + if ( user == '') {
198 199 alert( cpi18n.missing_userauth );
199 200 return;
200 201 }
201 202
202 203 var username = jQuery('#user-name').val().trim(); // Trim user input
203 - if ( user == 'authenticated' ) {
204 - if ( username == '' ) {
204 + if ( user == 'authenticated') {
205 + if ( username == '') {
205 206 alert( cpi18n.missing_username );
206 207 jQuery('#user-name').focus();
207 208 return;
208 209 }
@@ -208,9 +209,9 @@
208 209 }
209 210 }
210 211
211 212 var ua = jQuery('#ua-id').val();
212 - if ( ua == 'undefined' ) {
213 + if ( ua == 'undefined') {
213 214 ua = 'FireFox';
214 215 }
215 216
216 217 // GET or POST
@@ -215,9 +216,9 @@
215 216
216 217 // GET or POST
217 218 var method = jQuery('input[name="method"]:checked').val();
218 219 var payload = '';
219 - if ( method == 'post' ) {
220 + if ( method == 'post') {
220 221 // Payload
221 222 payload = jQuery('#post-value').val();
222 223 } else {
223 224 method = 'get';
@@ -247,9 +248,9 @@
247 248 'ua': ua
248 249 };
249 250 // Send the request via AJAX
250 251 jQuery.ajax( {
251 - type: "POST",
252 + type: 'POST',
252 253 url: ajaxurl,
253 254 data: data,
254 255 dataType: 'json',
255 256 success: function( response ) {
@@ -254,14 +255,14 @@
254 255 dataType: 'json',
255 256 success: function( response ) {
256 257
257 258 if (typeof response === 'undefined') {
258 - cpjs_start_error( '<p>'+ cpi18n.unknown_error +'</p>' );
259 + cpjs_start_error('<p>'+ cpi18n.unknown_error +'</p>');
259 260 return;
260 261 }
261 262
262 - if ( response.status != 'success' ) {
263 - cpjs_start_error( '<p>'+ response.message +'</p>' );
263 + if ( response.status != 'success') {
264 + cpjs_start_error('<p>'+ response.message +'</p>');
264 265 return;
265 266 }
266 267
267 268 // ------------------------------------------------------------
@@ -271,9 +272,9 @@
271 272
272 273 data['action'] = 'codeprofiler_prepare_report';
273 274 data['microtime'] = response.microtime;
274 275 jQuery.ajax( {
275 - type: "POST",
276 + type: 'POST',
276 277 url: ajaxurl,
277 278 data: data,
278 279 dataType: 'json',
279 280 success: function( response ) {
@@ -278,18 +279,18 @@
278 279 dataType: 'json',
279 280 success: function( response ) {
280 281
281 282 if (typeof response === 'undefined') {
282 - cpjs_start_error( '<p>'+ cpi18n.unknown_error +'</p>' );
283 + cpjs_start_error('<p>'+ cpi18n.unknown_error +'</p>');
283 284 return;
284 285 }
285 286
286 - if ( response.status != 'success' ) {
287 - cpjs_start_error( '<p>'+ response.message +'</p>' );
287 + if ( response.status != 'success') {
288 + cpjs_start_error('<p>'+ response.message +'</p>');
288 289 return;
289 290 }
290 291 var cp_uri;
291 - if (response.cp_profile !== 'undefined' && response.cp_profile != '' ) {
292 + if (response.cp_profile !== 'undefined' && response.cp_profile != '') {
292 293 cp_uri = '&cptab=profiles_list&action=view_profile&id=' + response.cp_profile + '&section=1';
293 294 } else {
294 295 cp_uri = '&cptab=profiles_list';
295 296 }
@@ -302,9 +303,9 @@
302 303 },
303 304
304 305 // Display non-200 HTTP response
305 306 error: function( xhr, status, err ) {
306 - if ( err != '' ) {
307 + if ( err != '') {
307 308 if ( xhr.status != 0 ) {
308 309 var message = cpi18n.http_error +' '+ xhr.status +' '+ err;
309 310 // Timeout
310 311 if ( xhr.status == 503 || xhr.status == 504 ) {
@@ -316,16 +317,16 @@
316 317 } else if ( xhr.status == 403 ) {
317 318 cpjs_start_error('<p>'+ message +'<br />'+ cpi18n.forbidden_error +'.</p>');
318 319 // Internal error
319 320 } else if ( xhr.status == 500 ) {
320 - cpjs_start_error('<p>'+ message +'<br />'+ cpi18n.internal_error +'.</p>');
321 + cpjs_start_error('<p>'+ message +'<br />'+ cpi18n.internal_error +'.<br />'+ cpi18n.timeout_error +'.</p>');
321 322 } else {
322 - cpjs_start_error( '<p>'+ cpi18n.http_error +' '+ xhr.status +' '+ err +'.</p>' );
323 + cpjs_start_error('<p>'+ cpi18n.http_error +' '+ xhr.status +' '+ err +'.</p>');
323 324 }
324 325 return;
325 326
326 327 } else {
327 - cpjs_start_error( '<p>'+ cpi18n.unknown_error +' '+ err +'.</p>' );
328 + cpjs_start_error('<p>'+ cpi18n.unknown_error +' '+ err +'.</p>');
328 329 return;
329 330 }
330 331 }
331 332 return;
@@ -335,9 +336,9 @@
335 336 },
336 337
337 338 // Display non-200 HTTP response
338 339 error: function( xhr, status, err ) {
339 - if ( err != '' ) {
340 + if ( err != '') {
340 341 if ( xhr.status != 0 ) {
341 342 var message = cpi18n.http_error +' '+ xhr.status +' '+ err;
342 343 // Timeout
343 344 if ( xhr.status == 503 || xhr.status == 504 ) {
@@ -349,16 +350,16 @@
349 350 } else if ( xhr.status == 403 ) {
350 351 cpjs_start_error('<p>'+ message +'<br />'+ cpi18n.forbidden_error +'.</p>');
351 352 // Internal error
352 353 } else if ( xhr.status == 500 ) {
353 - cpjs_start_error('<p>'+ message +'<br />'+ cpi18n.internal_error +'.</p>');
354 + cpjs_start_error('<p>'+ message +'<br />'+ cpi18n.internal_error +'.<br />'+ cpi18n.timeout_error +'.</p>');
354 355 } else {
355 - cpjs_start_error( '<p>'+ cpi18n.http_error +' '+ xhr.status +' '+ err +'.</p>' );
356 + cpjs_start_error('<p>'+ cpi18n.http_error +' '+ xhr.status +' '+ err +'.</p>');
356 357 }
357 358 return;
358 359
359 360 } else {
360 - cpjs_start_error( '<p>'+ cpi18n.unknown_error +' '+ err +'.</p>' );
361 + cpjs_start_error('<p>'+ cpi18n.unknown_error +' '+ err +'.</p>');
361 362 return;
362 363 }
363 364 }
364 365 return;
@@ -389,8 +390,106 @@
389 390 }
390 391 return false;
391 392 }
392 393
394 +// Hide/show the edit box and buttons when renaming a profile.
395 +function cpjs_toggle_name( row ) {
396 + if ( jQuery('#profile_div_'+ row).css('display') == 'none') {
397 + jQuery('#profile_name_'+ row).hide();
398 + jQuery('#profile_div_'+ row).show();
399 + jQuery('#edit-'+ row).val( jQuery('#profile_name_'+ row).html() );
400 + jQuery('#edit-'+ row).focus();
401 + } else {
402 + jQuery('#profile_div_'+ row).hide();
403 + jQuery('#profile_name_'+ row).show();
404 + }
405 +}
406 +
407 +// Edit the profile name via AJAX endpoint.
408 +function cpjs_edit_name( profile, id, cp_nonce, row ) {
409 +
410 + 'use strict';
411 +
412 + if ( cp_nonce == '') {
413 + alert( cpi18n.missing_nonce );
414 + return;
415 + }
416 + if ( profile == '') {
417 + alert( cpi18n.missing_profileid );
418 + return;
419 + }
420 +
421 + var new_name = jQuery('#edit-'+ id).val().trim();
422 + if ( new_name == '') {
423 + alert( cpi18n.missing_profilename );
424 + return;
425 + }
426 +
427 + jQuery('#profile_spinner_'+ row).addClass('is-active');
428 +
429 + var data = {
430 + 'action': 'codeprofiler_rename',
431 + 'cp_nonce': cp_nonce,
432 + 'new_name': new_name,
433 + 'profile': profile,
434 + };
435 +
436 + // Send the request via AJAX
437 + jQuery.ajax( {
438 + type: 'POST',
439 + url: ajaxurl,
440 + data: data,
441 + dataType: 'json',
442 + success: function( response ) {
443 + jQuery('#profile_spinner_'+ row ).removeClass('is-active');
444 +
445 + if (typeof response === 'undefined') {
446 + alert( cpi18n.unknown_error );
447 + return;
448 + }
449 +
450 + if ( response.status != 'success') {
451 + alert( response.message );
452 + return;
453 + }
454 +
455 + // Success: update the name in the table
456 + jQuery('#profile_name_'+ id).html( response.newname );
457 + cpjs_toggle_name(row);
458 + },
459 + // Display non-200 HTTP response
460 + error: function( xhr, status, err ) {
461 + jQuery('#profile_spinner_'+ row ).removeClass('is-active');
462 + if ( err != '') {
463 + if ( xhr.status != 0 ) {
464 + var message = cpi18n.http_error +' '+ xhr.status +' '+ err;
465 + // Timeout
466 + if ( xhr.status == 503 || xhr.status == 504 ) {
467 + alert( message +'<br />'+ cpi18n.timeout_error );
468 + // Redirections, not found
469 + } else if ( xhr.status == 301 || xhr.status == 302 || xhr.status == 404 ) {
470 + alert( message +'<br />'+ cpi18n.notfound_error );
471 + // Forbidden
472 + } else if ( xhr.status == 403 ) {
473 + alert( message +'<br />'+ cpi18n.forbidden_error );
474 + // Internal error
475 + } else if ( xhr.status == 500 ) {
476 + alert( message +'<br />'+ cpi18n.internal_error +'.<br />'+ cpi18n.timeout_error );
477 + } else {
478 + alert( cpi18n.http_error +' '+ xhr.status +' '+ err );
479 + }
480 + return;
481 +
482 + } else {
483 + alert( cpi18n.unknown_error +' '+ err );
484 + return;
485 + }
486 + }
487 + return;
488 + }
489 + });
490 +}
491 +
393 492 // =====================================================================
394 493 // Plugins/Theme chart.
395 494
396 495 function cpjs_plugins_chart( caxis, clabel, cdata, ctotal_time ) {
@@ -397,9 +496,9 @@
397 496 'use strict';
398 497 // Switch between vertical and horizontal bars
399 498 var _indexAxis = caxis;
400 499 document.getElementById('htov').onclick = function() {
401 - if ( _indexAxis == 'x' ) {
500 + if ( _indexAxis == 'x') {
402 501 _indexAxis = 'y';
403 502 } else {
404 503 _indexAxis = 'x';
405 504 }
@@ -438,9 +537,9 @@
438 537 const total_time = ctotal_time;
439 538 const footer = (tooltipItems) => {
440 539 var sum;
441 540 tooltipItems.forEach(function(tooltipItem) {
442 - if ( _indexAxis == 'x' ) {
541 + if ( _indexAxis == 'x') {
443 542 sum = Math.round( ( tooltipItem.parsed.y / total_time ) * 100 );
444 543 } else {
445 544 sum = Math.round( ( tooltipItem.parsed.x / total_time ) * 100 );
446 545 }
@@ -511,9 +610,9 @@
511 610 'use strict';
512 611 // Switch between vertical and horizontal bars
513 612 var _indexAxis = caxis;
514 613 document.getElementById('htov').onclick = function() {
515 - if ( _indexAxis == 'x' ) {
614 + if ( _indexAxis == 'x') {
516 615 _indexAxis = 'y';
517 616 } else {
518 617 _indexAxis = 'x';
519 618 }
@@ -612,9 +711,9 @@
612 711 'use strict';
613 712 // Switch between vertical and horizontal bars
614 713 var _indexAxis = caxis;
615 714 document.getElementById('htov').onclick = function() {
616 - if ( _indexAxis == 'x' ) {
715 + if ( _indexAxis == 'x') {
617 716 _indexAxis = 'y';
618 717 } else {
619 718 _indexAxis = 'x';
620 719 }