Conditions | 1 |
Paths | 4 |
Total Lines | 82 |
Lines | 0 |
Ratio | 0 % |
Changes | 8 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | jQuery( document ).ready(function() |
||
2 | { |
||
3 | var percentage = jQuery( '#wp-admin-bar-autoptimize-cache-info .autoptimize-radial-bar' ).attr('percentage'); |
||
4 | var rotate = percentage * 1.8; |
||
5 | |||
6 | jQuery( '#wp-admin-bar-autoptimize-cache-info .autoptimize-radial-bar .mask.full, #wp-admin-bar-autoptimize-cache-info .autoptimize-radial-bar .fill' ).css({ |
||
7 | '-webkit-transform' : 'rotate(' + rotate + 'deg)', |
||
8 | '-ms-transform' : 'rotate(' + rotate + 'deg)', |
||
9 | 'transform' : 'rotate(' + rotate + 'deg)' |
||
10 | }); |
||
11 | |||
12 | // Fix Background color of circle percentage & delete cache to fit with the current color theme |
||
13 | jQuery( '#wp-admin-bar-autoptimize-cache-info .autoptimize-radial-bar .inset' ).css( 'background-color', jQuery( '#wp-admin-bar-autoptimize .ab-sub-wrapper' ).css( 'background-color') ); |
||
14 | jQuery( '#wp-admin-bar-autoptimize-delete-cache .ab-item' ).css( 'background-color', jQuery( '#wpadminbar' ).css( 'background-color') ); |
||
15 | |||
16 | jQuery( '#wp-admin-bar-autoptimize-default li' ).click(function(e) |
||
17 | { |
||
18 | var id = ( typeof e.target.id != 'undefined' && e.target.id ) ? e.target.id : jQuery( e.target ).parent( 'li' ).attr( 'id' ); |
||
19 | var action = ''; |
||
20 | |||
21 | if( id == 'wp-admin-bar-autoptimize-delete-cache' ){ |
||
22 | action = 'autoptimize_delete_cache'; |
||
23 | } else { |
||
24 | return; |
||
25 | } |
||
26 | |||
27 | // Remove the class "hover" from drop-down Autoptimize menu to hide it. |
||
28 | jQuery( '#wp-admin-bar-autoptimize' ).removeClass( 'hover' ); |
||
29 | |||
30 | // Create and Show the Autoptimize Loading Modal |
||
31 | var modal_loading = jQuery( '<div class="autoptimize-loading"></div>' ).appendTo( 'body' ).show(); |
||
32 | |||
33 | var success = function() { |
||
34 | // Reset output values & class names of cache info |
||
35 | jQuery( '#wp-admin-bar-autoptimize-cache-info .size' ).attr( 'class', 'size green' ).html( '0.00 B' ); |
||
36 | jQuery( '#wp-admin-bar-autoptimize-cache-info .files' ).html( '0' ); |
||
37 | jQuery( '#wp-admin-bar-autoptimize-cache-info .percentage .numbers' ).attr( 'class', 'numbers green' ).html( '0%' ); |
||
38 | jQuery( '#wp-admin-bar-autoptimize-cache-info .autoptimize-radial-bar .fill' ).attr( 'class', 'fill bg-green' ); |
||
39 | |||
40 | // Reset the class names of bullet icon |
||
41 | jQuery( '#wp-admin-bar-autoptimize' ).attr( 'class', 'menupop bullet-green' ); |
||
42 | |||
43 | // Reset the Radial Bar progress |
||
44 | jQuery( '#wp-admin-bar-autoptimize-cache-info .autoptimize-radial-bar .mask.full, #wp-admin-bar-autoptimize-cache-info .autoptimize-radial-bar .fill' ).css({ |
||
45 | '-webkit-transform' : 'rotate(0deg)', |
||
46 | '-ms-transform' : 'rotate(0deg)', |
||
47 | 'transform' : 'rotate(0deg)' |
||
48 | }); |
||
49 | }; |
||
50 | |||
51 | var notice = function() { |
||
52 | jQuery( '<div id="ao-delete-cache-timeout" class="notice notice-error is-dismissible"><p><strong><span style="display:block;clear:both;">' + autoptimize_ajax_object.error_msg + '</span></strong></p><button type="button" class="notice-dismiss"><span class="screen-reader-text">' + autoptimize_ajax_object.dismiss_msg + '</span></button></div><br>' ).insertAfter( '#wpbody .wrap h1:first-of-type' ).show(); |
||
|
|||
53 | }; |
||
54 | |||
55 | jQuery.ajax({ |
||
56 | type : 'GET', |
||
57 | url : autoptimize_ajax_object.ajaxurl, |
||
58 | data : {'action':action, 'nonce':autoptimize_ajax_object.nonce}, |
||
59 | dataType : 'json', |
||
60 | cache : false, |
||
61 | timeout : 5000, |
||
62 | success : function( cleared ) |
||
63 | { |
||
64 | // Remove the Autoptimize Loading Modal |
||
65 | modal_loading.remove(); |
||
66 | if ( cleared ) { |
||
67 | success(); |
||
68 | } else { |
||
69 | notice(); |
||
70 | } |
||
71 | }, |
||
72 | error: function( jqXHR, textStatus ) |
||
73 | { |
||
74 | // Remove the Autoptimize Loading Modal |
||
75 | modal_loading.remove(); |
||
76 | |||
77 | // WordPress Admin Notice |
||
78 | notice(); |
||
79 | } |
||
80 | }); |
||
81 | }); |
||
82 | }); |
||
83 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.