📄 sync.textcomponent.js
字号:
/** * Component rendering peer: TextComponent * * Note that this component has workarounds for issues with percentage-width text fields/areas in various browsers. * Percentage widths are reduced based on container size and border width to ensure overall width of component meets * user-set percent width specification. Workaround is also provided for Internet Explorer 6's growing textarea bug. */Echo.Sync.TextComponent = Core.extend(Echo.Render.ComponentSync, { $abstract: true, $static: { /** * Array containing properties that may be updated without full re-render. * @type Array */ _supportedPartialProperties: ["text", "editable"] }, $virtual: { /** * Invoked to ensure that input meets requirements of text field. Default implementation ensures input * does not exceed maximum length. */ sanitizeInput: function() { var maximumLength = this.component.render("maximumLength", -1); if (maximumLength >= 0) { if (this.input.value && this.input.value.length > maximumLength) { this.input.value = this.input.value.substring(0, maximumLength); } } } }, /** * The rendered "input" element (may be a textarea). * @type Element */ input: null, /** * Container element which wraps the input element. * This element is only rendered for text areas, to mitigate IE "growing" text area bug. * @type Element */ container: null, /** * Actual focus state of component, based on received DOM focus/blur events. * @type Boolean */ _focused: false, /** * The last processed value of the text field, i.e., the last value of the input field * that was stored in the component hierarchy. When input is provided while restrictions * are in place, this value is not updated. */ _lastProcessedValue: null, /** * Flag indicating whether width has been set as a percentage. * @type Boolean */ percentWidth: false, /** * Renders style information: colors, borders, font, insets, etc. * Sets percentWidth flag. */ _renderStyle: function() { if (this.component.isRenderEnabled()) { Echo.Sync.renderComponentDefaults(this.component, this.input); Echo.Sync.Border.render(this.component.render("border"), this.input); Echo.Sync.FillImage.render(this.component.render("backgroundImage"), this.input); } else { Echo.Sync.LayoutDirection.render(this.component.getLayoutDirection(), this.input); Echo.Sync.Color.render(Echo.Sync.getEffectProperty(this.component, "foreground", "disabledForeground", true), this.input, "color"); Echo.Sync.Color.render(Echo.Sync.getEffectProperty(this.component, "background", "disabledBackground", true), this.input, "backgroundColor"); Echo.Sync.Border.render(Echo.Sync.getEffectProperty(this.component, "border", "disabledBorder", true), this.input); Echo.Sync.Font.render(Echo.Sync.getEffectProperty(this.component, "font", "disabledFont", true), this.input); Echo.Sync.FillImage.render(Echo.Sync.getEffectProperty(this.component, "backgroundImage", "disabledBackgroundImage", true), this.input); } Echo.Sync.Alignment.render(this.component.render("alignment"), this.input, false, null); Echo.Sync.Insets.render(this.component.render("insets"), this.input, "padding"); var width = this.component.render("width"); this.percentWidth = Echo.Sync.Extent.isPercent(width); if (width) { if (this.percentWidth) { // Set width very small temporarily, renderDisplay will correct. this.input.style.width = "5px"; } else { this.input.style.width = Echo.Sync.Extent.toCssValue(width, true); } } var height = this.component.render("height"); if (height) { this.input.style.height = Echo.Sync.Extent.toCssValue(height, false); } var toolTipText = this.component.render("toolTipText"); if (toolTipText) { this.input.title = toolTipText; } }, /** * Registers event handlers on the text component. */ _addEventHandlers: function() { Core.Web.Event.add(this.input, "click", Core.method(this, this._processClick), false); Core.Web.Event.add(this.input, "focus", Core.method(this, this._processFocus), false); Core.Web.Event.add(this.input, "blur", Core.method(this, this._processBlur), false); Core.Web.Event.add(this.input, "keypress", Core.method(this, this._processKeyPress), false); Core.Web.Event.add(this.input, "keyup", Core.method(this, this._processKeyUp), false); }, /** * Reduces a percentage width by a number of pixels based on the container size. * * @param {Number} percentValue the percent span * @param {Number} reducePixels the number of pixels by which the percent span should be reduced * @param {Number} containerPixels the size of the container element */ _adjustPercentWidth: function(percentValue, reducePixels, containerPixels) { var value = (100 - Math.ceil(100 * reducePixels / containerPixels)) * percentValue / 100; return value > 0 ? value : 0; }, /** * Processes a focus blur event. */ _processBlur: function(e) { this._focused = false; return this._storeValue(); }, /** * Processes a mouse click event. Notifies application of focus. */ _processClick: function(e) { if (!this.client || !this.client.verifyInput(this.component)) { return true; } this.client.application.setFocusedComponent(this.component); }, /** * Processes a focus event. Notifies application of focus. */ _processFocus: function(e) { this._focused = true; if (!this.client || !this.client.verifyInput(this.component)) { return true; } this.client.application.setFocusedComponent(this.component); }, /** * Processes a key press event. Prevents input when client is not ready. */ _processKeyPress: function(e) { return this._storeValue(e); }, /** * Processes a key up event. */ _processKeyUp: function(e) { return this._storeValue(e); }, /** * Event listener to process input after client input restrictions have been cleared. */ _processRestrictionsClear: function() { if (!this.client) { // Component has been disposed, do nothing. return; } if (!this.client.verifyInput(this.component) || this.input.readOnly) { // Client is unwilling to accept input or component has been made read-only: // Reset value of text field to text property of component. this.input.value = this.component.get("text"); return; } // All-clear, store current text value. this.component.set("text", this.input.value); }, /** * Adds the input element to its parent in the DOM. * Wraps the element in a special container DIV if necessary to appease Internet Explorer's various text field/area bugs, * including percent-based text areas inducing scroll bars and the IE6 percentage width "growing" text area bug. * * @param parentElement the parent element */ renderAddToParent: function(parentElement) { if (Core.Web.Env.BROWSER_INTERNET_EXPLORER && this.percentWidth) { this.container = document.createElement("div"); this.container.appendChild(this.input); parentElement.appendChild(this.container); } else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -