| Conditions | 6 |
| Paths | 3 |
| Total Lines | 91 |
| 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 | (function( $ ) { |
||
| 4 | $(function() { |
||
| 5 | // Only execute on the plugin settings page |
||
| 6 | if (typeof window.WORDPRESS_SECURITY_TXT_ADMIN === 'undefined') { |
||
| 7 | return; |
||
| 8 | } |
||
| 9 | |||
| 10 | // Show/hide when enabled/disabled |
||
| 11 | jQuery('input[name="wordpress-security-txt-options[enable]"]').change(function () { |
||
| 12 | if (jQuery(this)[0].checked) { |
||
| 13 | jQuery('.hide-when-disabled').closest('tr').fadeIn(); |
||
| 14 | jQuery('p.hide-when-disabled, div.hide-when-disabled').fadeIn().prev().fadeIn(); |
||
| 15 | } else { |
||
| 16 | jQuery('.hide-when-disabled').closest('tr').fadeOut(); |
||
| 17 | jQuery('p.hide-when-disabled, div.hide-when-disabled').fadeOut().prev().fadeOut(); |
||
| 18 | } |
||
| 19 | }).trigger('change'); |
||
| 20 | |||
| 21 | jQuery('input[name="wordpress-security-txt-options[debug]"]').change(function () { |
||
| 22 | if (jQuery(this)[0].checked) { |
||
| 23 | jQuery('div[id="wordpress-security-txt-sections[debug]"]').fadeIn().prev().fadeIn(); |
||
| 24 | } else { |
||
| 25 | jQuery('div[id="wordpress-security-txt-sections[debug]"]').fadeOut().prev().fadeOut(); |
||
| 26 | } |
||
| 27 | }).trigger('change'); |
||
| 28 | |||
| 29 | // Inject multi-line encryption placeholder |
||
| 30 | jQuery('textarea[name="wordpress-security-txt-options[encryption]"]').attr('placeholder', |
||
| 31 | '-----BEGIN PGP PUBLIC KEY BLOCK-----\n' + |
||
| 32 | 'mQINBFez...\n' + |
||
| 33 | '-----END PGP PUBLIC KEY BLOCK-----\n' |
||
| 34 | ); |
||
| 35 | |||
| 36 | // Add inline upload if browser supports it |
||
| 37 | if (window.File && window.FileReader && window.FileList && window.Blob) { |
||
| 38 | jQuery('textarea[name="wordpress-security-txt-options[encryption]"]') |
||
| 39 | .after('<input type="button" name="wordpress-security-txt-options[encryption][file_input]" value="Select file...">'); |
||
| 40 | |||
| 41 | jQuery('input[name="wordpress-security-txt-options[encryption][file_input]"]') |
||
| 42 | .click(function () { |
||
| 43 | jQuery('form[id="wordpress-security-txt[file_input]"] input') |
||
| 44 | .attr('data-target', 'textarea[name="wordpress-security-txt-options[encryption]"]') |
||
| 45 | .click(); |
||
| 46 | }); |
||
| 47 | |||
| 48 | jQuery('form[id="wordpress-security-txt[file_input]"] input').change(function () { |
||
| 49 | var fileReader = new FileReader(); |
||
|
|
|||
| 50 | |||
| 51 | fileReader.onload = function () { |
||
| 52 | var targetInput = jQuery('form[id="wordpress-security-txt[file_input]"] input').attr('data-target'); |
||
| 53 | |||
| 54 | jQuery(targetInput).val(fileReader.result); |
||
| 55 | |||
| 56 | setTimeout(function () { |
||
| 57 | console.log('done!'+targetInput); |
||
| 58 | jQuery(targetInput).click(); |
||
| 59 | }, 250); |
||
| 60 | }; |
||
| 61 | |||
| 62 | fileReader.readAsText(jQuery(this).prop('files')[0]); |
||
| 63 | }); |
||
| 64 | } |
||
| 65 | |||
| 66 | // Inject settings reset controls |
||
| 67 | jQuery('input[name="wordpress-security-txt[reset]"]').click(function () { |
||
| 68 | jQuery('input[name="wordpress-security-txt-options[reset]"]') |
||
| 69 | .val('WORDPRESS_SECURITY_TXT_RESET_REQUESTED'); |
||
| 70 | |||
| 71 | jQuery('input[name="wordpress-security-txt[submit]"]') |
||
| 72 | .click(); |
||
| 73 | }); |
||
| 74 | |||
| 75 | // Add validation handlers |
||
| 76 | jQuery('input[name="wordpress-security-txt-options[contact]"]').on('click keyup keypress blur change focus', function () { |
||
| 77 | window.WORDPRESS_SECURITY_TXT_VALIDATORS.apply(jQuery(this), 'contact'); |
||
| 78 | }).trigger('click'); |
||
| 79 | |||
| 80 | jQuery('textarea[name="wordpress-security-txt-options[encryption]"]').on('click keyup keypress blur change focus', function () { |
||
| 81 | window.WORDPRESS_SECURITY_TXT_VALIDATORS.apply(jQuery(this), 'encryption'); |
||
| 82 | }).trigger('click'); |
||
| 83 | |||
| 84 | jQuery('input[name="wordpress-security-txt-options[acknowledgement]"]').on('click keyup keypress blur change focus', function () { |
||
| 85 | window.WORDPRESS_SECURITY_TXT_VALIDATORS.apply(jQuery(this), 'acknowledgement'); |
||
| 86 | }).trigger('click'); |
||
| 87 | |||
| 88 | // Append plugin version (on plugin settings page only) |
||
| 89 | jQuery('div#wpfooter p#footer-upgrade').html( |
||
| 90 | jQuery('div#wpfooter p#footer-upgrade').html().trim() + |
||
| 91 | ', <code>wordpress-security-txt</code> Version ' + |
||
| 92 | WORDPRESS_SECURITY_TXT_VERSION |
||
| 93 | ); |
||
| 94 | }); |
||
| 95 | |||
| 98 |
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.