1
1
var WebGLInput = {
2
2
$instances : [ ] ,
3
- WebGLInputInit : function ( ) {
3
+ WebGLInputInit : function ( ) {
4
4
// use WebAssembly.Table : makeDynCall
5
5
// when enable. dynCall is undefined
6
6
if ( typeof dynCall === "undefined" )
7
7
{
8
- // make Runtime.dynCall to undefined
8
+ // make Runtime.dynCall to undefined
9
9
Runtime = { dynCall : undefined }
10
10
}
11
11
else
12
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 }
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
16
}
17
- } ,
17
+ } ,
18
18
WebGLInputCreate : function ( canvasId , x , y , width , height , fontsize , text , placeholder , isMultiLine , isPassword , isHidden , isMobile ) {
19
19
20
20
var container = document . getElementById ( UTF8ToString ( canvasId ) ) ;
@@ -27,99 +27,99 @@ var WebGLInput = {
27
27
container = canvas . parentNode ;
28
28
}
29
29
30
- if ( canvas )
31
- {
32
- var scaleX = container . offsetWidth / canvas . width ;
33
- var scaleY = container . offsetHeight / canvas . height ;
30
+ if ( canvas )
31
+ {
32
+ var scaleX = container . offsetWidth / canvas . width ;
33
+ var scaleY = container . offsetHeight / canvas . height ;
34
34
35
- if ( scaleX && scaleY )
36
- {
37
- x *= scaleX ;
38
- width *= scaleX ;
39
- y *= scaleY ;
40
- height *= scaleY ;
41
- }
42
- }
35
+ if ( scaleX && scaleY )
36
+ {
37
+ x *= scaleX ;
38
+ width *= scaleX ;
39
+ y *= scaleY ;
40
+ height *= scaleY ;
41
+ }
42
+ }
43
43
44
44
var input = document . createElement ( isMultiLine ?"textarea" :"input" ) ;
45
45
input . style . position = "absolute" ;
46
46
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
- }
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
+ }
62
62
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' ;
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' ;
69
69
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
- }
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
+ }
78
78
79
- if ( isMobile ) {
80
- document . body . appendChild ( input ) ;
81
- } else {
82
- container . appendChild ( input ) ;
83
- }
79
+ if ( isMobile ) {
80
+ document . body . appendChild ( input ) ;
81
+ } else {
82
+ container . appendChild ( input ) ;
83
+ }
84
84
return instances . push ( input ) - 1 ;
85
85
} ,
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
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
102
102
input . addEventListener ( 'keydown' , function ( e ) {
103
103
if ( ( e . which && e . which === 9 ) || ( e . keyCode && e . keyCode === 9 ) ) {
104
104
e . preventDefault ( ) ;
105
105
106
- // if enable tab text
107
- if ( input . enableTabText ) {
106
+ // if enable tab text
107
+ if ( input . enableTabText ) {
108
108
var val = input . value ;
109
109
var start = input . selectionStart ;
110
110
var end = input . selectionEnd ;
111
111
input . value = val . substr ( 0 , start ) + '\t' + val . substr ( end , val . length ) ;
112
112
input . setSelectionRange ( start + 1 , start + 1 ) ;
113
113
input . oninput ( ) ; // call oninput to exe ValueChange function!!
114
- } else {
115
- ( ! ! Runtime . dynCall ) ? Runtime . dynCall ( "vii" , cb , [ id , e . shiftKey ? - 1 : 1 ] ) : { { { makeDynCall ( "vii" , "cb" ) } } } ( id , e . shiftKey ? - 1 : 1 ) ;
116
- }
114
+ } else {
115
+ ( ! ! Runtime . dynCall ) ? Runtime . dynCall ( "vii" , cb , [ id , e . shiftKey ? - 1 : 1 ] ) : { { { makeDynCall ( "vii" , "cb" ) } } } ( id , e . shiftKey ? - 1 : 1 ) ;
116
+ }
117
117
}
118
- } ) ;
119
- } ,
120
- WebGLInputFocus: function ( id ) {
121
- var input = instances [ id ] ;
122
- input . focus ( ) ;
118
+ } ) ;
119
+ } ,
120
+ WebGLInputFocus: function ( id ) {
121
+ var input = instances [ id ] ;
122
+ input . focus ( ) ;
123
123
} ,
124
124
WebGLInputOnFocus : function ( id , cb ) {
125
125
var input = instances [ id ] ;
@@ -133,66 +133,66 @@ var WebGLInput = {
133
133
( ! ! Runtime . dynCall ) ? Runtime . dynCall ( "vi" , cb , [ id ] ) : { { { makeDynCall ( "vi" , "cb" ) } } } ( id ) ;
134
134
} ;
135
135
} ,
136
- WebGLInputIsFocus: function ( id ) {
137
- return instances [ id ] === document . activeElement ;
138
- } ,
139
- WebGLInputOnValueChange :function ( id , cb ) {
136
+ WebGLInputIsFocus: function ( id ) {
137
+ return instances [ id ] === document . activeElement ;
138
+ } ,
139
+ WebGLInputOnValueChange :function ( id , cb ) {
140
140
var input = instances [ id ] ;
141
141
input . oninput = 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 ) ? Runtime . dynCall ( "vii" , cb , [ id , buffer ] ) : { { { makeDynCall ( "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 ) ;
147
147
} ;
148
148
} ,
149
- WebGLInputOnEditEnd:function ( id , cb ) {
149
+ WebGLInputOnEditEnd:function ( id , cb ) {
150
150
var input = instances [ id ] ;
151
151
input . onchange = function ( ) {
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 ) ;
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 ) ;
157
157
} ;
158
158
} ,
159
- WebGLInputSelectionStart:function ( id ) {
159
+ WebGLInputSelectionStart:function ( id ) {
160
160
var input = instances [ id ] ;
161
- return input . selectionStart ;
162
- } ,
163
- WebGLInputSelectionEnd :function ( id ) {
161
+ return input . selectionStart ;
162
+ } ,
163
+ WebGLInputSelectionEnd :function ( id ) {
164
164
var input = instances [ id ] ;
165
- return input . selectionEnd ;
166
- } ,
167
- WebGLInputSelectionDirection :function ( id ) {
165
+ return input . selectionEnd ;
166
+ } ,
167
+ WebGLInputSelectionDirection :function ( id ) {
168
168
var input = instances [ id ] ;
169
- return ( input . selectionDirection == "backward" ) ?- 1 :1 ;
170
- } ,
171
- WebGLInputSetSelectionRange :function ( id , start , end ) {
172
- var input = instances [ id ] ;
173
- input . setSelectionRange ( start , end ) ;
174
- } ,
175
- WebGLInputMaxLength :function ( id , maxlength ) {
169
+ return ( input . selectionDirection == "backward" ) ?- 1 :1 ;
170
+ } ,
171
+ WebGLInputSetSelectionRange :function ( id , start , end ) {
176
172
var input = instances [ id ] ;
177
- input . maxLength = maxlength ;
178
- } ,
179
- WebGLInputText :function ( id , text ) {
173
+ input . setSelectionRange ( start , end ) ;
174
+ } ,
175
+ WebGLInputMaxLength :function ( id , maxlength ) {
180
176
var input = instances [ id ] ;
181
- input . value = UTF8ToString ( text ) ;
182
- } ,
183
- WebGLInputDelete :function ( id ) {
177
+ input . maxLength = maxlength ;
178
+ } ,
179
+ WebGLInputText :function ( id , text ) {
180
+ var input = instances [ id ] ;
181
+ input . value = UTF8ToString ( text ) ;
182
+ } ,
183
+ WebGLInputDelete :function ( id ) {
184
184
var input = instances [ id ] ;
185
185
input . parentNode . removeChild ( input ) ;
186
186
instances [ id ] = null ;
187
187
} ,
188
- WebGLInputEnableTabText :function ( id , enable ) {
188
+ WebGLInputEnableTabText :function ( id , enable ) {
189
189
var input = instances [ id ] ;
190
- input . enableTabText = enable ;
191
- } ,
192
- WebGLInputForceBlur :function ( id ) {
190
+ input . enableTabText = enable ;
191
+ } ,
192
+ WebGLInputForceBlur :function ( id ) {
193
193
var input = instances [ id ] ;
194
- input . blur ( ) ;
195
- } ,
194
+ input . blur ( ) ;
195
+ } ,
196
196
}
197
197
198
198
autoAddDeps ( WebGLInput , '$instances' ) ;
0 commit comments