Conditions | 1 |
Paths | 2 |
Total Lines | 54 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 | $('#wp-admin-bar-pagespeed_purge') |
||
4 | .click(function (event) { |
||
5 | event.preventDefault(); |
||
6 | |||
7 | var spinner = $(this).find('a'); |
||
8 | pagespeed_purge_animate(spinner); |
||
9 | |||
10 | // Purge cache for the entire website |
||
11 | // More info: https://modpagespeed.com/doc/system#purge_cache |
||
12 | $.ajax({ |
||
13 | method: "PURGE", |
||
14 | url: document.location.origin + '/*' |
||
15 | }) |
||
16 | .done(function (msg) { |
||
17 | if (msg && msg.indexOf("successful") > -1) { |
||
18 | pagespeed_purge_success(spinner); |
||
19 | } else { |
||
20 | pagespeed_purge_error(spinner); |
||
21 | } |
||
22 | }) |
||
23 | .fail(function () { |
||
24 | pagespeed_purge_error(spinner); |
||
25 | }) |
||
26 | .always(function () { |
||
27 | setTimeout(function () { |
||
28 | pagespeed_purge_reset(spinner); |
||
29 | }, 750); |
||
30 | }); |
||
31 | |||
32 | return false; |
||
33 | }); |
||
34 | |||
35 | function pagespeed_purge_animate(spinner) { |
||
36 | pagespeed_purge_reset(spinner); |
||
37 | spinner.addClass('spin'); |
||
38 | } |
||
39 | |||
40 | function pagespeed_purge_error(spinner) { |
||
41 | pagespeed_purge_reset(spinner); |
||
42 | spinner.addClass('error'); |
||
43 | } |
||
44 | |||
45 | function pagespeed_purge_success(spinner) { |
||
46 | pagespeed_purge_reset(spinner); |
||
47 | spinner.addClass('success'); |
||
48 | } |
||
49 | |||
50 | function pagespeed_purge_reset(spinner) { |
||
51 | spinner.removeClass('spin').removeClass('success').removeClass('error'); |
||
52 | } |
||
53 | |||
54 | }); |