@@ -66,6 +66,7 @@ var keyboardIsOpen;
66
66
var keyboardActiveElement ;
67
67
var keyboardFocusOutTimer ;
68
68
var keyboardFocusInTimer ;
69
+ var keyboardPollHeightTimer ;
69
70
var keyboardLastShow = 0 ;
70
71
71
72
var KEYBOARD_OPEN_CSS = 'keyboard-open' ;
@@ -75,6 +76,41 @@ ionic.keyboard = {
75
76
isOpen : false ,
76
77
height : null ,
77
78
landscape : false ,
79
+
80
+ hide : function ( ) {
81
+ clearTimeout ( keyboardFocusInTimer ) ;
82
+ clearTimeout ( keyboardFocusOutTimer ) ;
83
+ clearTimeout ( keyboardPollHeightTimer ) ;
84
+
85
+ console . log ( 'keyboardHide' ) ;
86
+ ionic . keyboard . isOpen = false ;
87
+
88
+ ionic . trigger ( 'resetScrollView' , {
89
+ target : keyboardActiveElement
90
+ } , true ) ;
91
+
92
+ ionic . requestAnimationFrame ( function ( ) {
93
+ document . body . classList . remove ( KEYBOARD_OPEN_CSS ) ;
94
+ } ) ;
95
+
96
+ // the keyboard is gone now, remove the touchmove that disables native scroll
97
+ if ( window . navigator . msPointerEnabled ) {
98
+ document . removeEventListener ( "MSPointerMove" , keyboardPreventDefault ) ;
99
+ } else {
100
+ document . removeEventListener ( 'touchmove' , keyboardPreventDefault ) ;
101
+ }
102
+ document . removeEventListener ( 'keydown' , keyboardOnKeyDown ) ;
103
+
104
+ if ( keyboardHasPlugin ( ) ) {
105
+ cordova . plugins . Keyboard . close ( ) ;
106
+ }
107
+ } ,
108
+
109
+ show : function ( ) {
110
+ if ( keyboardHasPlugin ( ) ) {
111
+ cordova . plugins . Keyboard . show ( ) ;
112
+ }
113
+ }
78
114
} ;
79
115
80
116
function keyboardInit ( ) {
@@ -126,22 +162,23 @@ function keyboardSetShow(e) {
126
162
127
163
keyboardFocusInTimer = setTimeout ( function ( ) {
128
164
if ( keyboardLastShow + 350 > Date . now ( ) ) return ;
165
+ console . log ( 'keyboardSetShow' ) ;
129
166
keyboardLastShow = Date . now ( ) ;
130
167
var keyboardHeight ;
131
168
var elementBounds = keyboardActiveElement . getBoundingClientRect ( ) ;
132
169
var count = 0 ;
133
170
134
- var pollKeyboardHeight = setInterval ( function ( ) {
171
+ keyboardPollHeightTimer = setInterval ( function ( ) {
135
172
136
173
keyboardHeight = keyboardGetHeight ( ) ;
137
174
if ( count > 10 ) {
138
- clearInterval ( pollKeyboardHeight ) ;
175
+ clearInterval ( keyboardPollHeightTimer ) ;
139
176
//waited long enough, just guess
140
177
keyboardHeight = 275 ;
141
178
}
142
179
if ( keyboardHeight ) {
180
+ clearInterval ( keyboardPollHeightTimer ) ;
143
181
keyboardShow ( e . target , elementBounds . top , elementBounds . bottom , keyboardViewportHeight , keyboardHeight ) ;
144
- clearInterval ( pollKeyboardHeight ) ;
145
182
}
146
183
count ++ ;
147
184
@@ -192,28 +229,7 @@ function keyboardShow(element, elementTop, elementBottom, viewportHeight, keyboa
192
229
function keyboardFocusOut ( e ) {
193
230
clearTimeout ( keyboardFocusOutTimer ) ;
194
231
195
- keyboardFocusOutTimer = setTimeout ( keyboardHide , 350 ) ;
196
- }
197
-
198
- function keyboardHide ( ) {
199
- console . log ( 'keyboardHide' ) ;
200
- ionic . keyboard . isOpen = false ;
201
-
202
- ionic . trigger ( 'resetScrollView' , {
203
- target : keyboardActiveElement
204
- } , true ) ;
205
-
206
- ionic . requestAnimationFrame ( function ( ) {
207
- document . body . classList . remove ( KEYBOARD_OPEN_CSS ) ;
208
- } ) ;
209
-
210
- // the keyboard is gone now, remove the touchmove that disables native scroll
211
- if ( window . navigator . msPointerEnabled ) {
212
- document . removeEventListener ( "MSPointerMove" , keyboardPreventDefault ) ;
213
- } else {
214
- document . removeEventListener ( 'touchmove' , keyboardPreventDefault ) ;
215
- }
216
- document . removeEventListener ( 'keydown' , keyboardOnKeyDown ) ;
232
+ keyboardFocusOutTimer = setTimeout ( ionic . keyboard . hide , 350 ) ;
217
233
}
218
234
219
235
function keyboardUpdateViewportHeight ( ) {
0 commit comments