aboutsummaryrefslogtreecommitdiffstats
path: root/js
diff options
context:
space:
mode:
authorpiernov <piernov@piernov.org>2016-05-04 14:39:10 +0200
committerpiernov <piernov@piernov.org>2016-05-04 14:39:10 +0200
commit30e4f5f70aef5de687bc021f8f7a1b34f209063f (patch)
treeffa3187c93dabafdb5a4ce9c1159381b297e3c1a /js
parent676ea92ed1c88b7490feb17f90978f613783293d (diff)
parentec7771705d62d09fcd142c87f4941604f31c1d76 (diff)
downloadcandybox-30e4f5f70aef5de687bc021f8f7a1b34f209063f.tar.gz
candybox-30e4f5f70aef5de687bc021f8f7a1b34f209063f.tar.bz2
candybox-30e4f5f70aef5de687bc021f8f7a1b34f209063f.tar.xz
candybox-30e4f5f70aef5de687bc021f8f7a1b34f209063f.zip
Merge branch 'feat/savegame' into piernov
Diffstat (limited to 'js')
-rw-r--r--js/craftmine.js5
-rw-r--r--js/savegame.js19
2 files changed, 21 insertions, 3 deletions
diff --git a/js/craftmine.js b/js/craftmine.js
index ffc9b5e..61abbf7 100644
--- a/js/craftmine.js
+++ b/js/craftmine.js
@@ -8,10 +8,10 @@ data = {
icon : "H"
}
-function sendRequest(url, params, callback) {
+function sendRequest(url, params, callback, isFile) {
var xhr = new XMLHttpRequest();
xhr.open("POST", url);
- xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+ if(!isFile) xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
if(xhr.readyState == XMLHttpRequest.DONE && xhr.status == "200") {
var data = "";
@@ -71,5 +71,6 @@ function updateMine() {
function init() {
initCraftMine();
changeTab();
+ listSaves();
window.setInterval(updateMine, 1000);
}
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);
+}