diff --git a/assets/js/build.js b/assets/js/build.js index cc54fe8..36e8100 100644 --- a/assets/js/build.js +++ b/assets/js/build.js @@ -197,38 +197,41 @@ build = { }, - uploadModal: function(icon, text, html) { + uploadModal: function(title, files) { var modal = ""; - if (html!==null||html!==undefined) { + modal += "
"; + + return modal; + }, contextMenu: function(items) { diff --git a/assets/js/upload.js b/assets/js/upload.js index 78769da..c54f82e 100755 --- a/assets/js/upload.js +++ b/assets/js/upload.js @@ -7,12 +7,10 @@ upload = { - show: function(icon, text, html) { - - if (icon===undefined) icon = "upload"; + show: function(title, files) { upload.close(true); - $("body").append(build.uploadModal(icon, text, html)); + $("body").append(build.uploadModal(title, files)); }, @@ -56,92 +54,95 @@ upload = { local: function(files) { var albumID = album.getID(), - html = ""; + process = function(files, file) { - var process = function(files, file) { + var formData = new FormData(), + xhr = new XMLHttpRequest(), + pre_progress = 0, + progress; - var formData = new FormData(), - xhr = new XMLHttpRequest(), - pre_progress = 0, - progress; + formData.append("function", "upload"); + formData.append("albumID", albumID); + formData.append(0, file); - formData.append("function", "upload"); - formData.append("albumID", albumID); - formData.append(0, file); + xhr.open("POST", lychee.api_path); - xhr.open("POST", lychee.api_path); + xhr.onload = function() { - xhr.onload = function() { + var wait; - var wait; + if (xhr.status===200) { - if (xhr.status===200) { + $(".upload_message .rows .row:nth-child(" + (file.num+1) + ") .status") + .html("Finished") + .addClass("success"); - $(".upload_message .rows .row:nth-child(" + (file.num+1) + ") .status") - .html("Finished") - .addClass("success"); + file.ready = true; + wait = false; - file.ready = true; - wait = false; + for (var i = 0; i < files.length; i++) { - for (var i = 0; i < files.length; i++) { + if (files[i].ready===false) { + wait = true; + break; + } + + } + + if (wait===false) { + + window.onbeforeunload = null; + + $("#upload_files").val(""); + + if (album.getID()===false) lychee.goto("0"); + else album.load(albumID); - if (files[i].ready===false) { - wait = true; - break; } } - if (wait===false) { + }; - $("#upload_files").val(""); + xhr.upload.onprogress = function(e) { - if (album.getID()===false) lychee.goto("0"); - else album.load(albumID); + if (e.lengthComputable) { + + progress = (e.loaded / e.total * 100 | 0); + + if (progress>pre_progress) { + $(".upload_message .rows .row:nth-child(" + (file.num+1) + ") .status").html(progress + "%"); + pre_progress = progress; + } + + if (progress>=100) { + + /*$(".upload_message .rows").animate({ + scrollTop: $(".upload_message .rows .row:nth-child(" + (file.num+1) + ")").offset().top - 200 + }, 0);*/ + + $(".upload_message .rows .row:nth-child(" + (file.num+1) + ") .status").html("Processing"); + + if (file.next!==null) process(files, file.next); + + } } - } + }; - }; + xhr.send(formData); - xhr.upload.onprogress = function(e) { - - if (e.lengthComputable) { - - progress = (e.loaded / e.total * 100 | 0); - - if (progress>pre_progress) { - $(".upload_message .rows .row:nth-child(" + (file.num+1) + ") .status").html(progress + "%"); - pre_progress = progress; - } - - if (progress>=100) { - - $(".upload_message .rows .row:nth-child(" + (file.num+1) + ") .status").html("Processing"); - - if (file.next!==null) process(files, file.next); - - } - - } - - }; - - xhr.send(formData); - - } + } if (files.length<=0) return false; if (albumID===false) albumID = 0; - html = "