| 1 | var TextInput = |
| 2 | { |
| 3 | el: null, |
| 4 | g_onChangeCallback: function(){}, |
| 5 | g_text: "", |
| 6 | |
| 7 | g_init: function() |
| 8 | { |
| 9 | var body = document.body; |
| 10 | body.insertAdjacentHTML('beforeend', '<input type="text" id="g_gameTextInput" style=""></input>'); |
| 11 | }, |
| 12 | |
| 13 | open: function(defaultText, callback, context) |
| 14 | { |
| 15 | this.el = document.getElementById("g_gameTextInput"); |
| 16 | this.el.value = defaultText; |
| 17 | this.el.focus(); |
| 18 | |
| 19 | var thisContext = this; |
| 20 | |
| 21 | this.g_onChangeCallback = function() |
| 22 | { |
| 23 | context = context || thisContext.el; |
| 24 | callback && callback.call(context, thisContext.g_text); |
| 25 | } |
| 26 | }, |
| 27 | |
| 28 | close: function() |
| 29 | { |
| 30 | this.g_onChangeCallback = function(){}; |
| 31 | }, |
| 32 | |
| 33 | g_update: function() |
| 34 | { |
| 35 | if(this.el != null) |
| 36 | { |
| 37 | if(this.g_text !== this.el.value) |
| 38 | { |
| 39 | this.g_text = this.el.value; |
| 40 | this.g_onChangeCallback(); |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | } |