📄 sync.button.js
字号:
_processInitEvent: function(e) { this._addEventListeners(); switch (e.type) { case "focus": this._processFocus(e); break; case "mouseover": if (this.component.render("rolloverEnabled")) { this._processRolloverEnter(e); } break; } }, /** Processes a key press event. Invokes <code>doAction()</code> in the case of enter being pressed. */ _processKeyPress: function(e) { if (!this.client || !this.client.verifyInput(this.component)) { return true; } if (e.keyCode == 13) { this.doAction(); return false; } else { return true; } }, /** Processes a mouse button press event, displaying the button's pressed appearance. */ _processPress: function(e) { if (!this.client || !this.client.verifyInput(this.component)) { return true; } Core.Web.DOM.preventEventDefault(e); this.setPressedState(true); }, /** Processes a mouse button release event on the button, displaying the button's normal appearance. */ _processRelease: function(e) { if (!this.client) { return true; } this.setPressedState(false); }, /** Processes a mouse roll over event, displaying the button's rollover appearance. */ _processRolloverEnter: function(e) { if (!this.client || !this.client.verifyInput(this.component) || Core.Web.dragInProgress) { return true; } this.client.application.addListener("focus", this._processRolloverExitRef); this.setRolloverState(true); }, /** Processes a mouse roll over exit event, displaying the button's normal appearance. */ _processRolloverExit: function(e) { if (!this.client) { return true; } if (this._processRolloverExitRef) { this.client.application.removeListener("focus", this._processRolloverExitRef); } this.setRolloverState(false); }, /** @see Echo.Render.ComponentSync#renderAdd */ renderAdd: function(update, parentElement) { this._enabled = this.component.isRenderEnabled(); this._div = Echo.Sync.Button._prototypeButton.cloneNode(false); this._div.id = this.component.renderId; Echo.Sync.LayoutDirection.render(this.component.getLayoutDirection(), this._div); if (this._enabled) { Echo.Sync.Color.renderFB(this.component, this._div); Echo.Sync.Border.render(this.component.render("border"), this._div); Echo.Sync.FillImage.render(this.component.render("backgroundImage"), this._div); } else { Echo.Sync.Color.render(Echo.Sync.getEffectProperty(this.component, "foreground", "disabledForeground", true), this._div, "color"); Echo.Sync.Color.render(Echo.Sync.getEffectProperty(this.component, "background", "disabledBackground", true), this._div, "backgroundColor"); Echo.Sync.Border.render(Echo.Sync.getEffectProperty(this.component, "border", "disabledBorder", true), this._div); Echo.Sync.FillImage.render(Echo.Sync.getEffectProperty(this.component, "backgroundImage", "disabledBackgroundImage", true), this._div); } Echo.Sync.Insets.render(this.component.render("insets"), this._div, "padding"); Echo.Sync.Alignment.render(this.component.render("alignment"), this._div, true, this.component); var toolTipText = this.component.render("toolTipText"); if (toolTipText) { this._div.title = toolTipText; } var width = this.component.render("width"); if (width) { this._div.style.width = Echo.Sync.Extent.toCssValue(width, true, true); } var height = this.component.render("height"); if (height) { this._div.style.height = Echo.Sync.Extent.toCssValue(height, false); this._div.style.overflow = "hidden"; } this.renderContent(); if (this._enabled) { // Add event listeners for focus and mouse rollover. When invoked, these listeners will register the full gamut // of button event listeners. There may be a large number of such listeners depending on how many effects // are enabled, and as such we do this lazily for performance reasons. Core.Web.Event.add(this._div, "focus", this._processInitEventRef, false); Core.Web.Event.add(this._div, "mouseover", this._processInitEventRef, false); } parentElement.appendChild(this._div); }, /** * Renders the button text. Configures text alignment, and font. * * @param element the element which should contain the text. * @param text the text to render */ _renderButtonText: function(element, text) { this._textElement = element; var textAlignment = this.component.render("textAlignment"); if (textAlignment) { Echo.Sync.Alignment.render(textAlignment, element, true, this.component); } if (this._enabled) { Echo.Sync.Font.render(this.component.render("font"), this._textElement); } else { Echo.Sync.Font.render(Echo.Sync.getEffectProperty(this.component, "font", "disabledFont", true), this._textElement); } element.appendChild(document.createTextNode(text)); if (!this.component.render("lineWrap", true)) { element.style.whiteSpace = "nowrap"; } }, /** * Renders the button icon. * * @param elemnt the element which should contain the icon. * @param icon the icon property to render */ _renderButtonIcon: function(element, icon) { var alignment = this.component.render("alignment"); if (alignment) { Echo.Sync.Alignment.render(alignment, element, true, this.component); } var imgElement = document.createElement("img"); Echo.Sync.ImageReference.renderImg(icon, imgElement); element.appendChild(imgElement); return imgElement; }, /** @see Echo.Render.ComponentSync#renderDispose */ renderDispose: function(update) { if (this._processRolloverExitRef) { this.client.application.removeListener("focus", this._processRolloverExitRef); } Core.Web.Event.removeAll(this._div); this._focused = false; this._div = null; this._textElement = null; this._iconImg = null; }, /** @see Echo.Render.ComponentSync#renderFocus */ renderFocus: function() { if (this._focused) { return; } this._renderFocusStyle(true); Core.Web.DOM.focusElement(this._div); }, /** @see Echo.Render.ComponentSync#renderUpdate */ renderUpdate: function(update) { var element = this._div; var containerElement = element.parentNode; this.renderDispose(update); containerElement.removeChild(element); this.renderAdd(update, containerElement); return false; // Child elements not supported: safe to return false. }, /** * Enables/disables focused appearance of button. * * @param {Boolean} focusState the new focus state. */ _renderFocusStyle: function(focusState) { if (this._focused == focusState) { return; } this._focused = focusState; var background; if (!this.component.render("focusedEnabled")) { // Render default focus aesthetic. background = this.component.render("background"); if (background != null) { var newBackground = focusState ? Echo.Sync.Color.adjust(background, 0x20, 0x20, 0x20) : background; Echo.Sync.Color.render(newBackground, this._div, "backgroundColor"); } return; } else { var foreground = Echo.Sync.getEffectProperty(this.component, "foreground", "focusedForeground", focusState); background = Echo.Sync.getEffectProperty(this.component, "background", "focusedBackground", focusState); var backgroundImage = Echo.Sync.getEffectProperty( this.component, "backgroundImage", "focusedBackgroundImage", focusState); var font = Echo.Sync.getEffectProperty(this.component, "font", "focusedFont", focusState); var border = Echo.Sync.getEffectProperty(this.component, "border", "focusedBorder", focusState); Echo.Sync.Color.renderClear(foreground, this._div, "color"); Echo.Sync.Color.renderClear(background, this._div, "backgroundColor"); Echo.Sync.FillImage.renderClear(backgroundImage, this._div, "backgroundColor"); Echo.Sync.Border.renderClear(border, this._div); if (this._textElement) { Echo.Sync.Font.renderClear(font, this._textElement); } if (this._iconImg) { var iconUrl = Echo.Sync.ImageReference.getUrl( Echo.Sync.getEffectProperty(this.component, "icon", "focusedIcon", focusState)); if (iconUrl != this._iconImg.src) { this._iconImg.src = iconUrl; } } } }});
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -