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; } };