diff options
author | Alex Xu <alex_y_xu@yahoo.ca> | 2013-07-13 10:40:07 -0400 |
---|---|---|
committer | Alex Xu <alex_y_xu@yahoo.ca> | 2013-07-13 10:40:07 -0400 |
commit | 62f7bd5ecd17be14b0f21f6044e695179d6458cd (patch) | |
tree | 69ccee0eda0cb7affb6a57236ec17e2f0c1eeaed /www/js | |
parent | abff23e68509733a1ca0b466a4dc6ee0d33d6e2f (diff) | |
download | html5ks-62f7bd5ecd17be14b0f21f6044e695179d6458cd.tar.xz html5ks-62f7bd5ecd17be14b0f21f6044e695179d6458cd.zip |
Fix... stuff.
Diffstat (limited to 'www/js')
-rw-r--r-- | www/js/api.js | 91 | ||||
-rw-r--r-- | www/js/html5ks.js | 2 | ||||
-rw-r--r-- | www/js/menu.js | 4 |
3 files changed, 46 insertions, 51 deletions
diff --git a/www/js/api.js b/www/js/api.js index c3c9f48..4aebde1 100644 --- a/www/js/api.js +++ b/www/js/api.js @@ -170,50 +170,15 @@ window.html5ks.api = { }, // NOT iscene scene: function (type, name) { - var deferred = when.defer(), - nom = type; - if (name) { - nom = type + "_" + name; - } - var img = new Image(); - var image = html5ks.data.images[nom]; - if (!image) { - var typ = { - "bg": {dir:"bgs",ext:"jpg"} - }[type]; - image = typ.dir + "/" + name + "." + typ.ext; - } - var bg = html5ks.elements.bg; - if (typeof image == "string") { - if (image.substring(0,1) == "#") { - bg.style.background = ""; - bg.style.backgroundColor = image; - deferred.resolve(); - return deferred.promise; - } else { - image = {image: image}; - } - } - img.onload = function () { - console.debug("setting bg " + img.src); - bg.style.background = ""; - bg.style.backgroundImage = "url(" + img.src + ")"; - bg.style.backgroundSize = "cover"; - deferred.resolve(); - }; - img.onerror = function () { - throw new Error("bg could not load"); - }; - if (Modernizr.webp) { - image.image = image.image.replace(/\.[a-z]+$/, ".webp"); - } - img.src = "dump/" + image.image; - return deferred.promise; + html5ks.elements.show.innerHTML = ""; + return this.show.apply(this, arguments); }, show: function (name, type, location) { var deferred = when.defer(); - var el = document.getElementById(name) || document.createElement("img"); + var lookup = document.getElementById(name), + el = lookup || document.createElement("img"); + if (!location && !lookup) location = "center"; el.onload = function () { if (location) { // calculate position @@ -249,17 +214,49 @@ window.html5ks.api = { // TODO: check if img is really in images.js deferred.resolve(); }; - var src = "dump/sprites/" + name + "/" + name + "_" + type + "."; + var nom = name; + if (type) { + nom = name + "_" + type; + } + var image = html5ks.data.images[nom]; + if (typeof image == "undefined") { + switch (name) { + case "bg": + image = "bgs/" + type + ".jpg"; + break; + case "url": + name = type; + image = type; + break; + default: + image = "sprites/" + name + "/" + name + "_" + type + ".png"; + } + } + if (typeof image == "string") { + if (image.substring(0,1) == "#") { + el.style.backgroundColor = image; + el.style.width = "100%"; + el.style.height = "100%"; + el.src = ""; + deferred.resolve(); + return deferred.promise; + } else { + image = {image: image}; + } + } + var src = ""; if (html5ks.persistent.settings.useWebP) { - src += "webp"; + src = image.image.replace(/\.[a-z]+$/, ".webp"); } else { - src += "png"; + src = image.image; } el.id = name; - el.src = src; + el.src = "dump/" + src; // prevent FOUIPC (flash of incorrectly placed content) - if (location) el.style.display = "none"; - html5ks.elements.show.appendChild(el); + if (!lookup) { + el.style.display = "none"; + html5ks.elements.show.appendChild(el); + } deferred.resolve(); return deferred.promise; }, @@ -439,7 +436,7 @@ window.html5ks.api = { frag = document.createDocumentFragment(), choice = document.createElement("div"); - choice.className = "choice button button-enabled"; + choice.className = "choice button"; for (var i in choices) { choice.innerHTML = i; diff --git a/www/js/html5ks.js b/www/js/html5ks.js index 354bae8..8a174dc 100644 --- a/www/js/html5ks.js +++ b/www/js/html5ks.js @@ -41,7 +41,6 @@ window.html5ks = { }, who: document.getElementById("who"), say: document.getElementById("say"), - bg: document.getElementById("bg"), window: document.getElementById("window"), ctc: document.getElementById("ctc"), nvl: document.getElementById("nvl"), @@ -91,7 +90,6 @@ window.html5ks = { } }; - applyScale(html5ks.elements.bg, newScale); if (html5ks.persistent.settings.scaleVideo) { applyScale(html5ks.elements.video, newScale); } diff --git a/www/js/menu.js b/www/js/menu.js index a57f9a0..ca0637f 100644 --- a/www/js/menu.js +++ b/www/js/menu.js @@ -7,7 +7,7 @@ html5ks.api.stop("ambient"); html5ks.api.window("hide"); html5ks.api.play("music", "music_menus"); - html5ks.elements.bg.style.background = "url(dump/ui/main/bg-main.png) 0 0 / cover"; + html5ks.api.show("url", "ui/main/bg-main.png"); this.elements.mainMenu.style.display = "block"; }, @@ -77,7 +77,7 @@ }, false); html5ks.fetch("imachine").then(function () { var start = this.elements.main.start; - start.className = start.className.replace("button-disabled", "button-enabled"); + start.className = start.className.replace("button-disabled", ""); this._imachine_loaded = true; }.bind(this)); } |