Passed
Push — develop ( 64494e...036482 )
by Andrew
05:23
created

OptimizedImagesField.js ➔ initSizesVueComponent   B

Complexity

Conditions 7

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 15
rs 8
cc 7
1
/**
2
 * Image Optimize plugin for Craft CMS
3
 *
4
 * OptimizedImages Field JS
5
 *
6
 * @author    nystudio107
7
 * @copyright Copyright (c) 2017 nystudio107
8
 * @link      https://nystudio107.com
9
 * @package   ImageOptimize
10
 * @since     1.2.0
11
 */
12
13
import ArrowLine from '../vue/ArrowLine.vue';
14
15
 ;(function ( $, window, document, undefined ) {
0 ignored issues
show
Unused Code introduced by
The parameter document 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...
Unused Code introduced by
The parameter window 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...
Unused Code introduced by
The parameter undefined 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...
16
17
    var pluginName = "ImageOptimizeOptimizedImages",
18
        defaults = {
19
        };
20
21
    // Plugin constructor
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
22
    function Plugin( element, options ) {
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 4
Loading history...
Coding Style introduced by
Opening brace should be on a new line
Loading history...
23
        this.element = element;
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 12 spaces, found 8
Loading history...
24
25
        this.options = $.extend( {}, defaults, options) ;
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 12 spaces, found 8
Loading history...
Coding Style introduced by
Space after opening parenthesis of function call prohibited
Loading history...
Coding Style introduced by
Space after closing parenthesis of function call prohibited
Loading history...
26
27
        this._defaults = defaults;
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 12 spaces, found 8
Loading history...
28
        this._name = pluginName;
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 12 spaces, found 8
Loading history...
29
30
        this.init();
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 12 spaces, found 8
Loading history...
31
    }
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 4
Loading history...
32
33
    Plugin.prototype = {
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
34
35
        init: function(id) {
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 8
Loading history...
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
Unused Code introduced by
The parameter id 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...
36
            var _this = this;
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 16 spaces, found 12
Loading history...
Unused Code introduced by
The variable _this seems to be never used. Consider removing it.
Loading history...
37
38
            $(function () {
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 16 spaces, found 12
Loading history...
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
39
40
/* -- _this.options gives us access to the $jsonVars that our FieldType passed down to us */
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 20 spaces, found 0
Loading history...
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 16 spaces, but found 0.
Loading history...
41
42
            });
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 16 spaces, found 12
Loading history...
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...
43
        }
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 8
Loading history...
44
    };
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 4
Loading history...
45
46
    // A really lightweight plugin wrapper around the constructor,
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
47
    // preventing against multiple instantiations
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
48
    $.fn[pluginName] = function ( options ) {
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 4
Loading history...
49
        return this.each(function () {
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 12 spaces, found 8
Loading history...
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
50
            if (!$.data(this, "plugin_" + pluginName)) {
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 16 spaces, found 12
Loading history...
51
                $.data(this, "plugin_" + pluginName,
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 20 spaces, found 16
Loading history...
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
52
                new Plugin( this, options ));
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 20 spaces, found 16
Loading history...
Coding Style introduced by
Space after opening parenthesis of function call prohibited
Loading history...
Coding Style introduced by
Expected 0 spaces before closing parenthesis; 1 found
Loading history...
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...
53
            }
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 16 spaces, found 12
Loading history...
54
        });
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 8
Loading history...
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
    };
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 4
Loading history...
56
57
})( jQuery, window, document );
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 1 spaces, found 0
Loading history...
Coding Style introduced by
Space after opening parenthesis of function call prohibited
Loading history...
Coding Style introduced by
Expected 0 spaces before closing parenthesis; 1 found
Loading history...
58
59
function initSizesVueComponent(sizesWrapperId){
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 1 spaces, found 0
Loading history...
Coding Style introduced by
Opening brace should be on a new line
Loading history...
60
     console.log(sizesWrapperId);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
61
     const vm = new Vue({
0 ignored issues
show
Coding Style introduced by
Opening statement of multi-line function call not indented correctly; expected 4 spaces but found 5
Loading history...
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
Bug introduced by
The variable Vue seems to be never declared. If this is a global, consider adding a /** global: Vue */ 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...
Unused Code introduced by
The constant vm seems to be never used. Consider removing it.
Loading history...
62
         el: '#' + sizesWrapperId,
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 9
Loading history...
63
         components: {
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 9
Loading history...
64
             'arrow-line': ArrowLine,
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 16 spaces, found 13
Loading history...
65
         },
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 9
Loading history...
66
         data: {
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 9
Loading history...
67
         },
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 9
Loading history...
68
         methods: {
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 9
Loading history...
69
         },
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 9
Loading history...
70
         mounted() {
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 12 spaces, found 9
Loading history...
71
         }
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 9
Loading history...
72
     });
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 8 spaces, found 5
Loading history...
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...
73
}
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 1 spaces, found 0
Loading history...
74
75
Craft.OptimizedImagesInput = Garnish.Base.extend(
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected at least 1 spaces, found 0
Loading history...
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...
Bug introduced by
The variable Garnish seems to be never declared. If this is a global, consider adding a /** global: Garnish */ 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...
76
    {
77
        id: null,
78
        inputNamePrefix: null,
79
        inputIdPrefix: null,
80
81
        $container: null,
82
        $blockContainer: null,
83
        $addBlockBtnContainer: null,
84
        $addBlockBtnGroup: null,
85
        $addBlockBtnGroupBtns: null,
86
87
        blockSort: null,
88
        blockSelect: null,
89
90
        init: function(id, inputNamePrefix, sizesWrapperId) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
91
92
            initSizesVueComponent(sizesWrapperId);
93
            this.id = id;
94
            this.inputNamePrefix = inputNamePrefix;
95
            this.inputIdPrefix = Craft.formatInputId(this.inputNamePrefix);
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...
96
97
            this.$container = $('#' + this.id);
98
            this.$blockContainer = this.$container.children('.variant-blocks');
99
            this.$addBlockBtnContainer = this.$container.children('.buttons');
100
            this.$addBlockBtnGroup = this.$addBlockBtnContainer.children('.btngroup');
101
            this.$addBlockBtnGroupBtns = this.$addBlockBtnGroup.children('.btn');
102
103
            // Create our action button menus
104
            var _this = this;
105
            this.$blockContainer.find('> > .actions > .settings').each(function (index, value) {
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...
106
                var $value = $(value);
107
                var menuBtn;
108
                if ($value.data('menubtn')) {
109
                    menuBtn = $value.data('menubtn');
110
                } else {
111
                    menuBtn = new Garnish.MenuBtn(value);
0 ignored issues
show
Bug introduced by
The variable Garnish seems to be never declared. If this is a global, consider adding a /** global: Garnish */ 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...
112
                }
113
                menuBtn.menu.settings.onOptionSelect = $.proxy(function(option) {
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...
114
                    this.onMenuOptionSelect(option, menuBtn);
115
                }, _this);
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...
116
            });
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...
117
118
            var $blocks = this.$blockContainer.children();
119
120
            this.blockSort = new Garnish.DragSort($blocks, {
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...
Bug introduced by
The variable Garnish seems to be never declared. If this is a global, consider adding a /** global: Garnish */ 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...
121
                handle: '> .actions > .move',
122
                axis: 'y',
123
                collapseDraggees: true,
124
                magnetStrength: 4,
125
                helperLagBase: 1.5,
126
                helperOpacity: 0.9,
127
                onSortChange: $.proxy(function() {
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...
128
                    this.resetVariantBlockOrder();
129
                }, this)
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...
130
            });
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...
131
132
            this.addListener(this.$addBlockBtnGroupBtns, 'click', function(ev) {
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...
133
                var type = $(ev.target).data('type');
0 ignored issues
show
Unused Code introduced by
The variable type seems to be never used. Consider removing it.
Loading history...
134
                this.addVariantBlock(null);
135
            });
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...
136
137
            this.addAspectRatioHandlers();
138
            this.reIndexVariants();
139
        },
140
141
        onMenuOptionSelect: function(option, menuBtn) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
142
            var $option = $(option);
143
            var container = menuBtn.$btn.closest('.matrixblock');
144
145
            switch ($option.data('action')) {
146
                case 'add': {
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
147
                    this.addVariantBlock(container);
148
                    break;
149
                }
150
                case 'delete': {
151
                    if (!$option.hasClass('disabled')) {
152
                        this.deleteVariantBlock(container);
153
                    }
154
                    break;
155
                }
156
            }
157
        },
