11var WebGLInput = {
22 $instances : [ ] ,
3- WebGLInputInit : function ( ) {
4- // Remove the `Runtime` object from "v1.37.27: 12/24/2017"
5- // if Runtime not defined. create and add functon!!
6- if ( typeof Runtime === "undefined" ) Runtime = { dynCall : dynCall }
7- } ,
3+ WebGLInputInit : function ( ) {
4+ // use WebAssembly.Table : makeDynCall
5+ // when enable. dynCall is undefined
6+ if ( typeof dynCall === "undefined" )
7+ {
8+ // make Runtime.dynCall to undefined
9+ Runtime = { dynCall : undefined }
10+ }
11+ else
12+ {
13+ // Remove the `Runtime` object from "v1.37.27: 12/24/2017"
14+ // if Runtime not defined. create and add functon!!
15+ if ( typeof Runtime === "undefined" ) Runtime = { dynCall : dynCall }
16+ }
17+ } ,
818 WebGLInputCreate : function ( canvasId , x , y , width , height , fontsize , text , placeholder , isMultiLine , isPassword , isHidden , isMobile ) {
919
1020 var container = document . getElementById ( UTF8ToString ( canvasId ) ) ;
@@ -17,172 +27,172 @@ var WebGLInput = {
1727 container = canvas . parentNode ;
1828 }
1929
20- if ( canvas )
21- {
22- var scaleX = container . offsetWidth / canvas . width ;
23- var scaleY = container . offsetHeight / canvas . height ;
30+ if ( canvas )
31+ {
32+ var scaleX = container . offsetWidth / canvas . width ;
33+ var scaleY = container . offsetHeight / canvas . height ;
2434
25- if ( scaleX && scaleY )
26- {
27- x *= scaleX ;
28- width *= scaleX ;
29- y *= scaleY ;
30- height *= scaleY ;
31- }
32- }
35+ if ( scaleX && scaleY )
36+ {
37+ x *= scaleX ;
38+ width *= scaleX ;
39+ y *= scaleY ;
40+ height *= scaleY ;
41+ }
42+ }
3343
3444 var input = document . createElement ( isMultiLine ?"textarea" :"input" ) ;
3545 input . style . position = "absolute" ;
3646
37- if ( isMobile ) {
38- input . style . bottom = 1 + "vh" ;
39- input . style . left = 5 + "vw" ;
40- input . style . width = 90 + "vw" ;
41- input . style . height = ( isMultiLine ? 18 : 10 ) + "vh" ;
42- input . style . fontSize = 5 + "vh" ;
43- input . style . borderWidth = 5 + "px" ;
44- input . style . borderColor = "#000000" ;
45- } else {
46- input . style . top = y + "px" ;
47- input . style . left = x + "px" ;
48- input . style . width = width + "px" ;
49- input . style . height = height + "px" ;
50- input . style . fontSize = fontsize + "px" ;
51- }
47+ if ( isMobile ) {
48+ input . style . bottom = 1 + "vh" ;
49+ input . style . left = 5 + "vw" ;
50+ input . style . width = 90 + "vw" ;
51+ input . style . height = ( isMultiLine ? 18 : 10 ) + "vh" ;
52+ input . style . fontSize = 5 + "vh" ;
53+ input . style . borderWidth = 5 + "px" ;
54+ input . style . borderColor = "#000000" ;
55+ } else {
56+ input . style . top = y + "px" ;
57+ input . style . left = x + "px" ;
58+ input . style . width = width + "px" ;
59+ input . style . height = height + "px" ;
60+ input . style . fontSize = fontsize + "px" ;
61+ }
5262
53- input . style . outlineWidth = 1 + 'px' ;
54- input . style . opacity = isHidden ?0 :1 ;
55- input . style . resize = 'none' ; // for textarea
56- input . style . padding = '0px 1px' ;
57- input . style . cursor = "default" ;
58- input . style . touchAction = 'none' ;
63+ input . style . outlineWidth = 1 + 'px' ;
64+ input . style . opacity = isHidden ?0 :1 ;
65+ input . style . resize = 'none' ; // for textarea
66+ input . style . padding = '0px 1px' ;
67+ input . style . cursor = "default" ;
68+ input . style . touchAction = 'none' ;
5969
60- input . spellcheck = false ;
61- input . value = UTF8ToString ( text ) ;
62- input . placeholder = UTF8ToString ( placeholder ) ;
63- input . style . outlineColor = 'black' ;
64-
65- if ( isPassword ) {
66- input . type = 'password' ;
67- }
70+ input . spellcheck = false ;
71+ input . value = UTF8ToString ( text ) ;
72+ input . placeholder = UTF8ToString ( placeholder ) ;
73+ input . style . outlineColor = 'black' ;
74+
75+ if ( isPassword ) {
76+ input . type = 'password' ;
77+ }
6878
69- if ( isMobile ) {
70- document . body . appendChild ( input ) ;
71- } else {
72- container . appendChild ( input ) ;
73- }
79+ if ( isMobile ) {
80+ document . body . appendChild ( input ) ;
81+ } else {
82+ container . appendChild ( input ) ;
83+ }
7484 return instances . push ( input ) - 1 ;
7585 } ,
76- WebGLInputEnterSubmit : function ( id , falg ) {
77- var input = instances [ id ] ;
78- // for enter key
79- input . addEventListener ( 'keydown' , function ( e ) {
80- if ( ( e . which && e . which === 13 ) || ( e . keyCode && e . keyCode === 13 ) ) {
81- if ( falg )
82- {
83- e . preventDefault ( ) ;
84- input . blur ( ) ;
85- }
86- }
87- } ) ;
88- } ,
89- WebGLInputTab :function ( id , cb ) {
90- var input = instances [ id ] ;
91- // for tab key
86+ WebGLInputEnterSubmit : function ( id , falg ) {
87+ var input = instances [ id ] ;
88+ // for enter key
89+ input . addEventListener ( 'keydown' , function ( e ) {
90+ if ( ( e . which && e . which === 13 ) || ( e . keyCode && e . keyCode === 13 ) ) {
91+ if ( falg )
92+ {
93+ e . preventDefault ( ) ;
94+ input . blur ( ) ;
95+ }
96+ }
97+ } ) ;
98+ } ,
99+ WebGLInputTab :function ( id , cb ) {
100+ var input = instances [ id ] ;
101+ // for tab key
92102 input . addEventListener ( 'keydown' , function ( e ) {
93103 if ( ( e . which && e . which === 9 ) || ( e . keyCode && e . keyCode === 9 ) ) {
94104 e . preventDefault ( ) ;
95105
96- // if enable tab text
97- if ( input . enableTabText ) {
106+ // if enable tab text
107+ if ( input . enableTabText ) {
98108 var val = input . value ;
99109 var start = input . selectionStart ;
100110 var end = input . selectionEnd ;
101111 input . value = val . substr ( 0 , start ) + '\t' + val . substr ( end , val . length ) ;
102112 input . setSelectionRange ( start + 1 , start + 1 ) ;
103113 input . oninput ( ) ; // call oninput to exe ValueChange function!!
104- } else {
105- Runtime . dynCall ( "vii" , cb , [ id , e . shiftKey ? - 1 : 1 ] ) ;
106- }
114+ } else {
115+ ( ! ! Runtime . dynCall ) ? Runtime . dynCall ( "vii" , cb , [ id , e . shiftKey ? - 1 : 1 ] ) : { { { makeDynCall ( "vii" , "cb" ) } } } ( id , e . shiftKey ? - 1 : 1 ) ;
116+ }
107117 }
108- } ) ;
109- } ,
110- WebGLInputFocus : function ( id ) {
111- var input = instances [ id ] ;
112- input . focus ( ) ;
118+ } ) ;
119+ } ,
120+ WebGLInputFocus: function ( id ) {
121+ var input = instances [ id ] ;
122+ input . focus ( ) ;
113123 } ,
114124 WebGLInputOnFocus : function ( id , cb ) {
115125 var input = instances [ id ] ;
116126 input . onfocus = function ( ) {
117- Runtime . dynCall ( "vi" , cb , [ id ] ) ;
127+ ( ! ! Runtime . dynCall ) ? Runtime . dynCall ( "vi" , cb , [ id ] ) : { { { makeDynCall ( "vi" , "cb" ) } } } ( id ) ;
118128 } ;
119129 } ,
120130 WebGLInputOnBlur: function ( id , cb ) {
121131 var input = instances [ id ] ;
122132 input . onblur = function ( ) {
123- Runtime . dynCall ( "vi" , cb , [ id ] ) ;
133+ ( ! ! Runtime . dynCall ) ? Runtime . dynCall ( "vi" , cb , [ id ] ) : { { { makeDynCall ( "vi" , "cb" ) } } } ( id ) ;
124134 } ;
125135 } ,
126- WebGLInputIsFocus : function ( id ) {
127- return instances [ id ] === document . activeElement ;
128- } ,
129- WebGLInputOnValueChange :function ( id , cb ) {
136+ WebGLInputIsFocus: function ( id ) {
137+ return instances [ id ] === document . activeElement ;
138+ } ,
139+ WebGLInputOnValueChange :function ( id , cb ) {
130140 var input = instances [ id ] ;
131141 input . oninput = function ( ) {
132- var returnStr = input . value ;
133- var bufferSize = lengthBytesUTF8 ( returnStr ) + 1 ;
134- var buffer = _malloc ( bufferSize ) ;
135- stringToUTF8 ( returnStr , buffer , bufferSize ) ;
136- Runtime . dynCall ( "vii" , cb , [ id , buffer ] ) ;
142+ var returnStr = input . value ;
143+ var bufferSize = lengthBytesUTF8 ( returnStr ) + 1 ;
144+ var buffer = _malloc ( bufferSize ) ;
145+ stringToUTF8 ( returnStr , buffer , bufferSize ) ;
146+ ( ! ! Runtime . dynCall ) ? Runtime . dynCall ( "vii" , cb , [ id , buffer ] ) : { { { makeDynCall ( "vii" , "cb" ) } } } ( id , buffer ) ;
137147 } ;
138148 } ,
139- WebGLInputOnEditEnd :function ( id , cb ) {
149+ WebGLInputOnEditEnd:function ( id , cb ) {
140150 var input = instances [ id ] ;
141151 input . onchange = function ( ) {
142- var returnStr = input . value ;
143- var bufferSize = lengthBytesUTF8 ( returnStr ) + 1 ;
144- var buffer = _malloc ( bufferSize ) ;
145- stringToUTF8 ( returnStr , buffer , bufferSize ) ;
146- Runtime . dynCall ( "vii" , cb , [ id , buffer ] ) ;
152+ var returnStr = input . value ;
153+ var bufferSize = lengthBytesUTF8 ( returnStr ) + 1 ;
154+ var buffer = _malloc ( bufferSize ) ;
155+ stringToUTF8 ( returnStr , buffer , bufferSize ) ;
156+ ( ! ! Runtime . dynCall ) ? Runtime . dynCall ( "vii" , cb , [ id , buffer ] ) : { { { makeDynCall ( "vii" , "cb" ) } } } ( id , buffer ) ;
147157 } ;
148158 } ,
149- WebGLInputSelectionStart :function ( id ) {
159+ WebGLInputSelectionStart:function ( id ) {
150160 var input = instances [ id ] ;
151- return input . selectionStart ;
152- } ,
153- WebGLInputSelectionEnd :function ( id ) {
161+ return input . selectionStart ;
162+ } ,
163+ WebGLInputSelectionEnd :function ( id ) {
154164 var input = instances [ id ] ;
155- return input . selectionEnd ;
156- } ,
157- WebGLInputSelectionDirection :function ( id ) {
165+ return input . selectionEnd ;
166+ } ,
167+ WebGLInputSelectionDirection :function ( id ) {
158168 var input = instances [ id ] ;
159- return ( input . selectionDirection == "backward" ) ?- 1 :1 ;
160- } ,
161- WebGLInputSetSelectionRange :function ( id , start , end ) {
162- var input = instances [ id ] ;
163- input . setSelectionRange ( start , end ) ;
164- } ,
165- WebGLInputMaxLength :function ( id , maxlength ) {
169+ return ( input . selectionDirection == "backward" ) ?- 1 :1 ;
170+ } ,
171+ WebGLInputSetSelectionRange :function ( id , start , end ) {
166172 var input = instances [ id ] ;
167- input . maxLength = maxlength ;
168- } ,
169- WebGLInputText :function ( id , text ) {
173+ input . setSelectionRange ( start , end ) ;
174+ } ,
175+ WebGLInputMaxLength :function ( id , maxlength ) {
176+ var input = instances [ id ] ;
177+ input . maxLength = maxlength ;
178+ } ,
179+ WebGLInputText :function ( id , text ) {
170180 var input = instances [ id ] ;
171- input . value = UTF8ToString ( text ) ;
172- } ,
173- WebGLInputDelete :function ( id ) {
181+ input . value = UTF8ToString ( text ) ;
182+ } ,
183+ WebGLInputDelete :function ( id ) {
174184 var input = instances [ id ] ;
175185 input . parentNode . removeChild ( input ) ;
176186 instances [ id ] = null ;
177187 } ,
178- WebGLInputEnableTabText :function ( id , enable ) {
188+ WebGLInputEnableTabText :function ( id , enable ) {
179189 var input = instances [ id ] ;
180- input . enableTabText = enable ;
181- } ,
182- WebGLInputForceBlur :function ( id ) {
190+ input . enableTabText = enable ;
191+ } ,
192+ WebGLInputForceBlur :function ( id ) {
183193 var input = instances [ id ] ;
184- input . blur ( ) ;
185- } ,
194+ input . blur ( ) ;
195+ } ,
186196}
187197
188198autoAddDeps ( WebGLInput , '$instances' ) ;
0 commit comments