Passed
Push — v1 ( 772a02...85e446 )
by Andrew
10:41 queued 03:46
created

$R.add(ꞌpluginꞌ).start   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
nc 1
nop 2
dl 0
loc 9
rs 10
c 1
b 0
f 0
1
/**
2
 * Rich Variables plugin for Craft CMS
3
 *
4
 * Rich Variables JS
5
 *
6
 * @author    nystudio107
7
 * @copyright Copyright (c) 2017 nystudio107
8
 * @link      https://nystudio107.com
9
 * @package   RichVariables
10
 * @since     1.0.18
11
 */
12
13
(function($R)
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
14
{
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
15
    $R.add('plugin', 'richvariables', {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
16
        translations: {
17
            en: {
18
                "variables": "Variables"
19
            }
20
        },
21
        init: function(app)
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
22
        {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
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);
0 ignored issues
show
Bug introduced by
The variable Craft seems to be never declared. If this is a global, consider adding a /** global: Craft */ comment.

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.

Loading history...
32
            request.onload = function() {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
33
                if (request.status >= 200 && request.status < 400) {
0 ignored issues
show
Comprehensibility Documentation Best Practice introduced by
This code block is empty. Consider removing it or adding a comment to explain.
Loading history...
34
                } else {
0 ignored issues
show
Comprehensibility Documentation Best Practice introduced by
This code block is empty. Consider removing it or adding a comment to explain.
Loading history...
35
                }
36
            };
37
            request.send();
38
            this.request = request;
39
        },
40
        start: function()
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
41
        {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
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) {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
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
            });
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
55
            // Handle empty menu items
56
            if (responseVars.variablesList.length === 0) {
57
                dropdown.point1 = {
58
                    title: "No Globals Found",
59
                    func: function(buttonName) {
0 ignored issues
show
Unused Code introduced by
The parameter buttonName is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
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)
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
72
        {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
73
            this.insertion.insertRaw(refTag);
74
        }
75
    });
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
76
})(Redactor);
0 ignored issues
show
Bug introduced by
The variable Redactor seems to be never declared. If this is a global, consider adding a /** global: Redactor */ comment.

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.

Loading history...
77