158
159
        getHiddenBlockCss: function($block) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
160
            return {
161
                opacity: 0,
162
                marginBottom: -($block.outerHeight())
163
            };
164
        },
165
166
        // Re-index all of the variant blocks
167
        reIndexVariants: function() {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
168
            this.$blockContainer = this.$container.children('.variant-blocks');
169
            var $blocks = this.$blockContainer.children();
170
            $blocks.each(function (index, value) {
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...
171
                var variantIndex = index;
172
                var $value = $(value);
173
                var elements = $value.find('div .field, label, input, select');
174
175
                // Re-index all of the element attributes
176
                $(elements).each(function (index, value) {
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...
177
                    // id attributes
178
                    var str = $(value).attr('id');
179
                    if (str) {
180
                        str = str.replace(/\-([0-9]+)\-/g, "-" + variantIndex +"-");
181
                        $(value).attr('id', str);
182
                    }
183
                    // for attributes
184
                    str = $(value).attr('for');
185
                    if (str) {
186
                        str = str.replace(/\-([0-9]+)\-/g, "-" + variantIndex +"-");
187
                        $(value).attr('for', str);
188
                    }
189
                    // Name attributes
190
                    str = $(value).attr('name');
191
                    if (str) {
192
                        str = str.replace(/\[([0-9]+)\]/g, "[" + variantIndex +"]");
193
                        $(value).attr('name', str);
194
                    }
195
                });
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...
196
            });
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...
197
            var disabledDeleteItem = false;
198
            // If we only have one block, don't allow it to be deleted
199
            if ($blocks.length == 1) {
0 ignored issues
show
Best Practice introduced by
Comparing $blocks.length to 1 using the == operator is not safe. Consider using === instead.
Loading history...
200
                disabledDeleteItem = true;
201
            }
202
            $blocks.find('> .actions > .settings').each(function (index, value) {
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...
203
                var $value = $(value);
204
                var menuBtn;
205
                if ($value.data('menubtn')) {
206
                    menuBtn = $value.data('menubtn');
207
                    $menuItem = $(menuBtn.menu.$menuList[1]);
0 ignored issues
show
Bug introduced by
The variable $menuItem seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.$menuItem.
Loading history...
208
                    if (disabledDeleteItem) {
209
                        $menuItem.find("> li > a").addClass('disabled').disable();
210
                    } else {
211
                        $menuItem.find("> li > a").removeClass('disabled').enable();
212
                    }
213
                }
214
            });
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...
215
216
        },
