Conditions | 4 |
Total Lines | 68 |
Code Lines | 51 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | |||
63 | function updateFileList() |
||
64 | { |
||
65 | /* |
||
66 | const filesArray = Array.from(g_oDropFile.dataTransfer.files); |
||
67 | if (filesArray.length > 1) { |
||
68 | g_oDropFile.oSelectedFiles.innerHTML = '<p>Selected files:</p><ul><li>' + filesArray.map(f => f.name).join('</li><li>') + '</li></ul>'; |
||
69 | } else if (filesArray.length == 1) { |
||
70 | g_oDropFile.oSelectedFiles.innerHTML = `<p>Selected file: ${filesArray[0].name}</p>`; |
||
71 | } else { |
||
72 | g_oDropFile.oSelectedFiles.innerHTML = ''; |
||
73 | } |
||
74 | */ |
||
75 | if (g_oDropFile.dataTransfer.files.length === 0) { |
||
76 | g_oDropFile.oSelectedFiles.innerHTML = ''; |
||
77 | return; |
||
78 | } |
||
79 | const aCSSClasses = { |
||
80 | 'image/jpg' : 'imgfile', |
||
81 | 'image/jpeg' : 'imgfile', |
||
82 | 'image/png' : 'imgfile', |
||
83 | 'image/gif' : 'imgfile', |
||
84 | 'image/bmp' : 'imgfile', |
||
85 | 'image/svg+xml' : 'imgfile', |
||
86 | 'application/pdf' : 'pdffile', |
||
87 | 'application/vnd.ms-excel' : 'xlsfile', |
||
88 | 'application/msexcel' : 'xlsfile', |
||
89 | 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' : 'xlsfile', |
||
90 | 'text/csv' : 'xlsfile', |
||
91 | 'application/vnd.ms-word' : 'docfile', |
||
92 | 'application/msword' : 'docfile', |
||
93 | 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' : 'docfile', |
||
94 | 'text/x-vcard' : 'vcard', |
||
95 | 'text/calendar' : 'ical', |
||
96 | 'application/zip' : 'archive', |
||
97 | 'application/x-zip-compressed' : 'archive', |
||
98 | 'application/vnd.rar' : 'archive', |
||
99 | 'application/x-rar-compressed' : 'archive', |
||
100 | 'application/x-tar' : 'archive', |
||
101 | 'application/x-tar-compressed' : 'archive', |
||
102 | 'application/x-7z-compressed' : 'archive', |
||
103 | 'audio/mpeg' : 'audiofile', |
||
104 | 'audio/mp3' : 'audiofile', |
||
105 | 'video/mpeg' : 'videofile', |
||
106 | 'video/mp4' : 'videofile', |
||
107 | 'video/x-msvideo' : 'videofile', |
||
108 | }; |
||
109 | var strSelectedFiles = ''; |
||
110 | for (var i = 0; i < g_oDropFile.dataTransfer.files.length; i++) { |
||
111 | var strCSSClass = 'file'; |
||
112 | if (aCSSClasses[g_oDropFile.dataTransfer.files[i].type]) { |
||
113 | strCSSClass += ' ' + aCSSClasses[g_oDropFile.dataTransfer.files[i].type]; |
||
114 | } |
||
115 | const EOL = "\n"; |
||
116 | const strName = g_oDropFile.dataTransfer.files[i].name; |
||
117 | const strOnClick = "deleteSelectedFile(" + i + ", '" + strName + "');"; |
||
118 | const strDeleteFromList = 'Eintrag aus der Liste entfernen'; |
||
119 | |||
120 | strSelectedFiles += '<div class="dropfileitem">' + EOL; |
||
121 | strSelectedFiles += ' <div class="dropedfile">' + EOL; |
||
122 | strSelectedFiles += ' <div class="dropedname">' + EOL; |
||
123 | strSelectedFiles += ' <span class="' + strCSSClass + '" title="' + strName + '">' + strName + '</span>' + EOL; |
||
124 | strSelectedFiles += ' </div>' + EOL; |
||
125 | strSelectedFiles += ' <div class="dropeddelete" onclick="' + strOnClick + '" title="' + strDeleteFromList + '"></div>' + EOL; |
||
126 | strSelectedFiles += ' </div>' + EOL; |
||
127 | strSelectedFiles += '</div>' + EOL; |
||
128 | } |
||
129 | g_oDropFile.oSelectedFiles.innerHTML = strSelectedFiles; |
||
130 | } |
||
131 | |||
142 |
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.