Conditions | 1 |
Paths | 2 |
Total Lines | 64 |
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 | /** |
||
13 | (function($R) |
||
14 | { |
||
15 | $R.add('plugin', 'richvariables', { |
||
16 | translations: { |
||
17 | en: { |
||
18 | "variables": "Variables" |
||
19 | } |
||
20 | }, |
||
21 | init: function(app) |
||
22 | { |
||
23 | this.app = app; |
||
24 | this.lang = app.lang; |
||
25 | this.inline = app.inline; |
||
26 | this.toolbar = app.toolbar; |
||
27 | this.insertion = app.insertion; |
||
28 | |||
29 | // Grab the globals set Reference Tags from our controller |
||
30 | var request = new XMLHttpRequest(); |
||
|
|||
31 | request.open('GET', Craft.getActionUrl('rich-variables'), false); |
||
32 | request.onload = function() { |
||
33 | if (request.status >= 200 && request.status < 400) { |
||
34 | } else { |
||
35 | } |
||
36 | }; |
||
37 | request.send(); |
||
38 | this.request = request; |
||
39 | }, |
||
40 | start: function() |
||
41 | { |
||
42 | var dropdown = {}; |
||
43 | var responseVars = JSON.parse(this.request.responseText); |
||
44 | |||
45 | // Iterate through each menu item, adding them to our dropdown |
||
46 | responseVars.variablesList.forEach(function(menuItem, index) { |
||
47 | var key = 'point' + (index + 1); |
||
48 | var refTag = '<ins>' + menuItem.text + '</ins>'; |
||
49 | dropdown[key] = { |
||
50 | title: menuItem.title, |
||
51 | api: 'plugin.richvariables.insert', |
||
52 | args: refTag |
||
53 | }; |
||
54 | }); |
||
55 | // Handle empty menu items |
||
56 | if (responseVars.variablesList.length === 0) { |
||
57 | dropdown.point1 = { |
||
58 | title: "No Globals Found", |
||
59 | func: function(buttonName) { |
||
60 | // NOP |
||
61 | }, |
||
62 | }; |
||
63 | } |
||
64 | // Add the button and dropdown |
||
65 | var $button = this.toolbar.addButton('variables', { title: this.lang.get('variables') }); |
||
66 | $button.setDropdown(dropdown); |
||
67 | if (responseVars.useIconForMenu) { |
||
68 | $button.setIcon('<img src="' + responseVars.menuIconUrl + '" height="16" width="16" style="margin-top: -2px;">'); |
||
69 | } |
||
70 | }, |
||
71 | insert: function(refTag) |
||
72 | { |
||
73 | this.insertion.insertRaw(refTag); |
||
74 | } |
||
75 | }); |
||
76 | })(Redactor); |
||
77 |
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.