217
218
        addAspectRatioHandlers: function () {
219
            this.addListener($('.lightswitch'), 'click', function(ev) {
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...
220
                var $target = $(ev.target);
221
                var $block = $target.closest('.matrixblock');
222
                $block.find('.io-aspect-ratio-wrapper').slideToggle();
223
            });
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...
224
            this.addListener($('.io-select-ar-box'), 'click', function(ev) {
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...
225
                var $target = $(ev.target);
226
                var x = $(ev.target).data('x'),
227
                    y = $(ev.target).data('y'),
228
                    custom = $(ev.target).data('custom'),
229
                    field, $block;
230
                // Select the appropriate aspect ratio
231
                $block = $target.closest('.matrixblock');
232
                $block.find('.io-select-ar-box').each(function (index, value) {
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...
233
                    $(value).removeClass('io-selected-ar-box');
234
                });
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...
235
                $target.addClass('io-selected-ar-box');
236
237
                // Handle setting the actual field values
238
                if (custom) {
239
                    $block.find('.io-custom-ar-wrapper').slideDown();
240
                } else {
241
                    $block.find('.io-custom-ar-wrapper').slideUp();
242
                    field = $block.find('input')[2];
243
                    $(field).val(x);
244
                    field = $block.find('input')[3];
245
                    $(field).val(y);
246
                }
247
            });
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...
248
        },
249
250
        addVariantBlock: function(container) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
251
            var _this = this;
252
            $block = $(this.$blockContainer.children()[0]).clone();
0 ignored issues
show
Bug introduced by
The variable $block seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.$block.
Loading history...
253
            // Reset to default values
254
            $block.find('.io-select-ar-box').each(function (index, value) {
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...
255
                if (index === 0) {
256
                    $(value).addClass('io-selected-ar-box');
257
                } else {
258
                    $(value).removeClass('io-selected-ar-box');
259
                }
260
            });
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...
261
            $block.find('.io-custom-ar-wrapper').hide();
262
            field = $block.find('input')[0];
0 ignored issues
show
Bug introduced by
The variable field seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.field.
Loading history...
263
            $(field).val(1200);
264
            field = $block.find('input')[1];
265
            $(field).val(1);
266
            field = $block.find('input')[2];
267
            $(field).val(16);
268
            field = $block.find('input')[3];
269
            $(field).val(9);
270
            field = $block.find('select')[0];
271
            $(field).val(82);
272
            field = $block.find('select')[1];
273
            $(field).val('jpg');
274
            $block.css(this.getHiddenBlockCss($block)).velocity({
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...
275
                opacity: 1,
276
                'margin-bottom': 10
277
            }, 'fast', $.proxy(function() {
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 16 spaces, but found 12.
Loading history...
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...
278
279
                // Insert the block in the right place
280
                if (container) {
281
                    $block.insertBefore(container);
282
                } else {
283
                    $block.appendTo(this.$blockContainer);
284
                }
285
                // Update the Garnish UI controls
286
                this.blockSort.addItems($block);
287
                this.addAspectRatioHandlers();
288
                $block.find('.settings').each(function (index, value) {
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...
289
                    var $value = $(value),
290
                        menuBtn,
291
                        menu;
292
293
                    menu = _this.$container.find('.io-menu-clone > .menu').clone();
294
                    $(menu).insertAfter($value);
295
                    menuBtn = new Garnish.MenuBtn(value);
0 ignored issues
show
Bug introduced by
The variable Garnish seems to be never declared. If this is a global, consider adding a /** global: Garnish */ 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...
296
297
                    menuBtn.menu.settings.onOptionSelect = $.proxy(function(option) {
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...
298
                        _this.onMenuOptionSelect(option, menuBtn);
299
                    }, this);
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...
300
                });
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...
301
                this.reIndexVariants();
302
            }, this));
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...
303
        },
304
305
        deleteVariantBlock: function(container) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
306
            var _this = this;
307
            container.velocity(this.getHiddenBlockCss(container), 'fast', $.proxy(function() {
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...
308
                container.remove();
309
                _this.reIndexVariants();
310
            }, this));
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...
311
        },
312
313
        resetVariantBlockOrder: function() {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
314
            this.reIndexVariants();
315
        }
316
317
    });
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 0 spaces, but found 4.
Loading history...
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...
318