var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
/**
 * @module annie
 */
var annie;
(function (annie) {
    /**
     * <h4><font color="red">小游戏不支持 小程序不支持</font></h4>
     * 输入文本,此文本类是annie.FloatDisplay对象的典型代表
     * @class annie.InputText
     * @public
     * @since 1.0.0
     * @extends annie.FloatDisplay
     */
    var InputText = (function (_super) {
        __extends(InputText, _super);
        /**
         * @method InputText
         * @public
         * @since 1.0.0
         * @param {number} inputType 0 input 1 password 2 multiline
         * @example
         *      var inputText=new annie.InputText('singleline');
         *      inputText.initInfo('annie',100,100,'#ffffff','left',14,'微软雅黑',false,2);
         */
        function InputText(inputType) {
            if (inputType === void 0) { inputType = 0; }
            _super.call(this);
            /**
             * 输入文本的类型.
             * @property inputType
             * @public
             * @since 1.0.0
             * @type {number} 0 input 1 password 2 mulit
             * @default 0
             */
            this.inputType = 0;
            /**
             * 在手机端是否需要自动收回软键盘,在pc端此参数无效
             * @property isAutoDownKeyBoard
             * @type {boolean}
             * @since 1.0.3
             * @default true
             */
            this.isAutoDownKeyBoard = true;
            this._size = 14;
            this._font = "Arial";
            var input = null;
            var s = this;
            s._instanceType = "annie.InputText";
            if (inputType < 2) {
                input = document.createElement("input");
                input.type = InputText._inputTypeList[inputType];
            }
            else {
                input = document.createElement("textarea");
                input.style.resize = "none";
                input.style.overflow = "hidden";
            }
            s.inputType = inputType;
            var remove = function () {
                if (s.stage._isMouseClickCanvas && s.isAutoDownKeyBoard && annie.osType != "pc") {
                    s.htmlElement && s.htmlElement.blur();
                }
            }.bind(s);
            s.addEventListener(annie.Event.REMOVE_TO_STAGE, function (e) {
                s.stage.removeEventListener(annie.MouseEvent.MOUSE_DOWN, remove);
            });
            s.addEventListener(annie.Event.ADD_TO_STAGE, function (e) {
                s.stage.addEventListener(annie.MouseEvent.MOUSE_DOWN, remove);
            });
            s.init(input);
        }
        /**
         * 初始化输入文本
         * @method init
         * @param htmlElement
         * @public
         * @return {void}
         * @since 1.0.0
         */
        InputText.prototype.init = function (htmlElement) {
            _super.prototype.init.call(this, htmlElement);
            //默认设置
            var s = this;
            s.htmlElement.style.outline = "none";
            s.htmlElement.style.borderWidth = "thin";
            s.htmlElement.style.borderColor = "#000";
            s.htmlElement.style.padding = 0;
            s.htmlElement.style.margin = 0;
            s.htmlElement.onblur = function () {
                window.scrollTo(0, 0);
            };
        };
        /**
         * 被始化输入文件的一些属性
         * @method initInfo
         * @public
         * @since 1.0.0
         * @param {string} text 默认文字
         * @param {string}color 文字颜色
         * @param {string}align 文字的对齐方式
         * @param {number}size  文字大小
         * @param {string}font  文字所使用的字体
         * @param {boolean}showBorder 是否需要显示边框
         * @param {number}lineHeight 如果是多行,请设置行高
         */
        InputText.prototype.initInfo = function (text, color, align, size, font, showBorder, lineHeight) {
            var s = this;
            s.htmlElement.placeholder = text;
            //font包括字体和大小
            s.htmlElement.style.font = size + "px " + font;
            s._size = size;
            s._font = font;
            s.htmlElement.style.color = color;
            s.htmlElement.style.textAlign = align;
            /////////////////////设置边框//////////////
            s.border = showBorder;
            //color:blue; text-align:center"
            if (s.inputType != 2) {
                s.lineHeight = lineHeight;
            }
        };
        Object.defineProperty(InputText.prototype, "lineHeight", {
            get: function () {
                return parseInt(this.htmlElement.style.lineHeight);
            },
            /**
             * @property lineHeight
             * @public
             * @since 2.0.0
             * @type {number}
             */
            set: function (value) {
                this.htmlElement.style.lineHeight = value + "px";
                this.htmlElement.style.height = value + "px";
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(InputText.prototype, "bold", {
            get: function () {
                return this.htmlElement.style.fontWeight == "bold";
            },
            /**
             * 设置文本是否为粗体
             * @property bold
             * @public
             * @type {boolean}
             * @since 1.0.3
             */
            set: function (bold) {
                var ss = this.htmlElement.style;
                if (bold) {
                    ss.fontWeight = "bold";
                }
                else {
                    ss.fontWeight = "normal";
                }
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(InputText.prototype, "size", {
            get: function () {
                return this._size;
            },
            /**
             * @property size
             * @public
             * @since 2.0.0
             * @type {number}
             */
            set: function (value) {
                var s = this;
                if (s._size != value) {
                    s._size = value;
                    s.htmlElement.style.font = value + "px " + s._font;
                }
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(InputText.prototype, "font", {
            get: function () {
                return this._font;
            },
            /**
             * 设置文本颜色
             * @property font
             * @type {string}
             * @public
             * @since 1.0.3
             */
            set: function (value) {
                var s = this;
                if (value != s._font) {
                    s._font = value;
                    s.htmlElement.style.font = s._size + "px " + s._font;
                }
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(InputText.prototype, "italic", {
            get: function () {
                return this.htmlElement.style.fontStyle == "italic";
            },
            /**
             * 设置文本是否倾斜
             * @property italic
             * @public
             * @type {boolean}
             * @since 1.0.3
             */
            set: function (italic) {
                var s = this.htmlElement.style;
                if (italic) {
                    s.fontStyle = "italic";
                }
                else {
                    s.fontStyle = "normal";
                }
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(InputText.prototype, "textHeight", {
            get: function () {
                return parseInt(this.htmlElement.style.height);
            },
            /**
             * 文本的行高
             * @property textHeight
             * @public
             * @since 1.0.0
             * @type {number}
             * @default 0
             */
            set: function (value) {
                this.htmlElement.style.height = value + "px";
                if (this.inputType != 2) {
                    this.htmlElement.style.lineHeight = value + "px";
                }
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(InputText.prototype, "textWidth", {
            get: function () {
                return parseInt(this.htmlElement.style.width);
            },
            /**
             * 文本的宽
             * @property textWidth
             * @public
             * @since 1.0.0
             * @type {number}
             * @default 0
             */
            set: function (value) {
                this.htmlElement.style.width = value + "px";
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(InputText.prototype, "color", {
            get: function () {
                return this.htmlElement.style.color;
            },
            /**
             * 设置文本颜色
             * @property color
             * @type {string}
             * @public
             * @since 1.0.3
             */
            set: function (value) {
                var ss = this.htmlElement.style;
                ss.color = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(InputText.prototype, "border", {
            get: function () {
                return this.htmlElement.style.borderStyle != "none";
            },
            /**
             * 设置或获取是否有边框
             * @property property
             * @type {boolean}
             * @public
             * @since 1.0.3
             */
            set: function (show) {
                var s = this;
                if (show) {
                    s.htmlElement.style.borderStyle = "inset";
                    s.htmlElement.style.backgroundColor = "#fff";
                }
                else {
                    s.htmlElement.style.borderStyle = "none";
                    s.htmlElement.style.backgroundColor = "transparent";
                }
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(InputText.prototype, "text", {
            /**
             * 获取或设置输入文本的值
             * 之前的getText 和setText 已废弃
             * @property text
             * @public
             * @since 1.0.3
             * @type {string}
             */
            get: function () {
                var s = this;
                if (s.htmlElement) {
                    return s.htmlElement.value;
                }
            },
            set: function (value) {
                var s = this;
                if (s.htmlElement) {
                    s.htmlElement.value = value;
                }
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(InputText.prototype, "maxCharacters", {
            /**
             * 输入文本的最大输入字数
             * @public
             * @since 1.1.0
             * @property maxCharacters
             * @type {number}
             */
            get: function () {
                var l = this.htmlElement.getAttribute("maxlength");
                if (l == null) {
                    return 0;
                }
                else {
                    return l;
                }
            },
            set: function (value) {
                this.htmlElement.setAttribute("maxlength", value);
            },
            enumerable: true,
            configurable: true
        });
        InputText._inputTypeList = ["input", "password", "textarea"];
        return InputText;
    }(annie.FloatDisplay));
    annie.InputText = InputText;
})(annie || (annie = {}));

    
Top