Total Complexity | 13 |
Complexity/F | 1.18 |
Lines of Code | 49 |
Function Count | 11 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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(); |
||
|
|||
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 |
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.