Passed
Push — develop ( 2386f6...9dccdb )
by Andrew
06:50
created

OptimizedImagesField.js ➔ imageLoaded   A

Complexity

Conditions 4

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 12
rs 10
c 0
b 0
f 0
cc 4
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
/**
14
 * Convert the passed in bytes into a human readable format
15
 *
16
 * @param bytes
0 ignored issues
show
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 3 spaces but found 1
Loading history...
17
 * @param si
0 ignored issues
show
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 3 spaces but found 1
Loading history...
18
 * @param dp
0 ignored issues
show
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 3 spaces but found 1
Loading history...
19
 * @returns {string}
0 ignored issues
show
Coding Style introduced by
Tag @returns cannot be grouped with parameter tags in a doc comment
Loading history...
20
 */
21
function humanFileSize(bytes, si=false, dp=1) {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on a new line
Loading history...
22
    const thresh = si ? 1000 : 1024;
23
24
    if (Math.abs(bytes) < thresh) {
25
        return bytes + ' B';
26
    }
27
28
    const units = si
29
        ? ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
30
        : ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
31
    let u = -1;
32
    const r = 10**dp;
33
34
    do {
35
        bytes /= thresh;
36
        ++u;
37
    } while (Math.round(Math.abs(bytes) * r) / r >= thresh && u < units.length - 1);
38
39
40
    return bytes.toFixed(dp) + ' ' + units[u];
41
}
42
43
/**
44
 * After an image has loaded, query the performance API for the decodedBodySize
45
 *
46
 * @param image
47
 */
48
function imageLoaded(image) {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on a new line
Loading history...
49
    const url = image.src || image.href;
50
    if (url && url.length > 0) {
51
        const iTime = performance.getEntriesByName(url)[0];
0 ignored issues
show
Bug introduced by
The variable performance seems to be never declared. If this is a global, consider adding a /** global: performance */ 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...
52
        if (iTime !== undefined) {
53
            const elem = image.parentNode.parentNode.parentNode.nextElementSibling.querySelector('.io-file-size');
54
            if (elem) {
55
                elem.innerHTML = humanFileSize(iTime.decodedBodySize, true);
56
            }
57
        }
58
    }
59
}
60
61
;(function ( $, window, document, undefined ) {
0 ignored issues
show
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...
62
63
    var pluginName = "ImageOptimizeOptimizedImages",
64
        defaults = {
65
        };
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 4 spaces, found 8
Loading history...
66
67
    // Plugin constructor
68
    function Plugin( element, options ) {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on a new line
Loading history...
69
        this.element = element;
70
71
        this.options = $.extend( {}, defaults, options) ;
0 ignored issues
show
Coding Style introduced by
Space after closing parenthesis of function call prohibited
Loading history...
Coding Style introduced by
Space after opening parenthesis of function call prohibited
Loading history...
72
73
        this._defaults = defaults;
74
        this._name = pluginName;
75
76
        this.init();
77
    }
78
79
    Plugin.prototype = {
80
81
        init: function(id) {
0 ignored issues
show
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...
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
82
            var _this = this;
0 ignored issues
show
Unused Code introduced by
The variable _this seems to be never used. Consider removing it.
Loading history...
83
84
            $(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...
85
86
/* -- _this.options gives us access to the $jsonVars that our FieldType passed down to us */
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 0.
Loading history...
Coding Style introduced by
Line indented incorrectly; expected at least 16 spaces, found 0
Loading history...
87
88
                const images = document.querySelectorAll("img.io-preview-image");
89
                for (const image of images) {
90
                    if (image.complete) {
91
                        imageLoaded(image);
92
                    } else {
93
                        image.addEventListener('load', (event) => {
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...
94
                            imageLoaded(event.target);
95
                        });
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...
96
                    }
97
                }
98
            });
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...
99
        }
100
    };
101
102
    // A really lightweight plugin wrapper around the constructor,
103
    // preventing against multiple instantiations
104
    $.fn[pluginName] = function ( options ) {
105
        return this.each(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...
106
            if (!$.data(this, "plugin_" + pluginName)) {
107
                $.data(this, "plugin_" + pluginName,
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...
108
                new Plugin( this, options ));
0 ignored issues
show
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...
Coding Style introduced by
Space after opening parenthesis of function call prohibited
Loading history...
109
            }
110
        });
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...
111
    };
