From f5a6c301cc9a277f024563ea656f3fe49aa89834 Mon Sep 17 00:00:00 2001 From: Alex Xu Date: Mon, 19 Aug 2013 12:17:25 -0400 Subject: www/scripts -> www/json, slim down html5ks.fetch --- .gitignore | 2 +- unrpyc/Makefile | 4 ++-- www/js/html5ks.js | 24 ++++++------------------ www/js/i18n.js | 2 ++ www/js/menu.js | 2 +- 5 files changed, 12 insertions(+), 22 deletions(-) create mode 100644 www/js/i18n.js diff --git a/.gitignore b/.gitignore index ef69786..5f229f9 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,7 @@ # generated nginx conf - see nginx.sh /nginx.gen.conf # ignore 'copyrighted' contents similar to emulators -/www/scripts +/www/json /www/dump /rpy diff --git a/unrpyc/Makefile b/unrpyc/Makefile index b64bb22..826f1e3 100644 --- a/unrpyc/Makefile +++ b/unrpyc/Makefile @@ -27,9 +27,9 @@ test: all jshint --show-non-errors *.json install: all - install -t ../www/scripts script.json script.json.gz imachine.json imachine.json.gz imachine_replay.json imachine_replay.json.gz ui-strings.json ui-strings.json.gz + install -t ../www/json script.json script.json.gz imachine.json imachine.json.gz imachine_replay.json imachine_replay.json.gz ui-strings.json ui-strings.json.gz uninstall: - rm -f ../www/scripts/* + rm -f ../www/json/* .PHONY: all clean test install diff --git a/www/js/html5ks.js b/www/js/html5ks.js index f97a1f0..aea03b1 100644 --- a/www/js/html5ks.js +++ b/www/js/html5ks.js @@ -219,42 +219,30 @@ window.html5ks = { } }, start: function () { - this.fetch("script").then(function () { + this.fetch("json", "script").then(function () { html5ks.api.movie_cutscene("4ls", true).then(function () { html5ks.menu.mainMenu(); }); }); }, - fetch: function (type) { + fetch: function (type, name) { var deferred = when.defer(); var xhr = new XMLHttpRequest(); switch (type) { - case "script": - if (html5ks.data._scriptFetched) { + case "json": + if (html5ks.data[name]) { deferred.resolve(); } else { - xhr.open("GET", "scripts/script.json"); + xhr.open("GET", "json/" + name + ".json"); xhr.onreadystatechange = function () { if (xhr.readyState === 4) { - html5ks.data._scriptFetched = true; - var script = JSON.parse(xhr.responseText); - html5ks.data.script = script; + html5ks.data[name] = JSON.parse(xhr.responseText); deferred.resolve(); } }; xhr.send(); } break; - case "imachine": - xhr.open("GET", "scripts/imachine.json"); - xhr.onreadystatechange = function () { - if (xhr.readyState === 4) { - html5ks.data.imachine = JSON.parse(xhr.responseText); - deferred.resolve(); - } - }; - xhr.send(); - break; default: throw new Error("fetchtype " + type + " not implemented"); } diff --git a/www/js/i18n.js b/www/js/i18n.js new file mode 100644 index 0000000..764a0dd --- /dev/null +++ b/www/js/i18n.js @@ -0,0 +1,2 @@ +html5ks.i18n = { + diff --git a/www/js/menu.js b/www/js/menu.js index 1e0e5a3..e4a8b2c 100644 --- a/www/js/menu.js +++ b/www/js/menu.js @@ -188,7 +188,7 @@ html5ks.imachine.start().then(this.mainMenu.bind(this)); } }.bind(this), false); - html5ks.fetch("imachine").then(function () { + html5ks.fetch("json", "imachine").then(function () { var start = this.elements.main.start; start.className = start.className.replace("disabled", ""); this._imachine_loaded = true; -- cgit v1.2.3-54-g00ecf