diff options
Diffstat (limited to 'www/js')
-rw-r--r-- | www/js/api.js | 66 | ||||
-rw-r--r-- | www/js/characters.js | 4 | ||||
-rw-r--r-- | www/js/html5ks.js | 2 | ||||
-rw-r--r-- | www/js/imachine.js | 2 |
4 files changed, 35 insertions, 39 deletions
diff --git a/www/js/api.js b/www/js/api.js index 1cf9fbe..edc37b6 100644 --- a/www/js/api.js +++ b/www/js/api.js @@ -29,7 +29,7 @@ window.html5ks.api = { play: function (channel, name, ignore, fade) { this.stop(channel); var deferred = when.defer(), - audio = new Audio(); + audio = html5ks.elements.audio[channel]; if (channel === "music" || channel === "ambient") { audio.loop = true; } @@ -38,15 +38,15 @@ window.html5ks.api = { audio.load(); audio.volume = fade ? 0 : 1; audio.play(); - audio.addEventListener("playing", function playing() { + audio.onplaying = function () { deferred.resolve(); if (fade) { html5ks.api.set_volume(1, fade, channel); } - }, false); - audio.addEventListener("error", function error() { + }; + audio.onerror = function () { deferred.reject(this.error); - }, false); + }; return deferred.promise; }, @@ -88,30 +88,25 @@ window.html5ks.api = { video.play(); var done = function () { video.style.display = "none"; - // clear event listeners - var oldVideo = document.getElementById("vid"); - oldVideo.pause(); - var newVideo = video.cloneNode(true); - oldVideo.parentNode.replaceChild(newVideo, oldVideo); - html5ks.elements.video = newVideo; + video.pause(); deferred.resolve(); }; document.addEventListener("keyup", function keyupListener(e) { + document.removeEventListener("keyup", keyupListener, false); if (e.keyCode === 27) { done(); e.preventDefault(); - e.stopPropagation(); } }, false); - video.addEventListener("click", function clickListener(e) { + video.onclick = function (e) { if (e.button === 0 && skippable) { done(); } - }, false); - video.addEventListener("ended", done, false); - video.addEventListener("error", function () { + }; + video.onended = done; + video.onerror = function () { deferred.reject(this.error); - }, false); + }; return deferred.promise; }, @@ -207,7 +202,7 @@ window.html5ks.api = { bgleft: { xpos: 0.4, xanchor: 0.5, ypos: 1.0, yanchor: 1.0 }, bgright: { xpos: 0.6, xanchor: 0.5, ypos: 1.0, yanchor: 1.0 } }; - var pos = positions[location] || positions.center; + var pos = positions[location]; // TODO: implement transitions if (pos) { el.style.left = pos.xpos * 800 + "px"; @@ -229,13 +224,16 @@ window.html5ks.api = { var image = html5ks.data.images[nom]; switch (typeof image) { case "string": - el = document.createElement("div"); - el.style.backgroundColor = image; - el.style.width = "100%"; - el.style.height = "100%"; - el.src = ""; - deferred.resolve(); - return deferred.promise; + if (image.substring(0, 1) === "#") { + el = document.createElement("div"); + el.style.backgroundColor = image; + el.style.width = "100%"; + el.style.height = "100%"; + el.src = ""; + deferred.resolve(); + return deferred.promise; + } + break; case "undefined": switch (name) { case "bg": @@ -326,10 +324,12 @@ window.html5ks.api = { if (!char) { char = { name: name, - what_prefix: "“", - what_suffix: "”" }; } + if (typeof char.what_prefix === "undefined") { + char.what_prefix = "“"; + char.what_suffix = "”"; + } if (!extend && char.what_prefix) { text = char.what_prefix + text; } @@ -433,13 +433,8 @@ window.html5ks.api = { return deferred.promise; }, - menu: function (label) { - var deferred = when.defer(), - imenu = html5ks.data.script[label], - char = imenu[1], - str = imenu[2], - choices = imenu[3]; - this.character(char, str, null, true); + menu: function (choices) { + var deferred = when.defer(); var menu = html5ks.elements.choices, frag = document.createDocumentFragment(), choice = document.createElement("div"); @@ -448,13 +443,14 @@ window.html5ks.api = { for (var i in choices) { choice.innerHTML = i; + choice.id = choices[i]; frag.appendChild(choice); choice = choice.cloneNode(false); } menu.addEventListener("click", function (e) { html5ks.elements.choices.innerHTML = ""; - deferred.resolve(choices[e.target.innerHTML]); + deferred.resolve(e.target.id); }, false); html5ks.elements.choices.appendChild(frag); diff --git a/www/js/characters.js b/www/js/characters.js index 9138e5b..c5d41d6 100644 --- a/www/js/characters.js +++ b/www/js/characters.js @@ -1,5 +1,5 @@ window.html5ks.data.characters = { - name_only: {name: ""}, + name_only: {name: "", what_prefix: "", what_suffix: ""}, hi: {name: "Hisao", color: "#629276"}, @@ -47,7 +47,7 @@ window.html5ks.data.characters = { hh_: {name: "Slim girl", color: "#6299FF"}, emm_: {name: "Woman with braid", color: "#995050"}, - n: {name: null, kind: "nvl"}, + n: {name: null, kind: "nvl", what_prefix: "", what_suffix: ""}, nb: {name: null, ctc: null, diff --git a/www/js/html5ks.js b/www/js/html5ks.js index 182d08a..fc3f99a 100644 --- a/www/js/html5ks.js +++ b/www/js/html5ks.js @@ -107,7 +107,7 @@ window.html5ks = { } }, initEvents: function () { - window.addEventListener("resize", html5ks.scale, false); + window.onresize = html5ks.scale; this.elements.container.addEventListener("mouseup", function () { html5ks.next(); }, false); diff --git a/www/js/imachine.js b/www/js/imachine.js index b6117f7..16d406f 100644 --- a/www/js/imachine.js +++ b/www/js/imachine.js @@ -43,7 +43,7 @@ html5ks.imachine = (function () { } break; case "imenu": - html5ks.api.menu(args[0]).then(function (choice) { + html5ks.api.iscene(args[0]).then(function (choice) { var next = args[1][choice] || args[1].else; return html5ks.imachine.run(typeof next[0] === "string" ? [next] : next).then(runInst); }); |