@@ -154,14 +154,14 @@ cc.EditBoxDelegate = cc.Class.extend({
154154 * This method is called when an edit box gains focus after keyboard is shown.
155155 * @param {cc.EditBox } sender
156156 */
157- editBoxEditingDidBegan : function ( sender ) {
157+ editBoxEditingDidBegin : function ( sender ) {
158158 } ,
159159
160160 /**
161161 * This method is called when an edit box loses focus after keyboard is hidden.
162162 * @param {cc.EditBox } sender
163163 */
164- editBoxEditingDidEnded : function ( sender ) {
164+ editBoxEditingDidEnd : function ( sender ) {
165165 } ,
166166
167167 /**
@@ -176,7 +176,7 @@ cc.EditBoxDelegate = cc.Class.extend({
176176 * This method is called when the return button was pressed.
177177 * @param {cc.EditBox } sender
178178 */
179- editBoxEditingReturn : function ( sender ) {
179+ editBoxReturn : function ( sender ) {
180180 }
181181} ) ;
182182
@@ -219,6 +219,8 @@ cc.EditBox = cc.Node.extend({
219219 _placeholderFontSize : 14 ,
220220 _placeholderColor : null ,
221221 _className : 'EditBox' ,
222+ _touchListener : null ,
223+ _touchEnabled : true ,
222224
223225 /**
224226 * constructor of cc.EditBox
@@ -240,16 +242,29 @@ cc.EditBox = cc.Node.extend({
240242
241243 this . initWithSizeAndBackgroundSprite ( size , normal9SpriteBg ) ;
242244
243- cc . eventManager . addListener ( {
245+ this . _touchListener = cc . EventListener . create ( {
244246 event : cc . EventListener . TOUCH_ONE_BY_ONE ,
245247 swallowTouches : true ,
246248 onTouchBegan : this . _onTouchBegan . bind ( this ) ,
247249 onTouchEnded : this . _onTouchEnded . bind ( this )
248- } , this ) ;
250+ } ) ;
251+ cc . eventManager . addListener ( this . _touchListener , this ) ;
249252
250253 this . setInputFlag ( this . _editBoxInputFlag ) ;
251254 } ,
252255
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+
253268 _createRenderCmd : function ( ) {
254269 if ( cc . _renderType === cc . game . RENDER_TYPE_CANVAS ) {
255270 return new cc . EditBox . CanvasRenderCmd ( this ) ;
@@ -319,7 +334,21 @@ cc.EditBox = cc.Node.extend({
319334 this . _renderCmd . _removeDomInputControl ( ) ;
320335 } ,
321336
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+
322348 _onTouchBegan : function ( touch ) {
349+ if ( ! this . isVisible ( ) || ! this . _isAncestorsVisible ( this ) ) {
350+ return ;
351+ }
323352 var touchPoint = touch . getLocation ( ) ;
324353 var bb = cc . rect ( 0 , 0 , this . _contentSize . width , this . _contentSize . height ) ;
325354 var hitted = cc . rectContainsPoint ( bb , this . convertToNodeSpace ( touchPoint ) ) ;
@@ -333,6 +362,9 @@ cc.EditBox = cc.Node.extend({
333362 } ,
334363
335364 _onTouchEnded : function ( ) {
365+ if ( ! this . isVisible ( ) || ! this . _isAncestorsVisible ( this ) ) {
366+ return ;
367+ }
336368 this . _renderCmd . show ( ) ;
337369 } ,
338370
@@ -822,8 +854,8 @@ cc.EditBox.create = function (size, normal9SpriteBg, press9SpriteBg, disabled9Sp
822854 editBox . _text = this . value ;
823855 thisPointer . _updateEditBoxContentStyle ( ) ;
824856 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 ) ;
827859 }
828860 cc . _canvas . focus ( ) ;
829861 }
@@ -845,10 +877,12 @@ cc.EditBox.create = function (size, normal9SpriteBg, press9SpriteBg, disabled9Sp
845877 this . __autoResize = cc . view . __resizeWithBrowserSize ;
846878 cc . view . resizeWithBrowserSize ( false ) ;
847879
848- scrollWindowUp ( editBox ) ;
880+ if ( cc . sys . isMobile ) {
881+ scrollWindowUp ( editBox ) ;
882+ }
849883
850- if ( editBox . _delegate && editBox . _delegate . editBoxEditingDidBegan ) {
851- editBox . _delegate . editBoxEditingDidBegan ( editBox ) ;
884+ if ( editBox . _delegate && editBox . _delegate . editBoxEditingDidBegin ) {
885+ editBox . _delegate . editBoxEditingDidBegin ( editBox ) ;
852886 }
853887 } ) ;
854888 tmpEdTxt . addEventListener ( 'blur' , function ( ) {
@@ -862,8 +896,8 @@ cc.EditBox.create = function (size, normal9SpriteBg, press9SpriteBg, disabled9Sp
862896 cc . view . resizeWithBrowserSize ( true ) ;
863897 }
864898 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 ) ;
867901 }
868902
869903 if ( this . value === '' ) {
@@ -930,10 +964,12 @@ cc.EditBox.create = function (size, normal9SpriteBg, press9SpriteBg, disabled9Sp
930964 this . __autoResize = cc . view . __resizeWithBrowserSize ;
931965 cc . view . resizeWithBrowserSize ( false ) ;
932966
933- scrollWindowUp ( editBox ) ;
967+ if ( cc . sys . isMobile ) {
968+ scrollWindowUp ( editBox ) ;
969+ }
934970
935- if ( editBox . _delegate && editBox . _delegate . editBoxEditingDidBegan ) {
936- editBox . _delegate . editBoxEditingDidBegan ( editBox ) ;
971+ if ( editBox . _delegate && editBox . _delegate . editBoxEditingDidBegin ) {
972+ editBox . _delegate . editBoxEditingDidBegin ( editBox ) ;
937973 }
938974
939975 } ) ;
@@ -943,8 +979,8 @@ cc.EditBox.create = function (size, normal9SpriteBg, press9SpriteBg, disabled9Sp
943979 if ( e . keyCode === cc . KEY . enter ) {
944980 e . stopPropagation ( ) ;
945981
946- if ( editBox . _delegate && editBox . _delegate . editBoxEditingReturn ) {
947- editBox . _delegate . editBoxEditingReturn ( editBox ) ;
982+ if ( editBox . _delegate && editBox . _delegate . editBoxReturn ) {
983+ editBox . _delegate . editBoxReturn ( editBox ) ;
948984 }
949985 }
950986 } ) ;
@@ -960,8 +996,8 @@ cc.EditBox.create = function (size, normal9SpriteBg, press9SpriteBg, disabled9Sp
960996 cc . view . resizeWithBrowserSize ( true ) ;
961997 }
962998
963- if ( editBox . _delegate && editBox . _delegate . editBoxEditingDidEnded ) {
964- editBox . _delegate . editBoxEditingDidEnded ( editBox ) ;
999+ if ( editBox . _delegate && editBox . _delegate . editBoxEditingDidEnd ) {
1000+ editBox . _delegate . editBoxEditingDidEnd ( editBox ) ;
9651001 }
9661002
9671003 if ( this . value === '' ) {
0 commit comments