var TextInput = { el: null, g_onChangeCallback: function(){}, g_text: "", g_init: function() { var body = document.body; body.insertAdjacentHTML('beforeend', ''); }, open: function(defaultText, callback, context) { this.el = document.getElementById("g_gameTextInput"); this.el.value = defaultText; this.el.focus(); var thisContext = this; this.g_onChangeCallback = function() { context = context || thisContext.el; callback && callback.call(context, thisContext.g_text); } }, close: function() { this.g_onChangeCallback = function(){}; }, g_update: function() { if(this.el != null) { if(this.g_text !== this.el.value) { this.g_text = this.el.value; this.g_onChangeCallback(); } } } }