1 /**************************************************************************** 2 Copyright (c) 2011-2012 cocos2d-x.org 3 Copyright (c) 2013-2014 Chukong Technologies Inc. 4 5 http://www.cocos2d-x.org 6 7 Permission is hereby granted, free of charge, to any person obtaining a copy 8 of this software and associated documentation files (the "Software"), to deal 9 in the Software without restriction, including without limitation the rights 10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 copies of the Software, and to permit persons to whom the Software is 12 furnished to do so, subject to the following conditions: 13 14 The above copyright notice and this permission notice shall be included in 15 all copies or substantial portions of the Software. 16 17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 THE SOFTWARE. 24 ****************************************************************************/ 25 26 /** 27 * @ignore 28 */ 29 //it's a private class, it's a renderer of ccui.TextField. 30 ccui._TextFieldRenderer = cc.TextFieldTTF.extend({ 31 _maxLengthEnabled: false, 32 _maxLength: 0, 33 _passwordEnabled: false, 34 _passwordStyleText: "", 35 _attachWithIME: false, 36 _detachWithIME: false, 37 _insertText: false, 38 _deleteBackward: false, 39 _className: "_TextFieldRenderer", 40 _textFieldRendererAdaptDirty: true, 41 42 ctor: function () { 43 cc.TextFieldTTF.prototype.ctor.call(this); 44 this._maxLengthEnabled = false; 45 this._maxLength = 0; 46 this._passwordEnabled = false; 47 this._passwordStyleText = "*"; 48 this._attachWithIME = false; 49 this._detachWithIME = false; 50 this._insertText = false; 51 this._deleteBackward = false; 52 }, 53 54 onEnter: function () { 55 cc.TextFieldTTF.prototype.onEnter.call(this); 56 cc.TextFieldTTF.prototype.setDelegate.call(this, this); 57 }, 58 59 onTextFieldAttachWithIME: function (sender) { 60 this.setAttachWithIME(true); 61 return false; 62 }, 63 64 onTextFieldInsertText: function (sender, text, len) { 65 if (len == 1 && text == "\n") 66 return false; 67 68 this.setInsertText(true); 69 return (this._maxLengthEnabled) && (cc.TextFieldTTF.prototype.getCharCount.call(this) >= this._maxLength); 70 }, 71 72 onTextFieldDeleteBackward: function (sender, delText, nLen) { 73 this.setDeleteBackward(true); 74 return false; 75 }, 76 77 onTextFieldDetachWithIME: function (sender) { 78 this.setDetachWithIME(true); 79 return false; 80 }, 81 82 insertText: function (text, len) { 83 var input_text = text; 84 85 if (text != "\n"){ 86 if (this._maxLengthEnabled){ 87 var text_count = this.getString().length; 88 if (text_count >= this._maxLength){ 89 // password 90 if (this._passwordEnabled) 91 this.setPasswordText(this.getString()); 92 return; 93 } 94 } 95 } 96 cc.TextFieldTTF.prototype.insertText.call(this, input_text, len); 97 98 // password 99 if (this._passwordEnabled && cc.TextFieldTTF.prototype.getCharCount.call(this) > 0) 100 this.setPasswordText(this.getString()); 101 }, 102 103 deleteBackward: function () { 104 cc.TextFieldTTF.prototype.deleteBackward.call(this); 105 106 if (cc.TextFieldTTF.prototype.getCharCount.call(this) > 0 && this._passwordEnabled) 107 this.setPasswordText(this._inputText); 108 }, 109 110 openIME: function () { 111 cc.TextFieldTTF.prototype.attachWithIME.call(this); 112 }, 113 114 closeIME: function () { 115 cc.TextFieldTTF.prototype.detachWithIME.call(this); 116 }, 117 118 setMaxLengthEnabled: function (enable) { 119 this._maxLengthEnabled = enable; 120 }, 121 122 isMaxLengthEnabled: function () { 123 return this._maxLengthEnabled; 124 }, 125 126 setMaxLength: function (length) { 127 this._maxLength = length; 128 }, 129 130 getMaxLength: function () { 131 return this._maxLength; 132 }, 133 134 getCharCount: function () { 135 return cc.TextFieldTTF.prototype.getCharCount.call(this); 136 }, 137 138 setPasswordEnabled: function (enable) { 139 this._passwordEnabled = enable; 140 }, 141 142 isPasswordEnabled: function () { 143 return this._passwordEnabled; 144 }, 145 146 setPasswordStyleText: function (styleText) { 147 if (styleText.length > 1) 148 return; 149 var header = styleText.charCodeAt(0); 150 if (header < 33 || header > 126) 151 return; 152 this._passwordStyleText = styleText; 153 }, 154 155 setPasswordText: function (text) { 156 var tempStr = ""; 157 var text_count = text.length; 158 var max = text_count; 159 160 if (this._maxLengthEnabled && text_count > this._maxLength) 161 max = this._maxLength; 162 163 for (var i = 0; i < max; ++i) 164 tempStr += this._passwordStyleText; 165 166 cc.LabelTTF.prototype.setString.call(this, tempStr); 167 }, 168 169 setAttachWithIME: function (attach) { 170 this._attachWithIME = attach; 171 }, 172 173 getAttachWithIME: function () { 174 return this._attachWithIME; 175 }, 176 177 setDetachWithIME: function (detach) { 178 this._detachWithIME = detach; 179 }, 180 181 getDetachWithIME: function () { 182 return this._detachWithIME; 183 }, 184 185 setInsertText: function (insert) { 186 this._insertText = insert; 187 }, 188 189 getInsertText: function () { 190 return this._insertText; 191 }, 192 193 setDeleteBackward: function (deleteBackward) { 194 this._deleteBackward = deleteBackward; 195 }, 196 197 getDeleteBackward: function () { 198 return this._deleteBackward; 199 }, 200 201 onDraw: function (sender) { 202 return false; 203 } 204 }); 205 206 ccui._TextFieldRenderer.create = function (placeholder, fontName, fontSize) { 207 var ret = new ccui._TextFieldRenderer(); 208 if (ret && ret.initWithString("", fontName, fontSize)) { 209 if (placeholder) 210 ret.setPlaceHolder(placeholder); 211 return ret; 212 } 213 return null; 214 }; 215 216 /** 217 * 218 * @class 219 * @extends ccui.Widget 220 * 221 * @property {String} string - The content string of the label 222 * @property {Number} placeHolder - The place holder of the text field 223 * @property {String} font - The text field font with a style string: e.g. "18px Verdana" 224 * @property {String} fontName - The text field font name 225 * @property {Number} fontSize - The text field font size 226 * @property {Boolean} maxLengthEnabled - Indicate whether max length limit is enabled 227 * @property {Number} maxLength - The max length of the text field 228 * @property {Boolean} passwordEnabled - Indicate whether the text field is for entering password 229 */ 230 ccui.TextField = ccui.Widget.extend(/** @lends ccui.TextField# */{ 231 _textFieldRenderer: null, 232 _touchWidth: 0, 233 _touchHeight: 0, 234 _useTouchArea: false, 235 _textFieldEventListener: null, 236 _textFieldEventSelector: null, 237 _passwordStyleText: "", 238 _textFieldRendererAdaptDirty: true, 239 _fontName: "", 240 _fontSize: 12, 241 242 /** 243 * allocates and initializes a UITextField. 244 * Constructor of ccui.TextField. override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 245 * @param {string} placeholder 246 * @param {string} fontName 247 * @param {Number} fontSize 248 * @example 249 * // example 250 * var uiTextField = new ccui.TextField(); 251 */ 252 ctor: function (placeholder, fontName, fontSize) { 253 ccui.Widget.prototype.ctor.call(this); 254 if (placeholder) 255 this.setPlaceHolder(placeholder); 256 if (fontName) 257 this.setFontName(fontName); 258 if (fontSize) 259 this.setFontSize(fontSize); 260 }, 261 262 /** 263 * Initializes a ccui.TextField. Please do not call this function by yourself, you should pass the parameters to constructor to initialize it. 264 * @returns {boolean} 265 * @override 266 */ 267 init: function(){ 268 if(ccui.Widget.prototype.init.call(this)){ 269 this.setTouchEnabled(true); 270 return true; 271 } 272 return false; 273 }, 274 275 /** 276 * Calls parent class' onEnter and schedules update function. 277 * @override 278 */ 279 onEnter: function () { 280 ccui.Widget.prototype.onEnter.call(this); 281 this.scheduleUpdate(); 282 }, 283 284 _initRenderer: function () { 285 this._textFieldRenderer = ccui._TextFieldRenderer.create("input words here", "Thonburi", 20); 286 this.addProtectedChild(this._textFieldRenderer, ccui.TextField.RENDERER_ZORDER, -1); 287 }, 288 289 /** 290 * Sets touch size of ccui.TextField. 291 * @param {cc.Size} size 292 */ 293 setTouchSize: function (size) { 294 this._touchWidth = size.width; 295 this._touchHeight = size.height; 296 }, 297 298 /** 299 * Sets whether use touch area. 300 * @param enable 301 */ 302 setTouchAreaEnabled: function(enable){ 303 this._useTouchArea = enable; 304 }, 305 306 /** 307 * Checks a point if is in ccui.TextField's space 308 * @param {cc.Point} pt 309 * @returns {boolean} 310 */ 311 hitTest: function(pt){ 312 if (this._useTouchArea) { 313 var nsp = this.convertToNodeSpace(pt); 314 var bb = cc.rect( 315 -this._touchWidth * this._anchorPoint.x, 316 -this._touchHeight * this._anchorPoint.y, 317 this._touchWidth, this._touchHeight 318 ); 319 320 return ( nsp.x >= bb.x && nsp.x <= bb.x + bb.width && 321 nsp.y >= bb.y && nsp.y <= bb.y + bb.height ); 322 } else 323 return ccui.Widget.prototype.hitTest.call(this, pt); 324 }, 325 326 /** 327 * Returns touch size of ccui.TextField. 328 * @returns {cc.Size} 329 */ 330 getTouchSize: function () { 331 return cc.size(this._touchWidth, this._touchHeight); 332 }, 333 334 /** 335 * Changes the string value of textField. 336 * @deprecated since v3.0, please use setString instead. 337 * @param {String} text 338 */ 339 setText: function (text) { 340 cc.log("Please use the setString"); 341 this.setString(text); 342 }, 343 344 /** 345 * Changes the string value of textField. 346 * @param {String} text 347 */ 348 setString: function (text) { 349 if (!text) 350 return; 351 352 text = String(text); 353 if (this.isMaxLengthEnabled()) 354 text = text.substr(0, this.getMaxLength()); 355 if (this.isPasswordEnabled()) { 356 this._textFieldRenderer.setPasswordText(text); 357 this._textFieldRenderer.setString(""); 358 this._textFieldRenderer.insertText(text, text.length); 359 } else 360 this._textFieldRenderer.setString(text); 361 this._textFieldRendererAdaptDirty = true; 362 this._updateContentSizeWithTextureSize(this._textFieldRenderer.getContentSize()); 363 }, 364 365 /** 366 * Sets the placeholder string. <br /> 367 * display this string if string equal "". 368 * @param {String} value 369 */ 370 setPlaceHolder: function (value) { 371 this._textFieldRenderer.setPlaceHolder(value); 372 this._textFieldRendererAdaptDirty = true; 373 this._updateContentSizeWithTextureSize(this._textFieldRenderer.getContentSize()); 374 }, 375 376 /** 377 * Returns the placeholder string. 378 * @returns {String} 379 */ 380 getPlaceHolder: function () { 381 return this._textFieldRenderer.getPlaceHolder(); 382 }, 383 384 /** 385 * Sets font size for ccui.TextField. 386 * @param {Number} size 387 */ 388 setFontSize: function (size) { 389 this._textFieldRenderer.setFontSize(size); 390 this._fontSize = size; 391 this._textFieldRendererAdaptDirty = true; 392 this._updateContentSizeWithTextureSize(this._textFieldRenderer.getContentSize()); 393 }, 394 395 /** 396 * Gets font size of ccui.TextField. 397 * @return {Number} size 398 */ 399 getFontSize: function () { 400 return this._fontSize; 401 }, 402 403 /** 404 * Sets font name for ccui.TextField 405 * @param {String} name 406 */ 407 setFontName: function (name) { 408 this._textFieldRenderer.setFontName(name); 409 this._fontName = name; 410 this._textFieldRendererAdaptDirty = true; 411 this._updateContentSizeWithTextureSize(this._textFieldRenderer.getContentSize()); 412 }, 413 414 /** 415 * Returns font name of ccui.TextField. 416 * @return {String} font name 417 */ 418 getFontName: function () { 419 return this._fontName; 420 }, 421 422 /** 423 * detach with IME 424 */ 425 didNotSelectSelf: function () { 426 this._textFieldRenderer.detachWithIME(); 427 }, 428 429 /** 430 * Returns textField string value 431 * @deprecated since v3.0, please use getString instead. 432 * @returns {String} 433 */ 434 getStringValue: function () { 435 cc.log("Please use the getString"); 436 return this.getString(); 437 }, 438 439 /** 440 * Returns string value of ccui.TextField. 441 * @returns {String} 442 */ 443 getString: function () { 444 return this._textFieldRenderer.getString(); 445 }, 446 447 /** 448 * Returns the length of ccui.TextField. 449 * @returns {Number} 450 */ 451 getStringLength: function(){ 452 return this._textFieldRenderer.getStringLength(); 453 }, 454 455 /** 456 * The touch began event callback handler. 457 * @param {cc.Point} touchPoint 458 */ 459 onTouchBegan: function (touchPoint, unusedEvent) { 460 var self = this; 461 var pass = ccui.Widget.prototype.onTouchBegan.call(self, touchPoint, unusedEvent); 462 if (self._hit) { 463 setTimeout(function(){ 464 self._textFieldRenderer.attachWithIME(); 465 }, 0); 466 } 467 return pass; 468 }, 469 470 /** 471 * Sets Whether to open string length limit for ccui.TextField. 472 * @param {Boolean} enable 473 */ 474 setMaxLengthEnabled: function (enable) { 475 this._textFieldRenderer.setMaxLengthEnabled(enable); 476 }, 477 478 /** 479 * Returns Whether to open string length limit. 480 * @returns {Boolean} 481 */ 482 isMaxLengthEnabled: function () { 483 return this._textFieldRenderer.isMaxLengthEnabled(); 484 }, 485 486 /** 487 * Sets the max length of ccui.TextField. Only when you turn on the string length limit, it is valid. 488 * @param {number} length 489 */ 490 setMaxLength: function (length) { 491 this._textFieldRenderer.setMaxLength(length); 492 this.setString(this.getString()); 493 }, 494 495 /** 496 * Returns the max length of ccui.TextField. 497 * @returns {number} length 498 */ 499 getMaxLength: function () { 500 return this._textFieldRenderer.getMaxLength(); 501 }, 502 503 /** 504 * Sets whether to open setting string as password character. 505 * @param {Boolean} enable 506 */ 507 setPasswordEnabled: function (enable) { 508 this._textFieldRenderer.setPasswordEnabled(enable); 509 }, 510 511 /** 512 * Returns whether to open setting string as password character. 513 * @returns {Boolean} 514 */ 515 isPasswordEnabled: function () { 516 return this._textFieldRenderer.isPasswordEnabled(); 517 }, 518 519 /** 520 * Sets the password style character, Only when you turn on setting string as password character, it is valid. 521 * @param styleText 522 */ 523 setPasswordStyleText: function(styleText){ 524 this._textFieldRenderer.setPasswordStyleText(styleText); 525 this._passwordStyleText = styleText; 526 527 this.setString(this.getString()); 528 }, 529 530 /** 531 * Returns the password style character. 532 * @returns {String} 533 */ 534 getPasswordStyleText: function () { 535 return this._passwordStyleText; 536 }, 537 538 update: function (dt) { 539 if (this.getAttachWithIME()) { 540 this._attachWithIMEEvent(); 541 this.setAttachWithIME(false); 542 } 543 if (this.getDetachWithIME()) { 544 this._detachWithIMEEvent(); 545 this.setDetachWithIME(false); 546 } 547 if (this.getInsertText()) { 548 this._insertTextEvent(); 549 this.setInsertText(false); 550 this._textFieldRendererAdaptDirty = true; 551 this._updateContentSizeWithTextureSize(this._textFieldRenderer.getContentSize()); 552 } 553 if (this.getDeleteBackward()) { 554 this._deleteBackwardEvent(); 555 this.setDeleteBackward(false); 556 this._textFieldRendererAdaptDirty = true; 557 this._updateContentSizeWithTextureSize(this._textFieldRenderer.getContentSize()); 558 } 559 }, 560 561 /** 562 * Returns whether attach with IME. 563 * @returns {Boolean} 564 */ 565 getAttachWithIME: function () { 566 return this._textFieldRenderer.getAttachWithIME(); 567 }, 568 569 /** 570 * Sets attach with IME. 571 * @param {Boolean} attach 572 */ 573 setAttachWithIME: function (attach) { 574 this._textFieldRenderer.setAttachWithIME(attach); 575 }, 576 577 /** 578 * Returns whether detach with IME. 579 * @returns {Boolean} 580 */ 581 getDetachWithIME: function () { 582 return this._textFieldRenderer.getDetachWithIME(); 583 }, 584 585 /** 586 * Sets detach with IME. 587 * @param {Boolean} detach 588 */ 589 setDetachWithIME: function (detach) { 590 this._textFieldRenderer.setDetachWithIME(detach); 591 }, 592 593 /** 594 * Returns insertText string of ccui.TextField. 595 * @returns {String} 596 */ 597 getInsertText: function () { 598 return this._textFieldRenderer.getInsertText(); 599 }, 600 601 /** 602 * Sets insertText string to ccui.TextField. 603 * @param {String} insertText 604 */ 605 setInsertText: function (insertText) { 606 this._textFieldRenderer.setInsertText(insertText); 607 }, 608 609 /** 610 * Returns the delete backward of ccui.TextField. 611 * @returns {Boolean} 612 */ 613 getDeleteBackward: function () { 614 return this._textFieldRenderer.getDeleteBackward(); 615 }, 616 617 /** 618 * Sets the delete backward of ccui.TextField. 619 * @param {Boolean} deleteBackward 620 */ 621 setDeleteBackward: function (deleteBackward) { 622 this._textFieldRenderer.setDeleteBackward(deleteBackward); 623 }, 624 625 _attachWithIMEEvent: function () { 626 if (this._textFieldEventListener && this._textFieldEventSelector) 627 this._textFieldEventSelector.call(this._textFieldEventListener, this, ccui.TextField.EVENT_ATTACH_WITH_IME); 628 if (this._eventCallback) 629 this._eventCallback(this, ccui.TextField.EVENT_ATTACH_WITH_IME); 630 }, 631 632 _detachWithIMEEvent: function () { 633 if (this._textFieldEventListener && this._textFieldEventSelector) 634 this._textFieldEventSelector.call(this._textFieldEventListener, this, ccui.TextField.EVENT_DETACH_WITH_IME); 635 if (this._eventCallback) 636 this._eventCallback(this, ccui.TextField.EVENT_DETACH_WITH_IME); 637 }, 638 639 _insertTextEvent: function () { 640 if (this._textFieldEventListener && this._textFieldEventSelector) 641 this._textFieldEventSelector.call(this._textFieldEventListener, this, ccui.TextField.EVENT_INSERT_TEXT); 642 if (this._eventCallback) 643 this._eventCallback(this, ccui.TextField.EVENT_INSERT_TEXT); 644 }, 645 646 _deleteBackwardEvent: function () { 647 if (this._textFieldEventListener && this._textFieldEventSelector) 648 this._textFieldEventSelector.call(this._textFieldEventListener, this, ccui.TextField.EVENT_DELETE_BACKWARD); 649 if (this._eventCallback) 650 this._eventCallback(this, ccui.TextField.EVENT_DELETE_BACKWARD); 651 }, 652 653 /** 654 * Adds event listener to cuci.TextField. 655 * @param {Object} target 656 * @param {Function} selector 657 * @deprecated since v3.0, please use addEventListener instead. 658 */ 659 addEventListenerTextField: function (selector, target) { 660 this._textFieldEventSelector = selector; 661 this._textFieldEventListener = target; 662 }, 663 664 /** 665 * Adds event listener callback. 666 * @param {function} callback 667 */ 668 addEventListener: function(callback){ 669 this._eventCallback = callback; 670 }, 671 672 _onSizeChanged: function () { 673 ccui.Widget.prototype._onSizeChanged.call(this); 674 this._textFieldRendererAdaptDirty = true; 675 }, 676 677 _adaptRenderers: function(){ 678 if (this._textFieldRendererAdaptDirty) { 679 this._textfieldRendererScaleChangedWithSize(); 680 this._textFieldRendererAdaptDirty = false; 681 } 682 }, 683 684 _textfieldRendererScaleChangedWithSize: function () { 685 if (!this._ignoreSize) 686 this._textFieldRenderer.setDimensions(this._contentSize); 687 this._textFieldRenderer.setPosition(this._contentSize.width / 2, this._contentSize.height / 2); 688 }, 689 690 /** 691 * Returns the ccui.TextField's content size. 692 * @returns {cc.Size} 693 */ 694 getVirtualRendererSize: function(){ 695 return this._textFieldRenderer.getContentSize(); 696 }, 697 698 /** 699 * Returns the renderer of ccui.TextField. 700 * @returns {cc.Node} 701 */ 702 getVirtualRenderer: function () { 703 return this._textFieldRenderer; 704 }, 705 706 /** 707 * Returns the "class name" of ccui.TextField. 708 * @returns {string} 709 */ 710 getDescription: function () { 711 return "TextField"; 712 }, 713 714 /** 715 * Open keyboard and receive input text. 716 * @return {Boolean} 717 */ 718 attachWithIME: function () { 719 this._textFieldRenderer.attachWithIME(); 720 }, 721 722 _createCloneInstance: function () { 723 return ccui.TextField.create(); 724 }, 725 726 _copySpecialProperties: function (textField) { 727 this.setString(textField._textFieldRenderer.getString()); 728 this.setPlaceHolder(textField.getString()); 729 this.setFontSize(textField._textFieldRenderer.getFontSize()); 730 this.setFontName(textField._textFieldRenderer.getFontName()); 731 this.setMaxLengthEnabled(textField.isMaxLengthEnabled()); 732 this.setMaxLength(textField.getMaxLength()); 733 this.setPasswordEnabled(textField.isPasswordEnabled()); 734 this.setPasswordStyleText(textField._passwordStyleText); 735 this.setAttachWithIME(textField.getAttachWithIME()); 736 this.setDetachWithIME(textField.getDetachWithIME()); 737 this.setInsertText(textField.getInsertText()); 738 this.setDeleteBackward(textField.getDeleteBackward()); 739 }, 740 741 /** 742 * Sets the text area size to ccui.TextField. 743 * @param {cc.Size} size 744 */ 745 setTextAreaSize: function(size){ 746 this.setContentSize(size); 747 }, 748 749 /** 750 * Sets the text horizontal alignment of ccui.TextField. 751 * @param alignment 752 */ 753 setTextHorizontalAlignment: function(alignment){ 754 this._textFieldRenderer.setHorizontalAlignment(alignment); 755 }, 756 757 /** 758 * Sets the text vertical alignment of ccui.TextField. 759 * @param alignment 760 */ 761 setTextVerticalAlignment: function(alignment){ 762 this._textFieldRenderer.setVerticalAlignment(alignment); 763 }, 764 _setFont: function (font) { 765 this._textFieldRender._setFont(font); 766 this._textFieldRendererAdaptDirty = true; 767 }, 768 769 _getFont: function () { 770 return this._textFieldRender._getFont(); 771 } 772 }); 773 774 /** 775 * Creates a ccui.TextField. 776 * @deprecated since v3.0, please use new ccui.TextField() instead. 777 * @param {String} placeholder 778 * @param {String} fontName 779 * @param {Number} fontSize 780 * @returns {ccui.TextField} 781 * @example 782 * // example 783 * var uiTextField = ccui.TextField.create(); 784 */ 785 ccui.TextField.create = function(placeholder, fontName, fontSize){ 786 return new ccui.TextField(placeholder, fontName, fontSize); 787 }; 788 789 var _p = ccui.TextField.prototype; 790 791 // Extended properties 792 /** @expose */ 793 _p.string; 794 cc.defineGetterSetter(_p, "string", _p.getString, _p.setString); 795 /** @expose */ 796 _p.placeHolder; 797 cc.defineGetterSetter(_p, "placeHolder", _p.getPlaceHolder, _p.setPlaceHolder); 798 /** @expose */ 799 _p.font; 800 cc.defineGetterSetter(_p, "font", _p._getFont, _p._setFont); 801 /** @expose */ 802 _p.fontSize; 803 cc.defineGetterSetter(_p, "fontSize", _p.getFontSize, _p.setFontSize); 804 /** @expose */ 805 _p.fontName; 806 cc.defineGetterSetter(_p, "fontName", _p.getFontName, _p.setFontName); 807 /** @expose */ 808 _p.maxLengthEnabled; 809 cc.defineGetterSetter(_p, "maxLengthEnabled", _p.isMaxLengthEnabled, _p.setMaxLengthEnabled); 810 /** @expose */ 811 _p.maxLength; 812 cc.defineGetterSetter(_p, "maxLength", _p.getMaxLength, _p.setMaxLength); 813 /** @expose */ 814 _p.passwordEnabled; 815 cc.defineGetterSetter(_p, "passwordEnabled", _p.isPasswordEnabled, _p.setPasswordEnabled); 816 817 _p = null; 818 819 // Constants 820 //TextField event 821 /** 822 * The attach with IME event flag of ccui.TextField 823 * @constant 824 * @type {number} 825 */ 826 ccui.TextField.EVENT_ATTACH_WITH_IME = 0; 827 /** 828 * The detach with IME event flag of ccui.TextField 829 * @constant 830 * @type {number} 831 */ 832 ccui.TextField.EVENT_DETACH_WITH_IME = 1; 833 /** 834 * The insert text event flag of ccui.TextField 835 * @constant 836 * @type {number} 837 */ 838 ccui.TextField.EVENT_INSERT_TEXT = 2; 839 /** 840 * The delete backward event flag of ccui.TextField 841 * @constant 842 * @type {number} 843 */ 844 ccui.TextField.EVENT_DELETE_BACKWARD = 3; 845 846 /** 847 * The zOrder value of ccui.TextField's renderer. 848 * @constant 849 * @type {number} 850 */ 851 ccui.TextField.RENDERER_ZORDER = -1;