diff options
| author | Alex Pickering <alex@cogarr.net> | 2026-02-01 13:14:32 -0600 |
|---|---|---|
| committer | Alexander M Pickering <alex@cogarr.net> | 2026-02-01 13:14:32 -0600 |
| commit | 3a975db66a3711f34e8b64bb27a8eaca79fdeca9 (patch) | |
| tree | fcc12f8f9d638ff575c1963796de76b7628854b4 /src/textbox_bridge.js | |
| download | ggj26-master.tar.gz ggj26-master.tar.bz2 ggj26-master.zip | |
Diffstat (limited to 'src/textbox_bridge.js')
| -rw-r--r-- | src/textbox_bridge.js | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/textbox_bridge.js b/src/textbox_bridge.js new file mode 100644 index 0000000..c52902e --- /dev/null +++ b/src/textbox_bridge.js @@ -0,0 +1,74 @@ + +var i = 0; +/* Detour SDL.receiveEvent to we can focus textboxes + */ + +var oldReceive = SDL.receiveEvent; +SDL.receiveEvent = function(e){ + console.log("Intercepting event!"); + return oldReceive(e); +}; +window.TEXTBOX = { + create_textbox: function(tbl) { + var value = tbl.value; + var palceholder = tbl.placeholder; + var s = document.createElement('input'); + s.setAttribute("type","text"); + s.setAttribute("id","textbox" + i); + s.setAttribute("style","z-index: 1; position:absolute; visibility:hidden;"); + var p = document.getElementById("container"); + var noop = function(){}; + p.prepend(s); + console.log("[JS] Added textbox" + i, s); + /* None of these work, amulet intercepts the keys */ + /* + s.addEventListener("keypress",function(e) { + console.log("Keypress on the textbox"); + }); + s.addEventListener("keyup",function(e) { + console.log("keyup on the textbox"); + }); + s.addEventListener("keydown",function(e) { + console.log("keydown on the textbox"); + }); + */ + s.addEventListener("focusin",function(e){ + e.preventDefault = noop; + }); + s.addEventListener("focusout",function(e){ + e.preventDefault = noop; + }); + // When we get an event, stop amulet from doing .preventDefault() + s.addEventListener("keypress",function(e){ + e.preventDefault = noop; + }); + s.addEventListener("keyup",function(e){ + e.preventDefault = noop; + }); + s.addEventListener("keydown",function(e){ + e.preventDefault = noop; + }); + i++; + return i; + }, + focus: function(tbl) { + var id = tbl.id; + var e = document.getElementById("textbox" + id); + e.setAttribute("style","z-index: 1; position:absolute;"); + console.log("[JS] Clicking element", e); + e.focus(); + }, + blur: function(tbl) { + var id = tbl.id; + var e = document.getElementById("textbox" + id); + e.setAttribute("style","position:absolute; visibility:hidden;"); + console.log("[JS] Bluring element", e); + e.blur(); + }, + get_text: function(tbl) { + var id = tbl.id; + var e = document.getElementById("textbox" + id); + console.log("Getting text",e.text); + return e.value; + } +}; |
