GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( a910b0...a0e75b )
by
unknown
04:10
created

image-preview.js ➔ displayUploadedImage   C

Complexity

Conditions 11

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 12
c 0
b 0
f 0
dl 0
loc 19
rs 5.4
cc 11

How to fix   Complexity   

Complexity

Complex classes like image-preview.js ➔ displayUploadedImage often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
(function ( $ ) {
2
    'use strict';
3
4
    $.fn.extend({
5
        previewUploadedImage: function (root) {
6
            $(root + ' input[type="file"]').each(function() {
7
                $(this).change(function() {
8
                    displayUploadedImage(this);
9
                });
10
            });
11
12
            $(root + ' [data-form-collection="add"]').on('click', function() {
13
                var self = $(this);
14
15
                setTimeout(function() {
16
                    self.parent().find('.column:last-child input[type="file"]').on('change', function() {
17
                        displayUploadedImage(this);
18
                    });
19
                }, 500);
20
            });
21
        }
22
    });
23
24
    function displayUploadedImage(input) {
25
        if (input.files && input.files[0]) {
26
            var reader = new FileReader();
0 ignored issues
show
Bug introduced by
The variable FileReader seems to be never declared. If this is a global, consider adding a /** global: FileReader */ 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...
27
28
            reader.onload = function (e) {
29
                var image = $(input).parent().siblings('.image');
30
31
                if (image.length > 0) {
32
                    image.attr('src', e.target.result);
33
                } else {
34
                    var img = $('<img class="ui small bordered image"/>');
35
                    img.attr('src', e.target.result);
36
                    $(input).parent().before(img);
37
                }
38
            };
39
40
            reader.readAsDataURL(input.files[0]);
41
        }
42
    }
43
})( jQuery );
44
45
(function($) {
46
    $(document).ready(function () {
47
        $(document).previewUploadedImage('#odiseo-image')
48
    });
49
})(jQuery);
50