From f77d6c590bf683377986064113ddddae9ed443c2 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 20 Mar 2016 15:45:02 -0400 Subject: Added Markdown editor and Javascript code refactoring --- assets/js/src/FileUpload.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'assets/js/src/FileUpload.js') diff --git a/assets/js/src/FileUpload.js b/assets/js/src/FileUpload.js index a8816bcd..f53b9bf8 100644 --- a/assets/js/src/FileUpload.js +++ b/assets/js/src/FileUpload.js @@ -1,10 +1,10 @@ -function FileUpload(app) { +Kanboard.FileUpload = function(app) { this.app = app; this.files = []; this.currentFile = 0; -} +}; -FileUpload.prototype.listen = function() { +Kanboard.FileUpload.prototype.onPopoverOpened = function() { var dropzone = document.getElementById("file-dropzone"); var self = this; @@ -12,7 +12,7 @@ FileUpload.prototype.listen = function() { dropzone.ondragover = dropzone.ondragenter = function(e) { e.stopPropagation(); e.preventDefault(); - } + }; dropzone.ondrop = function(e) { e.stopPropagation(); @@ -20,7 +20,7 @@ FileUpload.prototype.listen = function() { self.files = e.dataTransfer.files; self.show(); $("#file-error-max-size").hide(); - } + }; $(document).on("click", "#file-browser", function(e) { e.preventDefault(); @@ -41,7 +41,7 @@ FileUpload.prototype.listen = function() { } }; -FileUpload.prototype.show = function() { +Kanboard.FileUpload.prototype.show = function() { $("#file-list").remove(); if (this.files.length > 0) { @@ -69,7 +69,7 @@ FileUpload.prototype.show = function() { } }; -FileUpload.prototype.checkFiles = function() { +Kanboard.FileUpload.prototype.checkFiles = function() { var max = parseInt($("#file-dropzone").data("max-size")); for (var i = 0; i < this.files.length; i++) { @@ -84,13 +84,13 @@ FileUpload.prototype.checkFiles = function() { this.uploadFiles(); }; -FileUpload.prototype.uploadFiles = function() { +Kanboard.FileUpload.prototype.uploadFiles = function() { if (this.files.length > 0) { this.uploadFile(this.files[this.currentFile]); } }; -FileUpload.prototype.uploadFile = function(file) { +Kanboard.FileUpload.prototype.uploadFile = function(file) { var dropzone = document.getElementById("file-dropzone"); var url = dropzone.dataset.url; var xhr = new XMLHttpRequest(); @@ -104,21 +104,22 @@ FileUpload.prototype.uploadFile = function(file) { xhr.send(fd); }; -FileUpload.prototype.updateProgress = function(e) { +Kanboard.FileUpload.prototype.updateProgress = function(e) { if (e.lengthComputable) { $("#file-progress-" + this.currentFile).val(e.loaded / e.total); $("#file-percentage-" + this.currentFile).text('(' + Math.floor((e.loaded / e.total) * 100) + '%)'); } }; -FileUpload.prototype.transferComplete = function() { +Kanboard.FileUpload.prototype.transferComplete = function() { this.currentFile++; if (this.currentFile < this.files.length) { this.uploadFile(this.files[this.currentFile]); } else { - $("#file-upload-button").prop("disabled", true); - $("#file-upload-button").parent().hide(); + var uploadButton = $("#file-upload-button"); + uploadButton.prop("disabled", true); + uploadButton.parent().hide(); $("#file-done").show(); } }; -- cgit v1.2.3