112
113
})( jQuery, window, document );
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing parenthesis; 1 found
Loading history...
Coding Style introduced by
Space after opening parenthesis of function call prohibited
Loading history...
114
115
Craft.OptimizedImagesInput = Garnish.Base.extend(
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...
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...
116
    {
117
        id: null,
118
        inputNamePrefix: null,
119
        inputIdPrefix: null,
120
121
        $container: null,
122
        $blockContainer: null,
123
        $addBlockBtnContainer: null,
124
        $addBlockBtnGroup: null,
125
        $addBlockBtnGroupBtns: null,
126
127
        blockSort: null,
128
        blockSelect: null,
129
130
        init: function(id, inputNamePrefix, sizesWrapperId) {
0 ignored issues
show
Unused Code introduced by
The parameter sizesWrapperId 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...
131
132
            this.id = id;
133
            this.inputNamePrefix = inputNamePrefix;
134
            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...
135
136
            this.$container = $('#' + this.id);
137
            this.$blockContainer = this.$container.children('.variant-blocks');
138
            this.$addBlockBtnContainer = this.$container.children('.buttons');
139
            this.$addBlockBtnGroup = this.$addBlockBtnContainer.children('.btngroup');
140
            this.$addBlockBtnGroupBtns = this.$addBlockBtnGroup.children('.btn');
141
142
            // Create our action button menus
143
            var _this = this;
144
            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...
145
                var $value = $(value);
146
                var menuBtn;
147
                if ($value.data('menubtn')) {
148
                    menuBtn = $value.data('menubtn');
149
                } else {
150
                    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...
151
                }
152
                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...
153
                    this.onMenuOptionSelect(option, menuBtn);
154
                }, _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...
155
            });
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...
156
157
            var $blocks = this.$blockContainer.children();
158
159
            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...
160
                handle: '> .actions > .move',
161
                axis: 'y',
162
                collapseDraggees: true,
163
                magnetStrength: 4,
164
                helperLagBase: 1.5,
165
                helperOpacity: 0.9,
166
                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...
167
                    this.resetVariantBlockOrder();
168
                }, 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...
169
            });
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...
170
171
            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...
172
                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...
173
                this.addVariantBlock(null);
174
            });
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...
175
176
            this.addAspectRatioHandlers();
177
            this.reIndexVariants();
178
        },
179
180
        onMenuOptionSelect: function(option, menuBtn) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
181
            var $option = $(option);
182
            var container = menuBtn.$btn.closest('.matrixblock');
183
184
            switch ($option.data('action')) {
185
                case 'add': {
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
186
                    this.addVariantBlock(container);
187
                    break;
188
                }
189
                case 'delete': {
190
                    if (!$option.hasClass('disabled')) {
191
                        this.deleteVariantBlock(container);
192
                    }
193
                    break;
194
                }
195
            }
196
        },
197
198
        getHiddenBlockCss: function($block) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
199
            return {
200
                opacity: 0,
201
                marginBottom: -($block.outerHeight())
202
            };
203
        },
204
205
        // Re-index all of the variant blocks
206
        reIndexVariants: function() {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
207
            this.$blockContainer = this.$container.children('.variant-blocks');
208
            var $blocks = this.$blockContainer.children();
209
            $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...
210
                var variantIndex = index;
211
                var $value = $(value);
212
                var elements = $value.find('div .field, label, input, select');
213
214
                // Re-index all of the element attributes
215
                $(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...
216
                    // id attributes
217
                    var str = $(value).attr('id');
218
                    if (str) {
219
                        str = str.replace(/\-([0-9]+)\-/g, "-" + variantIndex +"-");
220
                        $(value).attr('id', str);
221
                    }
222
                    // for attributes
223
                    str = $(value).attr('for');
224
                    if (str) {
225
                        str = str.replace(/\-([0-9]+)\-/g, "-" + variantIndex +"-");
226
                        $(value).attr('for', str);
227
                    }
228
                    // Name attributes
229
                    str = $(value).attr('name');
230
                    if (str) {
231
                        str = str.replace(/\[([0-9]+)\]/g, "[" + variantIndex +"]");
232
                        $(value).attr('name', str);
233
                    }
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
            });
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...
236
            var disabledDeleteItem = false;
