WebGLInput.jslib 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. var WebGLInput = {
  2. $instances: [],
  3. WebGLInputCreate: function (canvasId, x, y, width, height, fontsize, text, isMultiLine, isPassword) {
  4. var container = document.getElementById(Pointer_stringify(canvasId));
  5. var input = document.createElement(isMultiLine?"textarea":"input");
  6. input.style.position = "absolute";
  7. input.style.top = y + "px";
  8. input.style.left = x + "px";
  9. input.style.width = width + "px";
  10. input.style.height = height + "px";
  11. input.style.backgroundColor = '#00000000';
  12. input.style.color = '#00000000';
  13. input.style.outline = "none";
  14. input.style.border = "hidden";
  15. input.style.opacity = 0;
  16. input.style.cursor = "default";
  17. input.spellcheck = false;
  18. input.value = Pointer_stringify(text);
  19. input.style.fontSize = fontsize + "px";
  20. //input.setSelectionRange(0, input.value.length);
  21. if(isPassword){
  22. input.type = 'password';
  23. }
  24. container.appendChild(input);
  25. return instances.push(input) - 1;
  26. },
  27. WebGLInputEnterSubmit: function(id, falg){
  28. var input = instances[id];
  29. // for enter key
  30. input.addEventListener('keydown', function(e) {
  31. if ((e.which && e.which === 13) || (e.keyCode && e.keyCode === 13)) {
  32. if(falg)
  33. {
  34. e.preventDefault();
  35. input.blur();
  36. }
  37. }
  38. });
  39. },
  40. WebGLInputTab:function(id, cb) {
  41. var input = instances[id];
  42. // for tab key
  43. input.addEventListener('keydown', function (e) {
  44. if ((e.which && e.which === 9) || (e.keyCode && e.keyCode === 9)) {
  45. e.preventDefault();
  46. Runtime.dynCall("vii", cb, [id, e.shiftKey ? -1 : 1]);
  47. }
  48. });
  49. },
  50. WebGLInputFocus: function(id){
  51. var input = instances[id];
  52. input.focus();
  53. },
  54. WebGLInputOnFocus: function (id, cb) {
  55. var input = instances[id];
  56. input.onfocus = function () {
  57. Runtime.dynCall("vi", cb, [id]);
  58. };
  59. },
  60. WebGLInputOnBlur: function (id, cb) {
  61. var input = instances[id];
  62. input.onblur = function () {
  63. Runtime.dynCall("vi", cb, [id]);
  64. };
  65. },
  66. WebGLInputIsFocus: function (id) {
  67. return instances[id] === document.activeElement;
  68. },
  69. WebGLInputOnValueChange:function(id, cb){
  70. var input = instances[id];
  71. input.oninput = function () {
  72. var value = allocate(intArrayFromString(input.value), 'i8', ALLOC_NORMAL);
  73. Runtime.dynCall("vii", cb, [id,value]);
  74. };
  75. },
  76. WebGLInputOnEditEnd:function(id, cb){
  77. var input = instances[id];
  78. input.onchange = function () {
  79. var value = allocate(intArrayFromString(input.value), 'i8', ALLOC_NORMAL);
  80. Runtime.dynCall("vii", cb, [id,value]);
  81. };
  82. },
  83. WebGLInputSelectionStart:function(id){
  84. var input = instances[id];
  85. return input.selectionStart;
  86. },
  87. WebGLInputSelectionEnd:function(id){
  88. var input = instances[id];
  89. return input.selectionEnd;
  90. },
  91. WebGLInputSelectionDirection:function(id){
  92. var input = instances[id];
  93. return (input.selectionDirection == "backward")?-1:1;
  94. },
  95. WebGLInputSetSelectionRange:function(id, start, end){
  96. var input = instances[id];
  97. input.setSelectionRange(start, end);
  98. },
  99. WebGLInputMaxLength:function(id, maxlength){
  100. var input = instances[id];
  101. input.maxLength = maxlength;
  102. },
  103. WebGLInputText:function(id, text){
  104. var input = instances[id];
  105. input.value = Pointer_stringify(text);
  106. },
  107. WebGLInputDelete:function(id){
  108. var input = instances[id];
  109. input.parentNode.removeChild(input);
  110. instances[id] = null;
  111. },
  112. }
  113. autoAddDeps(WebGLInput, '$instances');
  114. mergeInto(LibraryManager.library, WebGLInput);