| Conditions | 1 |
| Paths | 1 |
| Total Lines | 137 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 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 | document.addEventListener("DOMContentLoaded", function () { |
||
| 2 | |||
| 3 | Dropzone.autoDiscover = false; |
||
|
|
|||
| 4 | |||
| 5 | Dropzone.prototype.queueButtonsInit = function () { |
||
| 6 | this.queueButtonsObserve(); |
||
| 7 | this.queueButtonsState(0); |
||
| 8 | }; |
||
| 9 | |||
| 10 | Dropzone.prototype.queueButtonsObserve = function () { |
||
| 11 | var instance = this; |
||
| 12 | document.querySelector("#actions .start").addEventListener("click", function () { |
||
| 13 | instance.enqueueFiles(instance.getFilesWithStatus(Dropzone.ADDED)); |
||
| 14 | }, false); |
||
| 15 | document.querySelector("#actions .cancel").addEventListener("click", function () { |
||
| 16 | instance.removeAllFiles(true); |
||
| 17 | }, false); |
||
| 18 | }; |
||
| 19 | |||
| 20 | Dropzone.prototype.queueButtonsState = function (state) { |
||
| 21 | if (state === 1) { |
||
| 22 | document.querySelector("#actions .start").removeAttribute("disabled"); |
||
| 23 | document.querySelector("#actions .start").style.opacity = "1"; |
||
| 24 | document.querySelector("#actions .cancel").removeAttribute("disabled"); |
||
| 25 | document.querySelector("#actions .cancel").style.opacity = "1"; |
||
| 26 | } else { |
||
| 27 | document.querySelector("#actions .start").setAttribute("disabled", "disabled"); |
||
| 28 | document.querySelector("#actions .start").style.opacity = "0"; |
||
| 29 | document.querySelector("#actions .cancel").setAttribute("disabled", "disabled"); |
||
| 30 | document.querySelector("#actions .cancel").style.opacity = "0"; |
||
| 31 | } |
||
| 32 | }; |
||
| 33 | |||
| 34 | // Get the template HTML and remove it from the doumenthe template HTML and remove it from the doument |
||
| 35 | var previewNode = document.querySelector("#dropzone-file-template"); |
||
| 36 | previewNode.id = ""; |
||
| 37 | |||
| 38 | var previewTemplate = previewNode.parentNode.innerHTML; |
||
| 39 | previewNode.parentNode.removeChild(previewNode); |
||
| 40 | |||
| 41 | |||
| 42 | var myDropzone = new Dropzone('form.dropzone-gallery', { // Make the whole body a dropzone |
||
| 43 | thumbnailWidth: 200, |
||
| 44 | thumbnailHeight: 200, |
||
| 45 | parallelUploads: 20, |
||
| 46 | previewTemplate: previewTemplate, |
||
| 47 | previewsContainer: "#dropzone-previews", |
||
| 48 | autoQueue: false, // Make sure the files aren't queued until manually added |
||
| 49 | clickable: ".fileinput-button", // Define the element that should be used as click trigger to select files. |
||
| 50 | |||
| 51 | init: function () { |
||
| 52 | this.queueButtonsInit(); |
||
| 53 | |||
| 54 | this.on("addedfile", function (file) { |
||
| 55 | // Hookup the start button |
||
| 56 | file.previewElement.querySelector(".start").onclick = function () { |
||
| 57 | myDropzone.enqueueFile(file); |
||
| 58 | }; |
||
| 59 | |||
| 60 | this.queueButtonsState(1); |
||
| 61 | }); |
||
| 62 | |||
| 63 | // Update the total progress bar |
||
| 64 | this.on("totaluploadprogress", function (progress) { |
||
| 65 | document.querySelector("#total-progress .progress-bar").style.width = progress + "%"; |
||
| 66 | }); |
||
| 67 | |||
| 68 | this.on("sending", function (file) { |
||
| 69 | // Show the total progress bar when upload starts |
||
| 70 | document.querySelector("#total-progress").style.opacity = "1"; |
||
| 71 | // And disable the start button |
||
| 72 | file.previewElement.querySelector(".start").setAttribute("disabled", "disabled"); |
||
| 73 | }); |
||
| 74 | |||
| 75 | this.on("success", function (file, response) { |
||
| 76 | file.previewElement.querySelector('.dz-progress').style.opacity = "0"; |
||
| 77 | file.previewElement.querySelector('.dz-size').style.opacity = "0"; |
||
| 78 | file.previewElement.querySelector('.dz-error-message').style.opacity = "0"; |
||
| 79 | |||
| 80 | $(file.previewElement.querySelector(".cancel")).hide(); |
||
| 81 | file.previewElement.querySelector(".delete").style.display = "inline"; |
||
| 82 | }); |
||
| 83 | |||
| 84 | this.on("error", function (file, response, XMLHttpRequest) { |
||
| 85 | }); |
||
| 86 | |||
| 87 | // Hide the total progress bar when nothing's uploading anymore |
||
| 88 | this.on("queuecomplete", function (progress) { |
||
| 89 | document.querySelector("#total-progress").style.opacity = "0"; |
||
| 90 | |||
| 91 | this.queueButtonsState(0); |
||
| 92 | }); |
||
| 93 | } |
||
| 94 | }); |
||
| 95 | |||
| 96 | // function () { |
||
| 97 | // |
||
| 98 | // } |
||
| 99 | |||
| 100 | // Dropzone.options.myAwesomeDropzone = { |
||
| 101 | // paramName: "file", |
||
| 102 | // maxFilesize: 10, |
||
| 103 | // url: 'UploadImages', |
||
| 104 | // previewsContainer: "#dropzone-previews", |
||
| 105 | // uploadMultiple: true, |
||
| 106 | // parallelUploads: 5, |
||
| 107 | // maxFiles: 20, |
||
| 108 | // init: function () { |
||
| 109 | // var cd; |
||
| 110 | // this.on("success", function (file, response) { |
||
| 111 | // $('.dz-progress').hide(); |
||
| 112 | // $('.dz-size').hide(); |
||
| 113 | // $('.dz-error-mark').hide(); |
||
| 114 | // console.log(response); |
||
| 115 | // console.log(file); |
||
| 116 | // cd = response; |
||
| 117 | // }); |
||
| 118 | // this.on("addedfile", function (file) { |
||
| 119 | // var removeButton = Dropzone.createElement("<a href=\"#\">Remove file</a>"); |
||
| 120 | // var _this = this; |
||
| 121 | // removeButton.addEventListener("click", function (e) { |
||
| 122 | // e.preventDefault(); |
||
| 123 | // e.stopPropagation(); |
||
| 124 | // _this.removeFile(file); |
||
| 125 | // var name = "largeFileName=" + cd.pi.largePicPath + "&smallFileName=" + cd.pi.smallPicPath; |
||
| 126 | // $.ajax({ |
||
| 127 | // type: 'POST', |
||
| 128 | // url: 'DeleteImage', |
||
| 129 | // data: name, |
||
| 130 | // dataType: 'json' |
||
| 131 | // }); |
||
| 132 | // }); |
||
| 133 | // file.previewElement.appendChild(removeButton); |
||
| 134 | // }); |
||
| 135 | // } |
||
| 136 | // }; |
||
| 137 | }); |
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.