PluginProbe
Code Profiler – WordPress Performance Profiling and Debugging Made Easy / 1.9.6
Code Profiler – WordPress Performance Profiling and Debugging Made Easy v1.9.6
1.9.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 All 41 releases
← All changes | static/code-profiler.js +324 -77 1.4.11.9.6 View file →
@@ -5,9 +5,9 @@
5 5 | | | / _ \ / _` |/ _ \ | |_) | '__/ _ \| |_| | |/ _ \ '__| |
6 6 | | |__| (_) | (_| | __/ | __/| | | (_) | _| | | __/ | |
7 7 | \____\___/ \__,_|\___| |_| |_| \___/|_| |_|_|\___|_| |
8 8 | |
9 - | (c) Jerome Bruandet ~ https://code-profiler.com/ |
9 + | (c) Jerome Bruandet ~ https://nintechnet.com/codeprofiler/ |
10 10 +=====================================================================+
11 11 */
12 12
13 13 // =====================================================================
@@ -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
@@ -68,53 +68,106 @@
68 68 function cpjs_front_or_backend( item ) {
69 69 'use strict';
70 70 // Enable/disable frontend/backend select box
71 71 // depending on user's choice
72 - if ( item == 1 ) {
72 + if ( item == 'frontend') {
73 73 jQuery('#p-frontend').show();
74 74 jQuery('#p-backend').hide();
75 75 jQuery('#p-custom').hide();
76 - jQuery('#id-frontend').prop('disabled', false);
76 + jQuery('#p-wpcron').hide();
77 77 jQuery('#id-frontend').focus();
78 - jQuery('#id-backend').prop('disabled', true);
79 - jQuery('#id-custom').prop('disabled', true);
80 78 jQuery('#user-unauthenticated').prop('disabled', false);
81 - } else if ( item == 2 ) {
79 + jQuery('#user-authenticated').prop('disabled', false);
80 + } else if ( item == 'backend') {
82 81 jQuery('#p-backend').show();
83 82 jQuery('#p-frontend').hide();
84 83 jQuery('#p-custom').hide();
85 - jQuery('#id-backend').prop('disabled', false);
84 + jQuery('#p-wpcron').hide();
86 85 jQuery('#id-backend').focus();
87 - jQuery('#id-frontend').prop('disabled', true);
88 - jQuery('#id-custom').prop('disabled', true);
89 86 jQuery('#user-unauthenticated').prop('disabled', true);
90 - jQuery('#user-authenticated').prop('checked', true)
91 - } else {
87 + jQuery('#user-authenticated').prop('disabled', false);
88 + jQuery('#user-authenticated').prop('checked', true);
89 + jQuery('#user-name').prop('disabled', false);
90 + } else if ( item == 'custom') {
92 91 jQuery('#p-custom').show();
93 92 jQuery('#p-frontend').hide();
94 93 jQuery('#p-backend').hide();
95 - jQuery('#id-custom').prop('disabled', false);
94 + jQuery('#p-wpcron').hide();
96 95 jQuery('#id-custom').focus();
97 - jQuery('#id-backend').prop('disabled', true);
98 - jQuery('#id-frontend').prop('disabled', true);
99 96 jQuery('#user-unauthenticated').prop('disabled', false);
97 + jQuery('#user-authenticated').prop('disabled', false);
98 + } else {
99 + jQuery('#p-wpcron').show();
100 + jQuery('#p-custom').hide();
101 + jQuery('#p-frontend').hide();
102 + jQuery('#p-backend').hide();
103 + jQuery('#id-wpcron').focus();
104 + jQuery('#user-unauthenticated').prop('disabled', false);
100 105 }
101 106 }
102 107
108 +function cpjs_authenticated( id ) {
109 + if ( id == 1 ) {
110 + jQuery('#user-name').prop('disabled', false);
111 + jQuery('#user-name').focus();
112 + } else {
113 + jQuery('#user-name').prop('disabled', true);
114 + }
115 +}
116 +
103 117 function cpjs_show_adv_settings() {
104 - jQuery("#cp-advanced-settings").slideDown();
105 - jQuery("#button-adv-settings").prop('disabled', true);
118 + jQuery('#cp-advanced-settings').slideDown();
119 + jQuery('#button-adv-settings').prop('disabled', true);
106 120 }
107 121
108 122 function cpjs_get_post( id ) {
109 123 if ( id == 1 ) {
110 - jQuery("#post-value").prop('disabled', false);
111 - jQuery("#post-value").focus();
124 + jQuery('#post-value').prop('disabled', false);
125 + jQuery('#id-content-type').prop('disabled', false);
126 + jQuery('#post-value').focus();
112 127 } else {
113 - jQuery("#post-value").prop('disabled', true);
128 + jQuery('#post-value').prop('disabled', true);
129 + jQuery('#id-content-type').prop('disabled', true);
114 130 }
115 131 }
116 132
133 +function cpjs_content_type( value ) {
134 + if ( value == 1 ) {
135 + jQuery('#ct-1').slideDown();
136 + jQuery('#ct-3').slideUp();
137 + jQuery('#ct-2').slideUp();
138 + } else if ( value == 2 ) {
139 + jQuery('#ct-2').slideDown();
140 + jQuery('#ct-3').slideUp();
141 + jQuery('#ct-1').slideUp();
142 + } else {
143 + jQuery('#ct-3').slideDown();
144 + jQuery('#ct-1').slideUp();
145 + jQuery('#ct-2').slideUp();
146 + }
147 +}
148 +
149 +function cpjs_isJSON( data ) {
150 +
151 + if ( jQuery('#id-content-type').val() == 1 || jQuery('#get-method').prop('checked') == true ) {
152 + // Ignore
153 + return 1;
154 + }
155 + try {
156 + return JSON.parse( data );
157 + } catch (e) {
158 + // Not a JSON-encoded string
159 + return null;
160 + }
161 +}
162 +
163 +function cpjs_ismultiline( data ) {
164 + if ( data.match( /[\n\r]/) ) {
165 + return true;
166 + }
167 + return false;
168 +}
169 +
117 170 // =====================================================================
118 171 // Log page: filter and delete the log.
119 172
120 173 function cpjs_filter_log() {
@@ -123,8 +176,9 @@
123 176 var bitmask = 0;
124 177 if ( document.cplogform.info.checked == true ) { bitmask += 1; }
125 178 if ( document.cplogform.warn.checked == true ) { bitmask += 2; }
126 179 if ( document.cplogform.error.checked == true ) { bitmask += 4; }
180 + if ( document.cplogform.debug.checked == true ) { bitmask += 8; }
127 181
128 182 // Clear the textarea
129 183 document.cplogform.cptxtlog.value = '';
130 184
@@ -132,9 +186,9 @@
132 186 var cp_count = 0;
133 187 var i = 0;
134 188 for ( i = 0; i < cplog_array.length; ++i ) {
135 189 var line = decodeURIComponent( cplog_array[i] );
136 - var line_array = line.split( '~~', 2 );
190 + var line_array = line.split('~~', 2 );
137 191 if ( line_array[0] & bitmask ) {
138 192 document.cplogform.cptxtlog.value += line_array[1];
139 193 ++cp_count;
140 194 }
@@ -154,12 +208,18 @@
154 208 // =====================================================================
155 209 // AJAX call to start the profiler.
156 210
157 211 function cpjs_start_profiler() {
212 +
158 213 'use strict';
214 +
215 + jQuery('html, body').animate( {
216 + scrollTop: jQuery('#button-adv-settings').offset().top
217 + }, 1000 );
218 +
159 219 // Get the nonce
160 220 var cp_nonce = jQuery('#cp_nonce').val();
161 - if ( cp_nonce == '' ) {
221 + if ( cp_nonce == '') {
162 222 alert( cpi18n.missing_nonce );
163 223 return;
164 224 }
165 225
@@ -164,23 +224,30 @@
164 224 }
165 225
166 226 // Get the scan type (frontend/backend)
167 227 var post;
168 - var where = jQuery('input[name="where"]:checked').val();
169 - if ( where == 'frontend' ) {
228 + var x_end = jQuery('input[name="x_end"]:checked').val();
229 + if ( x_end == 'frontend') {
170 230 post = jQuery('#id-frontend').val();
171 231
172 - } else if ( where == 'backend' ) {
232 + } else if ( x_end == 'backend') {
173 233 post = jQuery('#id-backend').val();
174 234
175 - } else if ( where == 'custom' ) {
235 + } else if ( x_end == 'custom') {
176 236 post = jQuery('#id-custom').val().trim(); // Trim user input
177 237
238 + } else if ( x_end == 'wpcron') {
239 + post = jQuery('#id-wpcron').val();
240 + if ( post == 0 ) {
241 + alert( cpi18n.missing_wpcron );
242 + return;
243 + }
244 +
178 245 } else {
179 246 alert( cpi18n.missing_frontbackend );
180 247 return;
181 248 }
182 - if ( post == '' ) {
249 + if ( post == '') {
183 250 alert( cpi18n.missing_post );
184 251 return;
185 252 }
186 253
@@ -185,29 +252,40 @@
185 252 }
186 253
187 254 // Get the profile's name
188 255 var profile = jQuery('input[name="profile"]').val();
189 - if ( profile == '' ) {
256 + if ( profile == '') {
190 257 alert( cpi18n.missing_profilename );
191 258 jQuery('input[name="profile"]').focus();
192 259 return;
193 260 }
194 261
195 - var user = jQuery('input[name="user"]:checked').val();
196 - if ( user == '' ) {
262 + var x_auth = jQuery('input[name="x_auth"]:checked').val();
263 + if ( x_auth == '') {
197 264 alert( cpi18n.missing_userauth );
198 265 return;
199 266 }
200 267
201 - var ua = jQuery('#ua-id').val();
202 - if ( ua == 'undefined' ) {
203 - ua = 'FireFox';
268 + var username = jQuery('#user-name').val().trim(); // Trim user input
269 + if ( x_auth == 'authenticated') {
270 + if ( username == '') {
271 + alert( cpi18n.missing_username );
272 + jQuery('#user-name').focus();
273 + return;
274 + }
204 275 }
205 276
277 + var user_agent = jQuery('#ua-id').val();
278 + if ( user_agent == 'undefined') {
279 + user_agent = 'FireFox';
280 + }
281 +
282 + var theme = jQuery('#id-theme').val();
283 +
206 284 // GET or POST
207 285 var method = jQuery('input[name="method"]:checked').val();
208 286 var payload = '';
209 - if ( method == 'post' ) {
287 + if ( method == 'post') {
210 288 // Payload
211 289 payload = jQuery('#post-value').val();
212 290 } else {
213 291 method = 'get';
@@ -212,10 +290,30 @@
212 290 } else {
213 291 method = 'get';
214 292 }
215 293
216 - var cookies = jQuery('#cp-cookies').val();
294 + //Content type
295 + var ct = jQuery('#id-content-type').val();
296 + if ( ct == 2 ) {
297 + // application/json
298 + if ( cpjs_isJSON( payload ) == null ) {
299 + alert( cpi18n.missing_ajax );
300 + jQuery('#user-name').focus();
301 + return;
302 + }
303 + } else if ( ct == 3 ) {
304 + // Raw format must be on one single line
305 + if ( cpjs_ismultiline( payload.trim() ) == true ) {
306 + alert( cpi18n.multiline_raw );
307 + jQuery('#post-value').focus();
308 + return;
309 + }
310 + }
217 311
312 + var cookies = jQuery('#cp-cookies').val();
313 + var headers = jQuery('#custom-headers').val();
314 + var exclusions = jQuery('#exclusions').val();
315 +
218 316 // Change buttons status and add animated image with status message
219 317 jQuery('#start-profile').prop('disabled', true);
220 318 jQuery('#cp-progress-div').slideDown();
221 319 jQuery('#progress-gif').slideDown();
@@ -225,20 +323,25 @@
225 323
226 324 var data = {
227 325 'action': 'codeprofiler_start_profiler',
228 326 'cp_nonce': cp_nonce,
229 - 'where': where,
327 + 'x_end': x_end,
230 328 'post': post,
329 + 'content_type': ct,
231 330 'profile': profile,
232 - 'user': user,
331 + 'x_auth': x_auth,
332 + 'username': username,
233 333 'cookies': cookies,
334 + 'custom_headers': headers,
335 + 'exclusions': exclusions,
234 336 'method': method,
235 337 'payload': payload,
236 - 'ua': ua
338 + 'user_agent': user_agent,
339 + 'theme': theme
237 340 };
238 341 // Send the request via AJAX
239 342 jQuery.ajax( {
240 - type: "POST",
343 + type: 'POST',
241 344 url: ajaxurl,
242 345 data: data,
243 346 dataType: 'json',
244 347 success: function( response ) {
@@ -243,14 +346,14 @@
243 346 dataType: 'json',
244 347 success: function( response ) {
245 348
246 349 if (typeof response === 'undefined') {
247 - cpjs_start_error( '<p>'+ cpi18n.unknown_error +'</p>' );
350 + cpjs_start_error('<p>'+ cpi18n.unknown_error +'</p>');
248 351 return;
249 352 }
250 353
251 - if ( response.status != 'success' ) {
252 - cpjs_start_error( '<p>'+ response.message +'</p>' );
354 + if ( response.status != 'success') {
355 + cpjs_start_error('<p>'+ response.message +'</p>');
253 356 return;
254 357 }
255 358
256 359 // ------------------------------------------------------------
@@ -260,9 +363,9 @@
260 363
261 364 data['action'] = 'codeprofiler_prepare_report';
262 365 data['microtime'] = response.microtime;
263 366 jQuery.ajax( {
264 - type: "POST",
367 + type: 'POST',
265 368 url: ajaxurl,
266 369 data: data,
267 370 dataType: 'json',
268 371 success: function( response ) {
@@ -267,18 +370,18 @@
267 370 dataType: 'json',
268 371 success: function( response ) {
269 372
270 373 if (typeof response === 'undefined') {
271 - cpjs_start_error( '<p>'+ cpi18n.unknown_error +'</p>' );
374 + cpjs_start_error('<p>'+ cpi18n.unknown_error +'</p>');
272 375 return;
273 376 }
274 377
275 - if ( response.status != 'success' ) {
276 - cpjs_start_error( '<p>'+ response.message +'</p>' );
378 + if ( response.status != 'success') {
379 + cpjs_start_error('<p>'+ response.message +'</p>');
277 380 return;
278 381 }
279 382 var cp_uri;
280 - if (response.cp_profile !== 'undefined' && response.cp_profile != '' ) {
383 + if (response.cp_profile !== 'undefined' && response.cp_profile != '') {
281 384 cp_uri = '&cptab=profiles_list&action=view_profile&id=' + response.cp_profile + '&section=1';
282 385 } else {
283 386 cp_uri = '&cptab=profiles_list';
284 387 }
@@ -291,16 +394,30 @@
291 394 },
292 395
293 396 // Display non-200 HTTP response
294 397 error: function( xhr, status, err ) {
295 - if ( err != '' ) {
296 -
398 + if ( err != '') {
297 399 if ( xhr.status != 0 ) {
298 - cpjs_start_error( '<p>'+ cpi18n.http_error +' '+ xhr.status +' '+ err +'.</p>' );
400 + var message = cpi18n.http_error +' '+ xhr.status +' '+ err;
401 + // Timeout
402 + if ( xhr.status == 503 || xhr.status == 504 ) {
403 + cpjs_start_error('<p>'+ message +'<br />'+ cpi18n.timeout_error +'.</p>');
404 + // Redirections, not found
405 + } else if ( xhr.status == 301 || xhr.status == 302 || xhr.status == 404 ) {
406 + cpjs_start_error('<p>'+ message +'<br />'+ cpi18n.notfound_error +'.</p>');
407 + // Forbidden
408 + } else if ( xhr.status == 403 ) {
409 + cpjs_start_error('<p>'+ message +'<br />'+ cpi18n.forbidden_error +'.</p>');
410 + // Internal error
411 + } else if ( xhr.status == 500 ) {
412 + cpjs_start_error('<p>'+ message +'<br />'+ cpi18n.internal_error +'.<br />'+ cpi18n.timeout_error +'.</p>');
413 + } else {
414 + cpjs_start_error('<p>'+ cpi18n.http_error +' '+ xhr.status +' '+ err +'.</p>');
415 + }
299 416 return;
300 417
301 418 } else {
302 - cpjs_start_error( '<p>'+ cpi18n.unknown_error +' '+ err +'.</p>' );
419 + cpjs_start_error('<p>'+ cpi18n.unknown_error +' '+ err +'.</p>');
303 420 return;
304 421 }
305 422 }
306 423 return;
@@ -310,16 +427,30 @@
310 427 },
311 428
312 429 // Display non-200 HTTP response
313 430 error: function( xhr, status, err ) {
314 - if ( err != '' ) {
315 -
431 + if ( err != '') {
316 432 if ( xhr.status != 0 ) {
317 - cpjs_start_error( '<p>'+ cpi18n.http_error +' '+ xhr.status +' '+ err +'.</p>' );
433 + var message = cpi18n.http_error +' '+ xhr.status +' '+ err;
434 + // Timeout
435 + if ( xhr.status == 503 || xhr.status == 504 ) {
436 + cpjs_start_error('<p>'+ message +'<br />'+ cpi18n.timeout_error +'.</p>');
437 + // Redirections, not found
438 + } else if ( xhr.status == 301 || xhr.status == 302 || xhr.status == 404 ) {
439 + cpjs_start_error('<p>'+ message +'<br />'+ cpi18n.notfound_error +'.</p>');
440 + // Forbidden
441 + } else if ( xhr.status == 403 ) {
442 + cpjs_start_error('<p>'+ message +'<br />'+ cpi18n.forbidden_error +'.</p>');
443 + // Internal error
444 + } else if ( xhr.status == 500 ) {
445 + cpjs_start_error('<p>'+ message +'<br />'+ cpi18n.internal_error +'.<br />'+ cpi18n.timeout_error +'.</p>');
446 + } else {
447 + cpjs_start_error('<p>'+ cpi18n.http_error +' '+ xhr.status +' '+ err +'.</p>');
448 + }
318 449 return;
319 450
320 451 } else {
321 - cpjs_start_error( '<p>'+ cpi18n.unknown_error +' '+ err +'.</p>' );
452 + cpjs_start_error('<p>'+ cpi18n.unknown_error +' '+ err +'.</p>');
322 453 return;
323 454 }
324 455 }
325 456 return;
@@ -350,8 +481,106 @@
350 481 }
351 482 return false;
352 483 }
353 484
485 +// Hide/show the edit box and buttons when renaming a profile.
486 +function cpjs_toggle_name( row ) {
487 + if ( jQuery('#profile_div_'+ row).css('display') == 'none') {
488 + jQuery('#profile_name_'+ row).hide();
489 + jQuery('#profile_div_'+ row).show();
490 + jQuery('#edit-'+ row).val( jQuery('#profile_name_'+ row).html() );
491 + jQuery('#edit-'+ row).focus();
492 + } else {
493 + jQuery('#profile_div_'+ row).hide();
494 + jQuery('#profile_name_'+ row).show();
495 + }
496 +}
497 +
498 +// Edit the profile name via AJAX endpoint.
499 +function cpjs_edit_name( profile, id, cp_nonce, row ) {
500 +
501 + 'use strict';
502 +
503 + if ( cp_nonce == '') {
504 + alert( cpi18n.missing_nonce );
505 + return;
506 + }
507 + if ( profile == '') {
508 + alert( cpi18n.missing_profileid );
509 + return;
510 + }
511 +
512 + var new_name = jQuery('#edit-'+ id).val().trim();
513 + if ( new_name == '') {
514 + alert( cpi18n.missing_profilename );
515 + return;
516 + }
517 +
518 + jQuery('#profile_spinner_'+ row).addClass('is-active');
519 +
520 + var data = {
521 + 'action': 'codeprofiler_rename',
522 + 'cp_nonce': cp_nonce,
523 + 'new_name': new_name,
524 + 'profile': profile,
525 + };
526 +
527 + // Send the request via AJAX
528 + jQuery.ajax( {
529 + type: 'POST',
530 + url: ajaxurl,
531 + data: data,
532 + dataType: 'json',
533 + success: function( response ) {
534 + jQuery('#profile_spinner_'+ row ).removeClass('is-active');
535 +
536 + if (typeof response === 'undefined') {
537 + alert( cpi18n.unknown_error );
538 + return;
539 + }
540 +
541 + if ( response.status != 'success') {
542 + alert( response.message );
543 + return;
544 + }
545 +
546 + // Success: update the name in the table
547 + jQuery('#profile_name_'+ id).html( response.newname );
548 + cpjs_toggle_name(row);
549 + },
550 + // Display non-200 HTTP response
551 + error: function( xhr, status, err ) {
552 + jQuery('#profile_spinner_'+ row ).removeClass('is-active');
553 + if ( err != '') {
554 + if ( xhr.status != 0 ) {
555 + var message = cpi18n.http_error +' '+ xhr.status +' '+ err;
556 + // Timeout
557 + if ( xhr.status == 503 || xhr.status == 504 ) {
558 + alert( message +'<br />'+ cpi18n.timeout_error );
559 + // Redirections, not found
560 + } else if ( xhr.status == 301 || xhr.status == 302 || xhr.status == 404 ) {
561 + alert( message +'<br />'+ cpi18n.notfound_error );
562 + // Forbidden
563 + } else if ( xhr.status == 403 ) {
564 + alert( message +'<br />'+ cpi18n.forbidden_error );
565 + // Internal error
566 + } else if ( xhr.status == 500 ) {
567 + alert( message +'<br />'+ cpi18n.internal_error +'.<br />'+ cpi18n.timeout_error );
568 + } else {
569 + alert( cpi18n.http_error +' '+ xhr.status +' '+ err );
570 + }
571 + return;
572 +
573 + } else {
574 + alert( cpi18n.unknown_error +' '+ err );
575 + return;
576 + }
577 + }
578 + return;
579 + }
580 + });
581 +}
582 +
354 583 // =====================================================================
355 584 // Plugins/Theme chart.
356 585
357 586 function cpjs_plugins_chart( caxis, clabel, cdata, ctotal_time ) {
@@ -358,9 +587,9 @@
358 587 'use strict';
359 588 // Switch between vertical and horizontal bars
360 589 var _indexAxis = caxis;
361 590 document.getElementById('htov').onclick = function() {
362 - if ( _indexAxis == 'x' ) {
591 + if ( _indexAxis == 'x') {
363 592 _indexAxis = 'y';
364 593 } else {
365 594 _indexAxis = 'x';
366 595 }
@@ -369,11 +598,8 @@
369 598 type: 'bar',
370 599 options: {
371 600 animation: {
372 601 duration: 1000,
373 - onComplete: function() {
374 - document.getElementById('download-png-img').href = myChart.toBase64Image();
375 - }
376 602 },
377 603 indexAxis: _indexAxis,
378 604 plugins: chartPlugins
379 605 },
@@ -399,15 +625,15 @@
399 625 const total_time = ctotal_time;
400 626 const footer = (tooltipItems) => {
401 627 var sum;
402 628 tooltipItems.forEach(function(tooltipItem) {
403 - if ( _indexAxis == 'x' ) {
629 + if ( _indexAxis == 'x') {
404 630 sum = Math.round( ( tooltipItem.parsed.y / total_time ) * 100 );
405 631 } else {
406 632 sum = Math.round( ( tooltipItem.parsed.x / total_time ) * 100 );
407 633 }
408 634 });
409 - return '('+ sum + cpi18n.pc_plugins +')';
635 + return sum + cpi18n.pc_plugins;
410 636 };
411 637
412 638 var chartPlugins = {
413 639 title: {
@@ -454,9 +680,8 @@
454 680 animation: {
455 681 duration: 700,
456 682 onComplete: function() {
457 683 jQuery('#cp-footer-buttons').slideDown(200);
458 - document.getElementById('download-png-img').href = myChart.toBase64Image();
459 684 }
460 685 },
461 686 indexAxis: _indexAxis,
462 687 plugins: chartPlugins
@@ -462,8 +687,15 @@
462 687 plugins: chartPlugins
463 688 },
464 689 plugins:[plugin]
465 690 });
691 +
692 + document.getElementById('download-png-img').onclick = function() {
693 + var a = document.createElement('a');
694 + a.href = myChart.toBase64Image();
695 + a.download = jQuery('#download-png-img').attr('download');
696 + a.click();
697 + }
466 698 }
467 699
468 700 // =====================================================================
469 701 // File I/O chart.
@@ -472,9 +704,9 @@
472 704 'use strict';
473 705 // Switch between vertical and horizontal bars
474 706 var _indexAxis = caxis;
475 707 document.getElementById('htov').onclick = function() {
476 - if ( _indexAxis == 'x' ) {
708 + if ( _indexAxis == 'x') {
477 709 _indexAxis = 'y';
478 710 } else {
479 711 _indexAxis = 'x';
480 712 }
@@ -483,11 +715,8 @@
483 715 type: 'line',
484 716 options: {
485 717 animation: {
486 718 duration: 1000,
487 - onComplete: function() {
488 - document.getElementById('download-png-img').href = myChart.toBase64Image();
489 - }
490 719 },
491 720 indexAxis: _indexAxis,
492 721 plugins: chartPlugins
493 722 },
@@ -555,9 +784,8 @@
555 784 animation: {
556 785 duration: 700,
557 786 onComplete: function() {
558 787 jQuery('#cp-footer-buttons').slideDown(200);
559 - document.getElementById('download-png-img').href = myChart.toBase64Image();
560 788 }
561 789 },
562 790 indexAxis: _indexAxis,
563 791 plugins: chartPlugins
@@ -564,8 +792,15 @@
564 792 },
565 793 plugins:[plugin]
566 794 });
567 795
796 + document.getElementById('download-png-img').onclick = function() {
797 + var a = document.createElement('a');
798 + a.href = myChart.toBase64Image();
799 + a.download = jQuery('#download-png-img').attr('download');
800 + a.click();
801 + }
802 +
568 803 }
569 804 // =====================================================================
570 805 // Disk I/O chart.
571 806
@@ -573,9 +808,9 @@
573 808 'use strict';
574 809 // Switch between vertical and horizontal bars
575 810 var _indexAxis = caxis;
576 811 document.getElementById('htov').onclick = function() {
577 - if ( _indexAxis == 'x' ) {
812 + if ( _indexAxis == 'x') {
578 813 _indexAxis = 'y';
579 814 } else {
580 815 _indexAxis = 'x';
581 816 }
@@ -584,11 +819,8 @@
584 819 type: 'line',
585 820 options: {
586 821 animation: {
587 822 duration: 1000,
588 - onComplete: function() {
589 - document.getElementById('download-png-img').href = myChart.toBase64Image();
590 - }
591 823 },
592 824 indexAxis: _indexAxis,
593 825 plugins: chartPlugins
594 826 },
@@ -655,9 +887,8 @@
655 887 animation: {
656 888 duration: 700,
657 889 onComplete: function() {
658 890 jQuery('#cp-footer-buttons').slideDown(200);
659 - document.getElementById('download-png-img').href = myChart.toBase64Image();
660 891 }
661 892 },
662 893 indexAxis: _indexAxis,
663 894 plugins: chartPlugins
@@ -663,8 +894,24 @@
663 894 plugins: chartPlugins
664 895 },
665 896 plugins:[plugin]
666 897 });
898 +
899 + document.getElementById('download-png-img').onclick = function() {
900 + var a = document.createElement('a');
901 + a.href = myChart.toBase64Image();
902 + a.download = jQuery('#download-png-img').attr('download');
903 + a.click();
904 + }
905 +}
906 +
907 +// =====================================================================
908 +// Settings page
909 +
910 +function cpjs_copy_textarea( id ) {
911 + document.getElementById(id).select();
912 + document.execCommand('copy');
913 + alert( cpi18n.text_copied );
667 914 }
668 915
669 916 // =====================================================================
670 917 // EOF