aboutsummaryrefslogtreecommitdiff
path: root/src/textbox_bridge.js
blob: c52902e64d1fd77a96d1c9e82e116d83ee324a26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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;
	}
};