237
            // If we only have one block, don't allow it to be deleted
238
            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...
239
                disabledDeleteItem = true;
240
            }
241
            $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...
242
                var $value = $(value);
243
                var menuBtn;
244
                if ($value.data('menubtn')) {
245
                    menuBtn = $value.data('menubtn');
246
                    $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...
247
                    if (disabledDeleteItem) {
248
                        $menuItem.find("> li > a").addClass('disabled').disable();
249
                    } else {
250
                        $menuItem.find("> li > a").removeClass('disabled').enable();
251
                    }
252
                }
253
            });
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...
254
255
        },
256
257
        addAspectRatioHandlers: function () {
258
            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...
259
                var $target = $(ev.target);
260
                var $block = $target.closest('.matrixblock');
261
                $block.find('.io-aspect-ratio-wrapper').slideToggle();
262
            });
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...
263
            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...
264
                var $target = $(ev.target);
265
                var x = $(ev.target).data('x'),
266
                    y = $(ev.target).data('y'),
267
                    custom = $(ev.target).data('custom'),
268
                    field, $block;
269
                // Select the appropriate aspect ratio
270
                $block = $target.closest('.matrixblock');
271
                $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...
272
                    $(value).removeClass('io-selected-ar-box');
273
                });
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...
274
                $target.addClass('io-selected-ar-box');
275
276
                // Handle setting the actual field values
277
                if (custom) {
278
                    $block.find('.io-custom-ar-wrapper').slideDown();
279
                } else {
280
                    $block.find('.io-custom-ar-wrapper').slideUp();
281
                    field = $block.find('input')[2];
282
                    $(field).val(x);
283
                    field = $block.find('input')[3];
284
                    $(field).val(y);
285
                }
286
            });
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...
287
        },
288
289
        addVariantBlock: function(container) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
290
            var _this = this;
291
            $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...
292
            // Reset to default values
293
            $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...
294
                if (index === 0) {
295
                    $(value).addClass('io-selected-ar-box');
296
                } else {
297
                    $(value).removeClass('io-selected-ar-box');
298
                }
299
            });
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
            $block.find('.io-custom-ar-wrapper').hide();
301
            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...
302
            $(field).val(1200);
303
            field = $block.find('input')[1];
304
            $(field).val(1);
305
            field = $block.find('input')[2];
306
            $(field).val(16);
307
            field = $block.find('input')[3];
308
            $(field).val(9);
309
            field = $block.find('select')[0];
310
            $(field).val(82);
311
            field = $block.find('select')[1];
312
            $(field).val('jpg');
313
            $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...
314
                opacity: 1,
315
                'margin-bottom': 10
316
            }, '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...
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...
317
318
                // Insert the block in the right place
319
                if (container) {
320
                    $block.insertBefore(container);
321
                } else {
322
                    $block.appendTo(this.$blockContainer);
323
                }
324
                // Update the Garnish UI controls
325
                this.blockSort.addItems($block);
326
                this.addAspectRatioHandlers();
327
                $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...
328
                    var $value = $(value),
329
                        menuBtn,
330
                        menu;
331
332
                    menu = _this.$container.find('.io-menu-clone > .menu').clone();
333
                    $(menu).insertAfter($value);
334
                    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...
335
336
                    menuBtn.menu.settings.onOptionSelect = $.proxy(function(option) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
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...
337
                        _this.onMenuOptionSelect(option, menuBtn);
338
                    }, 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...
339
                });
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...
340
                this.reIndexVariants();
341
            }, 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...
342
        },
343
344
        deleteVariantBlock: function(container) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
345
            var _this = this;
346
            container.velocity(this.getHiddenBlockCss(container), 'fast', $.proxy(function() {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
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...
347
                container.remove();
348
                _this.reIndexVariants();
349
            }, 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...
350
        },
351
352
        resetVariantBlockOrder: function() {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
353
            this.reIndexVariants();
354
        }
355
356
    });
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...
357