@@ -154,14 +154,14 @@ cc.EditBoxDelegate = cc.Class.extend({
154
154
* This method is called when an edit box gains focus after keyboard is shown.
155
155
* @param {cc.EditBox } sender
156
156
*/
157
- editBoxEditingDidBegan : function ( sender ) {
157
+ editBoxEditingDidBegin : function ( sender ) {
158
158
} ,
159
159
160
160
/**
161
161
* This method is called when an edit box loses focus after keyboard is hidden.
162
162
* @param {cc.EditBox } sender
163
163
*/
164
- editBoxEditingDidEnded : function ( sender ) {
164
+ editBoxEditingDidEnd : function ( sender ) {
165
165
} ,
166
166
167
167
/**
@@ -176,7 +176,7 @@ cc.EditBoxDelegate = cc.Class.extend({
176
176
* This method is called when the return button was pressed.
177
177
* @param {cc.EditBox } sender
178
178
*/
179
- editBoxEditingReturn : function ( sender ) {
179
+ editBoxReturn : function ( sender ) {
180
180
}
181
181
} ) ;
182
182
@@ -219,6 +219,8 @@ cc.EditBox = cc.Node.extend({
219
219
_placeholderFontSize : 14 ,
220
220
_placeholderColor : null ,
221
221
_className : 'EditBox' ,
222
+ _touchListener : null ,
223
+ _touchEnabled : true ,
222
224
223
225
/**
224
226
* constructor of cc.EditBox
@@ -240,16 +242,29 @@ cc.EditBox = cc.Node.extend({
240
242
241
243
this . initWithSizeAndBackgroundSprite ( size , normal9SpriteBg ) ;
242
244
243
- cc . eventManager . addListener ( {
245
+ this . _touchListener = cc . EventListener . create ( {
244
246
event : cc . EventListener . TOUCH_ONE_BY_ONE ,
245
247
swallowTouches : true ,
246
248
onTouchBegan : this . _onTouchBegan . bind ( this ) ,
247
249
onTouchEnded : this . _onTouchEnded . bind ( this )
248
- } , this ) ;
250
+ } ) ;
251
+ cc . eventManager . addListener ( this . _touchListener , this ) ;
249
252
250
253
this . setInputFlag ( this . _editBoxInputFlag ) ;
251
254
} ,
252
255
256
+ setTouchEnabled : function ( enable ) {
257
+ if ( this . _touchEnabled === enable ) {
258
+ return ;
259
+ }
260
+ this . _touchEnabled = enable ;
261
+ if ( this . _touchEnabled ) {
262
+ cc . eventManager . addListener ( this . _touchListener , this ) ;
263
+ } else {
264
+ cc . eventManager . removeListener ( this . _touchListener ) ;
265
+ }
266
+ } ,
267
+
253
268
_createRenderCmd : function ( ) {
254
269
if ( cc . _renderType === cc . game . RENDER_TYPE_CANVAS ) {
255
270
return new cc . EditBox . CanvasRenderCmd ( this ) ;
@@ -319,7 +334,21 @@ cc.EditBox = cc.Node.extend({
319
334
this . _renderCmd . _removeDomInputControl ( ) ;
320
335
} ,
321
336
337
+ _isAncestorsVisible : function ( node ) {
338
+ if ( null == node )
339
+ return true ;
340
+
341
+ var parent = node . getParent ( ) ;
342
+
343
+ if ( parent && ! parent . isVisible ( ) )
344
+ return false ;
345
+ return this . _isAncestorsVisible ( parent ) ;
346
+ } ,
347
+
322
348
_onTouchBegan : function ( touch ) {
349
+ if ( ! this . isVisible ( ) || ! this . _isAncestorsVisible ( this ) ) {
350
+ return ;
351
+ }
323
352
var touchPoint = touch . getLocation ( ) ;
324
353
var bb = cc . rect ( 0 , 0 , this . _contentSize . width , this . _contentSize . height ) ;
325
354
var hitted = cc . rectContainsPoint ( bb , this . convertToNodeSpace ( touchPoint ) ) ;
@@ -333,6 +362,9 @@ cc.EditBox = cc.Node.extend({
333
362
} ,
334
363
335
364
_onTouchEnded : function ( ) {
365
+ if ( ! this . isVisible ( ) || ! this . _isAncestorsVisible ( this ) ) {
366
+ return ;
367
+ }
336
368
this . _renderCmd . show ( ) ;
337
369
} ,
338
370
@@ -822,8 +854,8 @@ cc.EditBox.create = function (size, normal9SpriteBg, press9SpriteBg, disabled9Sp
822
854
editBox . _text = this . value ;
823
855
thisPointer . _updateEditBoxContentStyle ( ) ;
824
856
thisPointer . hidden ( ) ;
825
- if ( editBox . _delegate && editBox . _delegate . editBoxEditingReturn ) {
826
- editBox . _delegate . editBoxEditingReturn ( editBox ) ;
857
+ if ( editBox . _delegate && editBox . _delegate . editBoxReturn ) {
858
+ editBox . _delegate . editBoxReturn ( editBox ) ;
827
859
}
828
860
cc . _canvas . focus ( ) ;
829
861
}
@@ -845,10 +877,12 @@ cc.EditBox.create = function (size, normal9SpriteBg, press9SpriteBg, disabled9Sp
845
877
this . __autoResize = cc . view . __resizeWithBrowserSize ;
846
878
cc . view . resizeWithBrowserSize ( false ) ;
847
879
848
- scrollWindowUp ( editBox ) ;
880
+ if ( cc . sys . isMobile ) {
881
+ scrollWindowUp ( editBox ) ;
882
+ }
849
883
850
- if ( editBox . _delegate && editBox . _delegate . editBoxEditingDidBegan ) {
851
- editBox . _delegate . editBoxEditingDidBegan ( editBox ) ;
884
+ if ( editBox . _delegate && editBox . _delegate . editBoxEditingDidBegin ) {
885
+ editBox . _delegate . editBoxEditingDidBegin ( editBox ) ;
852
886
}
853
887
} ) ;
854
888
tmpEdTxt . addEventListener ( 'blur' , function ( ) {
@@ -862,8 +896,8 @@ cc.EditBox.create = function (size, normal9SpriteBg, press9SpriteBg, disabled9Sp
862
896
cc . view . resizeWithBrowserSize ( true ) ;
863
897
}
864
898
window . scrollY = 0 ;
865
- if ( editBox . _delegate && editBox . _delegate . editBoxEditingDidEnded ) {
866
- editBox . _delegate . editBoxEditingDidEnded ( editBox ) ;
899
+ if ( editBox . _delegate && editBox . _delegate . editBoxEditingDidEnd ) {
900
+ editBox . _delegate . editBoxEditingDidEnd ( editBox ) ;
867
901
}
868
902
869
903
if ( this . value === '' ) {
@@ -930,10 +964,12 @@ cc.EditBox.create = function (size, normal9SpriteBg, press9SpriteBg, disabled9Sp
930
964
this . __autoResize = cc . view . __resizeWithBrowserSize ;
931
965
cc . view . resizeWithBrowserSize ( false ) ;
932
966
933
- scrollWindowUp ( editBox ) ;
967
+ if ( cc . sys . isMobile ) {
968
+ scrollWindowUp ( editBox ) ;
969
+ }
934
970
935
- if ( editBox . _delegate && editBox . _delegate . editBoxEditingDidBegan ) {
936
- editBox . _delegate . editBoxEditingDidBegan ( editBox ) ;
971
+ if ( editBox . _delegate && editBox . _delegate . editBoxEditingDidBegin ) {
972
+ editBox . _delegate . editBoxEditingDidBegin ( editBox ) ;
937
973
}
938
974
939
975
} ) ;
@@ -943,8 +979,8 @@ cc.EditBox.create = function (size, normal9SpriteBg, press9SpriteBg, disabled9Sp
943
979
if ( e . keyCode === cc . KEY . enter ) {
944
980
e . stopPropagation ( ) ;
945
981
946
- if ( editBox . _delegate && editBox . _delegate . editBoxEditingReturn ) {
947
- editBox . _delegate . editBoxEditingReturn ( editBox ) ;
982
+ if ( editBox . _delegate && editBox . _delegate . editBoxReturn ) {
983
+ editBox . _delegate . editBoxReturn ( editBox ) ;
948
984
}
949
985
}
950
986
} ) ;
@@ -960,8 +996,8 @@ cc.EditBox.create = function (size, normal9SpriteBg, press9SpriteBg, disabled9Sp
960
996
cc . view . resizeWithBrowserSize ( true ) ;
961
997
}
962
998
963
- if ( editBox . _delegate && editBox . _delegate . editBoxEditingDidEnded ) {
964
- editBox . _delegate . editBoxEditingDidEnded ( editBox ) ;
999
+ if ( editBox . _delegate && editBox . _delegate . editBoxEditingDidEnd ) {
1000
+ editBox . _delegate . editBoxEditingDidEnd ( editBox ) ;
965
1001
}
966
1002
967
1003
if ( this . value === '' ) {
0 commit comments