1 /**************************************************************************** 2 Copyright (c) 2011-2012 cocos2d-x.org 3 Copyright (c) 2013-2014 Chukong Technologies Inc. 4 Copyright (c) 2012 James Chen 5 6 http://www.cocos2d-x.org 7 8 Permission is hereby granted, free of charge, to any person obtaining a copy 9 of this software and associated documentation files (the "Software"), to deal 10 in the Software without restriction, including without limitation the rights 11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 copies of the Software, and to permit persons to whom the Software is 13 furnished to do so, subject to the following conditions: 14 15 The above copyright notice and this permission notice shall be included in 16 all copies or substantial portions of the Software. 17 18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 THE SOFTWARE. 25 ****************************************************************************/ 26 27 /** 28 * @constant 29 * @type Number 30 */ 31 cc.KEYBOARD_RETURNTYPE_DEFAULT = 0; 32 33 /** 34 * @constant 35 * @type Number 36 */ 37 cc.KEYBOARD_RETURNTYPE_DONE = 1; 38 39 /** 40 * @constant 41 * @type Number 42 */ 43 cc.KEYBOARD_RETURNTYPE_SEND = 2; 44 45 /** 46 * @constant 47 * @type Number 48 */ 49 cc.KEYBOARD_RETURNTYPE_SEARCH = 3; 50 51 /** 52 * @constant 53 * @type Number 54 */ 55 cc.KEYBOARD_RETURNTYPE_GO = 4; 56 57 /** 58 * The EditBoxInputMode defines the type of text that the user is allowed * to enter. 59 * @constant 60 * @type Number 61 */ 62 cc.EDITBOX_INPUT_MODE_ANY = 0; 63 64 /** 65 * The user is allowed to enter an e-mail address. 66 * @constant 67 * @type Number 68 */ 69 cc.EDITBOX_INPUT_MODE_EMAILADDR = 1; 70 71 /** 72 * The user is allowed to enter an integer value. 73 * @constant 74 * @type Number 75 */ 76 cc.EDITBOX_INPUT_MODE_NUMERIC = 2; 77 78 /** 79 * The user is allowed to enter a phone number. 80 * @constant 81 * @type Number 82 */ 83 cc.EDITBOX_INPUT_MODE_PHONENUMBER = 3; 84 85 /** 86 * The user is allowed to enter a URL. 87 * @constant 88 * @type Number 89 */ 90 cc.EDITBOX_INPUT_MODE_URL = 4; 91 92 /** 93 * The user is allowed to enter a real number value. 94 * This extends kEditBoxInputModeNumeric by allowing a decimal point. 95 * @constant 96 * @type Number 97 */ 98 cc.EDITBOX_INPUT_MODE_DECIMAL = 5; 99 100 /** 101 * The user is allowed to enter any text, except for line breaks. 102 * @constant 103 * @type Number 104 */ 105 cc.EDITBOX_INPUT_MODE_SINGLELINE = 6; 106 107 /** 108 * Indicates that the text entered is confidential data that should be 109 * obscured whenever possible. This implies EDIT_BOX_INPUT_FLAG_SENSITIVE. 110 * @constant 111 * @type Number 112 */ 113 cc.EDITBOX_INPUT_FLAG_PASSWORD = 0; 114 115 /** 116 * Indicates that the text entered is sensitive data that the 117 * implementation must never store into a dictionary or table for use 118 * in predictive, auto-completing, or other accelerated input schemes. 119 * A credit card number is an example of sensitive data. 120 * @constant 121 * @type Number 122 */ 123 cc.EDITBOX_INPUT_FLAG_SENSITIVE = 1; 124 125 /** 126 * This flag is a hint to the implementation that during text editing, 127 * the initial letter of each word should be capitalized. 128 * @constant 129 * @type Number 130 */ 131 cc.EDITBOX_INPUT_FLAG_INITIAL_CAPS_WORD = 2; 132 133 /** 134 * This flag is a hint to the implementation that during text editing, 135 * the initial letter of each sentence should be capitalized. 136 * @constant 137 * @type Number 138 */ 139 cc.EDITBOX_INPUT_FLAG_INITIAL_CAPS_SENTENCE = 3; 140 141 /** 142 * Capitalize all characters automatically. 143 * @constant 144 * @type Number 145 */ 146 cc.EDITBOX_INPUT_FLAG_INITIAL_CAPS_ALL_CHARACTERS = 4; 147 148 /** 149 * @class 150 * @extends cc.Class 151 */ 152 cc.EditBoxDelegate = cc.Class.extend({ 153 /** 154 * This method is called when an edit box gains focus after keyboard is shown. 155 * @param {cc.EditBox} sender 156 */ 157 editBoxEditingDidBegin: function (sender) { 158 }, 159 160 /** 161 * This method is called when an edit box loses focus after keyboard is hidden. 162 * @param {cc.EditBox} sender 163 */ 164 editBoxEditingDidEnd: function (sender) { 165 }, 166 167 /** 168 * This method is called when the edit box text was changed. 169 * @param {cc.EditBox} sender 170 * @param {String} text 171 */ 172 editBoxTextChanged: function (sender, text) { 173 }, 174 175 /** 176 * This method is called when the return button was pressed or the outside area of keyboard was touched. 177 * @param {cc.EditBox} sender 178 */ 179 editBoxReturn: function (sender) { 180 } 181 }); 182 183 /** 184 * <p>cc.EditBox is a brief Class for edit box.<br/> 185 * You can use this widget to gather small amounts of text from the user.</p> 186 * 187 * @class 188 * @extends cc.ControlButton 189 * 190 * @property {String} string - Content string of edit box 191 * @property {String} maxLength - Max length of the content string 192 * @property {String} font - <@writeonly> Config font of edit box 193 * @property {String} fontName - <@writeonly> Config font name of edit box 194 * @property {Number} fontSize - <@writeonly> Config font size of edit box 195 * @property {cc.Color} fontColor - <@writeonly> Config font color of edit box 196 * @property {String} placeHolder - Place holder of edit box 197 * @property {String} placeHolderFont - <@writeonly> Config font of place holder 198 * @property {String} placeHolderFontName - <@writeonly> Config font name of place holder 199 * @property {Number} placeHolderFontSize - <@writeonly> Config font size of place holder 200 * @property {cc.Color} placeHolderFontColor - <@writeonly> Config font color of place holder 201 * @property {Number} inputFlag - <@writeonly> Input flag of edit box, one of the EditBoxInputFlag constants. e.g.cc.EDITBOX_INPUT_FLAG_PASSWORD 202 * @property {Object} delegate - <@writeonly> Delegate of edit box 203 * @property {Number} inputMode - <@writeonly> Input mode of the edit box. Value should be one of the EditBoxInputMode constants. 204 * @property {Number} returnType - <@writeonly> Return type of edit box, value should be one of the KeyboardReturnType constants. 205 * 206 */ 207 cc.EditBox = cc.ControlButton.extend({ 208 _domInputSprite: null, 209 210 _delegate: null, 211 _editBoxInputMode: cc.EDITBOX_INPUT_MODE_ANY, 212 _editBoxInputFlag: cc.EDITBOX_INPUT_FLAG_SENSITIVE, 213 _keyboardReturnType: cc.KEYBOARD_RETURNTYPE_DEFAULT, 214 215 _text: "", 216 _placeholderText: "", 217 _textColor: null, 218 _placeholderColor: null, 219 _maxLength: 50, 220 _adjustHeight: 18, 221 222 _edTxt: null, 223 _edFontSize: 14, 224 _edFontName: "Arial", 225 226 _placeholderFontName: "", 227 _placeholderFontSize: 14, 228 229 _tooltip: false, 230 _className: "EditBox", 231 232 /** 233 * constructor of cc.EditBox 234 * @param {cc.Size} size 235 * @param {cc.Scale9Sprite} normal9SpriteBg 236 * @param {cc.Scale9Sprite} press9SpriteBg 237 * @param {cc.Scale9Sprite} disabled9SpriteBg 238 */ 239 ctor: function (size, normal9SpriteBg, press9SpriteBg, disabled9SpriteBg) { 240 cc.ControlButton.prototype.ctor.call(this); 241 242 this._textColor = cc.color.WHITE; 243 this._placeholderColor = cc.color.GRAY; 244 this.setContentSize(size); 245 var tmpDOMSprite = this._domInputSprite = new cc.Sprite(); 246 tmpDOMSprite.draw = function () { 247 }; //redefine draw function 248 this.addChild(tmpDOMSprite); 249 var selfPointer = this; 250 var tmpEdTxt = this._edTxt = cc.newElement("input"); 251 tmpEdTxt.type = "text"; 252 tmpEdTxt.style.fontSize = this._edFontSize + "px"; 253 tmpEdTxt.style.color = "#000000"; 254 tmpEdTxt.style.border = 0; 255 tmpEdTxt.style.background = "transparent"; 256 //tmpEdTxt.style.paddingLeft = "2px"; 257 tmpEdTxt.style.width = "100%"; 258 tmpEdTxt.style.height = "100%"; 259 tmpEdTxt.style.active = 0; 260 tmpEdTxt.style.outline = "medium"; 261 tmpEdTxt.style.padding = "0"; 262 var onCanvasClick = function() { 263 tmpEdTxt.blur(); 264 }; 265 266 // TODO the event listener will be remove when EditBox removes from parent. 267 cc._addEventListener(tmpEdTxt, "input", function () { 268 if (selfPointer._delegate && selfPointer._delegate.editBoxTextChanged) 269 selfPointer._delegate.editBoxTextChanged(selfPointer, this.value); 270 }); 271 cc._addEventListener(tmpEdTxt, "keypress", function (e) { 272 if (e.keyCode === cc.KEY.enter) { 273 e.stopPropagation(); 274 e.preventDefault(); 275 cc._canvas.focus(); 276 } 277 }); 278 cc._addEventListener(tmpEdTxt, "focus", function () { 279 if (this.value == selfPointer._placeholderText) { 280 this.value = ""; 281 this.style.fontSize = selfPointer._edFontSize + "px"; 282 this.style.color = cc.colorToHex(selfPointer._textColor); 283 } 284 if (selfPointer._delegate && selfPointer._delegate.editBoxEditingDidBegin) 285 selfPointer._delegate.editBoxEditingDidBegin(selfPointer); 286 cc._addEventListener(cc._canvas, "click", onCanvasClick); 287 }); 288 cc._addEventListener(tmpEdTxt, "blur", function () { 289 if (this.value == "") { 290 this.value = selfPointer._placeholderText; 291 this.style.fontSize = selfPointer._placeholderFontSize + "px"; 292 this.style.color = cc.colorToHex(selfPointer._placeholderColor); 293 } 294 if (selfPointer._delegate && selfPointer._delegate.editBoxEditingDidEnd) 295 selfPointer._delegate.editBoxEditingDidEnd(selfPointer); 296 if (selfPointer._delegate && selfPointer._delegate.editBoxReturn) 297 selfPointer._delegate.editBoxReturn(selfPointer); 298 cc._canvas.removeEventListener('click', onCanvasClick); 299 }); 300 301 cc.DOM.convert(tmpDOMSprite); 302 tmpDOMSprite.dom.appendChild(tmpEdTxt); 303 tmpDOMSprite.dom.showTooltipDiv = false; 304 tmpDOMSprite.dom.style.width = (size.width - 6) + "px"; 305 tmpDOMSprite.dom.style.height = (size.height - 6) + "px"; 306 307 //this._domInputSprite.dom.style.borderWidth = "1px"; 308 //this._domInputSprite.dom.style.borderStyle = "solid"; 309 //this._domInputSprite.dom.style.borderRadius = "8px"; 310 tmpDOMSprite.canvas.remove(); 311 312 if (this.initWithSizeAndBackgroundSprite(size, normal9SpriteBg)) { 313 if (press9SpriteBg) 314 this.setBackgroundSpriteForState(press9SpriteBg, cc.CONTROL_STATE_HIGHLIGHTED); 315 316 if (disabled9SpriteBg) 317 this.setBackgroundSpriteForState(disabled9SpriteBg, cc.CONTROL_STATE_DISABLED); 318 } 319 }, 320 321 /** 322 * Set the font. 323 * @param {String} fontName The font name. 324 * @param {Number} fontSize The font size. 325 */ 326 setFont: function (fontName, fontSize) { 327 this._edFontSize = fontSize; 328 this._edFontName = fontName; 329 this._setFontToEditBox(); 330 }, 331 332 _setFont: function (fontStyle) { 333 var res = cc.LabelTTF._fontStyleRE.exec(fontStyle); 334 if (res) { 335 this._edFontSize = parseInt(res[1]); 336 this._edFontName = res[2]; 337 this._setFontToEditBox(); 338 } 339 }, 340 341 /** 342 * set fontName 343 * @param {String} fontName 344 */ 345 setFontName: function (fontName) { 346 this._edFontName = fontName; 347 this._setFontToEditBox(); 348 }, 349 350 /** 351 * set fontSize 352 * @param {Number} fontSize 353 */ 354 setFontSize: function (fontSize) { 355 this._edFontSize = fontSize; 356 this._setFontToEditBox(); 357 }, 358 359 _setFontToEditBox: function () { 360 if (this._edTxt.value != this._placeholderText) { 361 this._edTxt.style.fontFamily = this._edFontName; 362 this._edTxt.style.fontSize = this._edFontSize + "px"; 363 } 364 }, 365 366 /** 367 * Set the text entered in the edit box. 368 * @deprecated 369 * @param {string} text The given text. 370 */ 371 setText: function (text) { 372 cc.log("Please use the setString"); 373 if (text != null) { 374 if (text == "") { 375 this._edTxt.value = this._placeholderText; 376 this._edTxt.style.color = cc.colorToHex(this._placeholderColor); 377 } else { 378 this._edTxt.value = text; 379 this._edTxt.style.color = cc.colorToHex(this._textColor); 380 } 381 } 382 }, 383 384 /** 385 * Set the text entered in the edit box. 386 * @param {string} text The given text. 387 */ 388 setString: function (text) { 389 if (text != null) { 390 if (text == "") { 391 this._edTxt.value = this._placeholderText; 392 this._edTxt.style.color = cc.colorToHex(this._placeholderColor); 393 } else { 394 this._edTxt.value = text; 395 this._edTxt.style.color = cc.colorToHex(this._textColor); 396 } 397 } 398 }, 399 400 /** 401 * Set the font color of the widget's text. 402 * @param {cc.Color} color 403 */ 404 setFontColor: function (color) { 405 this._textColor = color; 406 if (this._edTxt.value != this._placeholderText) { 407 this._edTxt.style.color = cc.colorToHex(color); 408 } 409 }, 410 411 /** 412 * <p> 413 * Sets the maximum input length of the edit box. <br/> 414 * Setting this value enables multiline input mode by default. 415 * </p> 416 * @param {Number} maxLength The maximum length. 417 */ 418 setMaxLength: function (maxLength) { 419 if (!isNaN(maxLength) && maxLength > 0) { 420 this._maxLength = maxLength; 421 this._edTxt.maxLength = maxLength; 422 } 423 }, 424 425 /** 426 * Gets the maximum input length of the edit box. 427 * @return {Number} Maximum input length. 428 */ 429 getMaxLength: function () { 430 return this._maxLength; 431 }, 432 433 /** 434 * Set a text in the edit box that acts as a placeholder when an edit box is empty. 435 * @param {string} text The given text. 436 */ 437 setPlaceHolder: function (text) { 438 if (text != null) { 439 var oldPlaceholderText = this._placeholderText; 440 this._placeholderText = text; 441 if (this._edTxt.value == oldPlaceholderText) { 442 this._edTxt.value = text; 443 this._edTxt.style.color = cc.colorToHex(this._placeholderColor); 444 this._setPlaceholderFontToEditText(); 445 } 446 } 447 }, 448 449 /** 450 * Set the placeholder's font. 451 * @param {String} fontName 452 * @param {Number} fontSize 453 */ 454 setPlaceholderFont: function (fontName, fontSize) { 455 this._placeholderFontName = fontName; 456 this._placeholderFontSize = fontSize; 457 this._setPlaceholderFontToEditText(); 458 }, 459 _setPlaceholderFont: function (fontStyle) { 460 var res = cc.LabelTTF._fontStyleRE.exec(fontStyle); 461 if (res) { 462 this._placeholderFontName = res[2]; 463 this._placeholderFontSize = parseInt(res[1]); 464 this._setPlaceholderFontToEditText(); 465 } 466 }, 467 468 /** 469 * Set the placeholder's fontName. 470 * @param {String} fontName 471 */ 472 setPlaceholderFontName: function (fontName) { 473 this._placeholderFontName = fontName; 474 this._setPlaceholderFontToEditText(); 475 }, 476 477 /** 478 * Set the placeholder's fontSize. 479 * @param {Number} fontSize 480 */ 481 setPlaceholderFontSize: function (fontSize) { 482 this._placeholderFontSize = fontSize; 483 this._setPlaceholderFontToEditText(); 484 }, 485 486 _setPlaceholderFontToEditText: function () { 487 if (this._edTxt.value == this._placeholderText) { 488 this._edTxt.style.fontFamily = this._placeholderFontName; 489 this._edTxt.style.fontSize = this._placeholderFontSize + "px"; 490 } 491 }, 492 493 /** 494 * Set the font color of the placeholder text when the edit box is empty. 495 * @param {cc.Color} color 496 */ 497 setPlaceholderFontColor: function (color) { 498 this._placeholderColor = color; 499 if (this._edTxt.value == this._placeholderText) { 500 this._edTxt.style.color = cc.colorToHex(color); 501 } 502 }, 503 504 /** 505 * Set the input flags that are to be applied to the edit box. 506 * @param {Number} inputFlag One of the EditBoxInputFlag constants. 507 * e.g.cc.EDITBOX_INPUT_FLAG_PASSWORD 508 */ 509 setInputFlag: function (inputFlag) { 510 this._editBoxInputFlag = inputFlag; 511 if (inputFlag == cc.EDITBOX_INPUT_FLAG_PASSWORD) 512 this._edTxt.type = "password"; 513 else 514 this._edTxt.type = "text"; 515 }, 516 517 /** 518 * Gets the input string of the edit box. 519 * @deprecated 520 * @return {string} 521 */ 522 getText: function () { 523 cc.log("Please use the getString"); 524 return this._edTxt.value; 525 }, 526 527 /** 528 * Gets the input string of the edit box. 529 * @return {string} 530 */ 531 getString: function () { 532 return this._edTxt.value; 533 }, 534 535 /** 536 * Init edit box with specified size. 537 * @param {cc.Size} size 538 * @param {cc.Color | cc.Scale9Sprite} normal9SpriteBg 539 */ 540 initWithSizeAndBackgroundSprite: function (size, normal9SpriteBg) { 541 if (this.initWithBackgroundSprite(normal9SpriteBg)) { 542 this._domInputSprite.x = 3; 543 this._domInputSprite.y = 3; 544 545 this.setZoomOnTouchDown(false); 546 this.setPreferredSize(size); 547 this.x = 0; 548 this.y = 0; 549 this._addTargetWithActionForControlEvent(this, this.touchDownAction, cc.CONTROL_EVENT_TOUCH_UP_INSIDE); 550 return true; 551 } 552 return false; 553 }, 554 555 /* override functions */ 556 /** 557 * Set the delegate for edit box. 558 * @param {cc.EditBoxDelegate} delegate 559 */ 560 setDelegate: function (delegate) { 561 this._delegate = delegate; 562 }, 563 564 /** 565 * Get a text in the edit box that acts as a placeholder when an 566 * edit box is empty. 567 * @return {String} 568 */ 569 getPlaceHolder: function () { 570 return this._placeholderText; 571 }, 572 573 /** 574 * Set the input mode of the edit box. 575 * @param {Number} inputMode One of the EditBoxInputMode constants. 576 */ 577 setInputMode: function (inputMode) { 578 this._editBoxInputMode = inputMode; 579 }, 580 581 /** 582 * Set the return type that are to be applied to the edit box. 583 * @param {Number} returnType One of the CCKeyboardReturnType constants. 584 */ 585 setReturnType: function (returnType) { 586 this._keyboardReturnType = returnType; 587 }, 588 589 keyboardWillShow: function (info) { 590 var rectTracked = cc.EditBox.getRect(this); 591 // some adjustment for margin between the keyboard and the edit box. 592 rectTracked.y -= 4; 593 // if the keyboard area doesn't intersect with the tracking node area, nothing needs to be done. 594 if (!rectTracked.intersectsRect(info.end)) { 595 cc.log("needn't to adjust view layout."); 596 return; 597 } 598 599 // assume keyboard at the bottom of screen, calculate the vertical adjustment. 600 this._adjustHeight = info.end.getMaxY() - rectTracked.getMinY(); 601 // CCLOG("CCEditBox:needAdjustVerticalPosition(%f)", m_fAdjustHeight); 602 603 //callback 604 }, 605 keyboardDidShow: function (info) { 606 }, 607 keyboardWillHide: function (info) { 608 //if (m_pEditBoxImpl != NULL) { 609 // m_pEditBoxImpl->doAnimationWhenKeyboardMove(info.duration, -m_fAdjustHeight); 610 //} 611 }, 612 keyboardDidHide: function (info) { 613 }, 614 615 touchDownAction: function (sender, controlEvent) { 616 //this._editBoxImpl.openKeyboard(); 617 }, 618 619 /** 620 * @warning HTML5 Only 621 * @param {cc.Size} size 622 * @param {cc.color} bgColor 623 */ 624 initWithBackgroundColor: function (size, bgColor) { 625 this._edWidth = size.width; 626 this.dom.style.width = this._edWidth.toString() + "px"; 627 this._edHeight = size.height; 628 this.dom.style.height = this._edHeight.toString() + "px"; 629 this.dom.style.backgroundColor = cc.colorToHex(bgColor); 630 } 631 }); 632 633 var _p = cc.EditBox.prototype; 634 635 // Extended properties 636 /** @expose */ 637 _p.font; 638 cc.defineGetterSetter(_p, "font", null, _p._setFont); 639 /** @expose */ 640 _p.fontName; 641 cc.defineGetterSetter(_p, "fontName", null, _p.setFontName); 642 /** @expose */ 643 _p.fontSize; 644 cc.defineGetterSetter(_p, "fontSize", null, _p.setFontSize); 645 /** @expose */ 646 _p.fontColor; 647 cc.defineGetterSetter(_p, "fontColor", null, _p.setFontColor); 648 /** @expose */ 649 _p.string; 650 cc.defineGetterSetter(_p, "string", _p.getString, _p.setString); 651 /** @expose */ 652 _p.maxLength; 653 cc.defineGetterSetter(_p, "maxLength", _p.getMaxLength, _p.setMaxLength); 654 /** @expose */ 655 _p.placeHolder; 656 cc.defineGetterSetter(_p, "placeHolder", _p.getPlaceHolder, _p.setPlaceHolder); 657 /** @expose */ 658 _p.placeHolderFont; 659 cc.defineGetterSetter(_p, "placeHolderFont", null, _p._setPlaceholderFont); 660 /** @expose */ 661 _p.placeHolderFontName; 662 cc.defineGetterSetter(_p, "placeHolderFontName", null, _p.setPlaceholderFontName); 663 /** @expose */ 664 _p.placeHolderFontSize; 665 cc.defineGetterSetter(_p, "placeHolderFontSize", null, _p.setPlaceholderFontSize); 666 /** @expose */ 667 _p.placeHolderFontColor; 668 cc.defineGetterSetter(_p, "placeHolderFontColor", null, _p.setPlaceholderFontColor); 669 /** @expose */ 670 _p.inputFlag; 671 cc.defineGetterSetter(_p, "inputFlag", null, _p.setInputFlag); 672 /** @expose */ 673 _p.delegate; 674 cc.defineGetterSetter(_p, "delegate", null, _p.setDelegate); 675 /** @expose */ 676 _p.inputMode; 677 cc.defineGetterSetter(_p, "inputMode", null, _p.setInputMode); 678 /** @expose */ 679 _p.returnType; 680 cc.defineGetterSetter(_p, "returnType", null, _p.setReturnType); 681 682 _p = null; 683 684 /** 685 * get the rect of a node in world coordinate frame 686 * @function 687 * @param {cc.Node} node 688 * @return {cc.rect} 689 */ 690 cc.EditBox.getRect = function (node) { 691 var contentSize = node.getContentSize(); 692 var rect = cc.rect(0, 0, contentSize.width, contentSize.height); 693 return cc.rectApplyAffineTransform(rect, node.nodeToWorldTransform()); 694 }; 695 696 /** 697 * create a edit box with size and background-color or 698 * @deprecated since v3.0, please use new cc.EditBox(size, normal9SpriteBg, press9SpriteBg, disabled9SpriteBg) instead 699 * @param {cc.Size} size 700 * @param {cc.Scale9Sprite } normal9SpriteBg 701 * @param {cc.Scale9Sprite } [press9SpriteBg] 702 * @param {cc.Scale9Sprite } [disabled9SpriteBg] 703 * @return {cc.EditBox} 704 */ 705 cc.EditBox.create = function (size, normal9SpriteBg, press9SpriteBg, disabled9SpriteBg) { 706 return new cc.EditBox(size, normal9SpriteBg, press9SpriteBg, disabled9SpriteBg); 707 }; 708 709 710 711 712