aboutsummaryrefslogtreecommitdiffstats
path: root/js
diff options
context:
space:
mode:
authorpiernov <piernov@piernov.org>2016-05-04 14:27:59 +0200
committerpiernov <piernov@piernov.org>2016-05-04 14:27:59 +0200
commit80f61cc5216fe020f82fc303317e4098acb5d21d (patch)
tree80ed24dc6fcc49576f0c185b2401364cb450112e /js
parent9ce1da5147b3df01812687562faca80623b27a38 (diff)
downloadcandybox-80f61cc5216fe020f82fc303317e4098acb5d21d.tar.gz
candybox-80f61cc5216fe020f82fc303317e4098acb5d21d.tar.bz2
candybox-80f61cc5216fe020f82fc303317e4098acb5d21d.tar.xz
candybox-80f61cc5216fe020f82fc303317e4098acb5d21d.zip
AJAX upload file
Diffstat (limited to 'js')
-rw-r--r--js/savegame.js19
1 files changed, 18 insertions, 1 deletions
diff --git a/js/savegame.js b/js/savegame.js
index 4a08f91..d5a9ba1 100644
--- a/js/savegame.js
+++ b/js/savegame.js
@@ -24,7 +24,9 @@ function loadSave() {
}
function downloadSave() {
- window.open("craftmine.php?op=downSave&filename="+getCheckedSave(), "_blank");
+ var filename = getCheckedSave();
+ if(filename == -1) downGame();
+ else window.open("craftmine.php?op=downSave&filename="+getCheckedSave(), "_blank");
}
function deleteSave() {
@@ -40,3 +42,18 @@ function saveGame() {
function downGame() {
window.open("craftmine.php?op=downSave", "_blank");
}
+
+function uploadSave() {
+ var selectedFile = document.getElementById("selectedFile");
+ if(selectedFile.files[0].size > 2000000) {
+ showError("File is too big.");
+ return;
+ }
+
+ var form = new FormData(); // Doesn't work with IE < 10 (and Opera Mini), but, as always, who cares?
+ form.append("savefile", selectedFile.files[0]);
+
+ sendRequest("upload.php", form, function(ret) {
+ console.log(ret);
+ }, true);
+}