📄 sync.js
字号:
while (true) { var side = this.getPixelSize(border[sideName]); if (side == null) { switch (sideName) { case "left": // If left side specified but value null, try again with right. sideName = "right"; continue; case "right": case "bottom": // If bottom or right side specified, try again with top. sideName = "top"; continue; } } return side; } } }};/** * Provides tools for rendering color properties. * @class */Echo.Sync.Color = { /** * Adjusts the value of the color's RGB values by the * specified amounts, returning a new Color. * The original color is unchanged. * * @param color the color to adjust (a 24 bit hex value, e.g., #1a2b3c) * @param r the amount to adjust the red value of the color (-255 to 255) * @param g the amount to adjust the green value of the color (-255 to 255) * @param b the amount to adjust the blue value of the color (-255 to 255) * @return the adjusted color (a 24 bit hex value) */ adjust: function(value, r, g, b) { var colorInt = parseInt(value.substring(1), 16); var red = Math.floor(colorInt / 0x10000) + r; var green = Math.floor(colorInt / 0x100) % 0x100 + g; var blue = colorInt % 0x100 + b; return this.toHex(red, green, blue); }, /** * Blends two colors together. * * @param {#Color} value1 the first color * @param {#Color} value2 the second color * @param {Number} ratio the blend ratio, where 0 represents the first color, 1 the second color, and 0.5 an equal blend * between the first and second colors * @return the blended color * @type #Color */ blend: function(value1, value2, ratio) { ratio = ratio < 0 ? 0 : (ratio > 1 ? 1 : ratio); var colorInt1 = parseInt(value1.substring(1), 16); var colorInt2 = parseInt(value2.substring(1), 16); var red = Math.round(Math.floor(colorInt1 / 0x10000) * (1 - ratio) + Math.floor(colorInt2 / 0x10000) * ratio); var green = Math.round(Math.floor(colorInt1 / 0x100) % 0x100 * (1 - ratio) + Math.floor(colorInt2 / 0x100) % 0x100 * ratio); var blue = Math.round((colorInt1 % 0x100) * (1 - ratio) + (colorInt2 % 0x100) * ratio); return this.toHex(red, green, blue); }, /** * Renders a color to an element. * * @param {#Color} color the color * @param {#Element} element the target element * @param {String} styleAttribute the name of the style attribute, e.g., "color", "backgroundColor" */ render: function(color, element, styleAttribute) { if (color) { element.style[styleAttribute] = color; } }, /** * Renders a color to an element, clearing any existing value. * * @param {#Color} color the color * @param {#Element} element the target element * @param {String} styleAttribute the name of the style attribute, e.g., "color", "backgroundColor" */ renderClear: function(color, element, styleAttribute) { element.style[styleAttribute] = color ? color : ""; }, /** * Renders the "foreground" and "background" color properties of a component to an element's "color" and * "backgroundColor" properties. * * @param {Echo.Component} component the component * @param {Element} the target element */ renderFB: function(component, element) { var color; if ((color = component.render("foreground"))) { element.style.color = color; } if ((color = component.render("background"))) { element.style.backgroundColor = color; } }, /** * Converts red/green/blue integer values to a 6 digit hexadecimal string, preceded by a sharp, e.g. #1a2b3c. * * @param {Number} red the red value, 0-255 * @param {Number} green the green value, 0-255 * @param {Number} blue the blue value, 0-255 * @return the hex string * @type String */ toHex: function(red, green, blue) { if (red < 0) { red = 0; } else if (red > 255) { red = 255; } if (green < 0) { green = 0; } else if (green > 255) { green = 255; } if (blue < 0) { blue = 0; } else if (blue > 255) { blue = 255; } return "#" + (red < 16 ? "0" : "") + red.toString(16) + (green < 16 ? "0" : "") + green.toString(16) + (blue < 16 ? "0" : "") + blue.toString(16); }};/** * Provides tools for rendering extent (dimension) properties. * @class */Echo.Sync.Extent = { /** * Regular expression to parse an extent value, e.g., "12px" into its value and unit components. * @type RegExp */ _PARSER: /^(-?\d+(?:\.\d+)?)(.+)?$/, /** * Regular expression to determine if an extent value is already formatted to pixel units. * @type RegExp */ _FORMATTED_INT_PIXEL_TEST: /^(-?\d+px *)$/, /** * Regular expression to determine if an extent value is already formatted to pixel units. * @type RegExp */ _FORMATTED_DECIMAL_PIXEL_TEST: /^(-?\d+(.\d+)?px *)$/, /** * Determines if an extent has percent units. * * @param {#Extent} extent the Extent * @return true if the extent has percent units * @type Boolean */ isPercent: function(extent) { if (extent == null || typeof(extent) == "number") { return false; } else { var parts = this._PARSER.exec(extent); if (!parts) { return false; } return parts[2] == "%"; } }, /** * Renders an extent value to an element. * * @param {#Extent} extent the Extent * @param {Element} element the target element * @param {String} styleAttribute the style attribute name, e.g., "padding-left", or "width" * @param {Boolean} horizontal flag indicating whether the value is being rendered horizontally * @param {Boolean} allowPercent flag indicating whether percent values should be rendered */ render: function(extent, element, styleAttribute, horizontal, allowPercent) { var cssValue = Echo.Sync.Extent.toCssValue(extent, horizontal, allowPercent); if (cssValue !== "") { element.style[styleAttribute] = cssValue; } }, /** * Returns a CSS representation of an extent value. * * @param {#Extent} extent the Extent * @param {Boolean} horizontal flag indicating whether the value is being rendered horizontally * @param {Boolean} allowPercent flag indicating whether percent values should be rendered * @return the rendered CSS value or the empty string ("") if no value could be determined (null will never be returned) * @type String */ toCssValue: function(extent, horizontal, allowPercent) { switch(typeof(extent)) { case "number": return Math.round(extent) + "px"; case "string": if (this._FORMATTED_INT_PIXEL_TEST.test(extent)) { return extent; } else if (this._FORMATTED_DECIMAL_PIXEL_TEST.test(extent)) { return Math.round(parseFloat(extent)) + "px"; } else { if (allowPercent && this.isPercent(extent)) { return extent; } else { var pixels = this.toPixels(extent, horizontal); return pixels == null ? "" : this.toPixels(extent, horizontal) + "px"; } } break; } return ""; }, /** * Converts an extent value to pixels. * * @param {#Extent} extent the Extent * @param {Boolean} horizontal flag indicating whether the value is being rendered horizontally * @type Number */ toPixels: function(extent, horizontal) { if (extent == null) { return 0; } else if (typeof(extent) == "number") { return Math.round(extent); } else { return Math.round(Core.Web.Measure.extentToPixels(extent, horizontal)); } }};/** * Provides tools for rendering fill image (background image) properties. * @class */Echo.Sync.FillImage = { /** Mapping between repeat property values and rendered CSS repeat values. */ _REPEAT_VALUES: { "0": "no-repeat", "x": "repeat-x", "y": "repeat-y", "xy": "repeat", "no-repeat": "no-repeat", "repeat-x": "repeat-x", "repeat-y": "repeat-y", "repeat": "repeat" }, /** * Flag indicating that the Internet Explorer 6-specific PNG alpha filter should be used to render PNG alpha (transparency). * @type Number */ FLAG_ENABLE_IE_PNG_ALPHA_FILTER: 0x1, /** * Determines the background-position CSS attribute of a FillImage. * * @param {#FillImage} fillImage the FillImage * @return the appropriate CSS background-position attribute, or null if it is not specified * @type String */ getPosition: function(fillImage) { if (fillImage.x || fillImage.y) { var x, y; if (Echo.Sync.Extent.isPercent(fillImage.x)) { x = fillImage.x; } else { x = Echo.Sync.Extent.toPixels(fillImage.x, true) + "px"; } if (Echo.Sync.Extent.isPercent(fillImage.y)) { y = fillImage.y; } else { y = Echo.Sync.Extent.toPixels(fillImage.y, false) + "px"; } return x + " " + y; } else { return null; } }, /** * Determines the background-repeat CSS attribute of a FillImage. * * @param {#FillImage} fillImage the FillImage * @return the appropriate CSS background-repeat attribute, or null if it is not specified/invalid * @type String */ getRepeat: function(fillImage) { if (this._REPEAT_VALUES[fillImage.repeat]) { return this._REPEAT_VALUES[fillImage.repeat]; } else { return null; } }, /** * Returns the URL of a FillImage. * * @param {#FillImage} fillImage the FillImage * @return the URL * @type String */ getUrl: function(fillImage) { if (fillImage == null) { return null; } return typeof(fillImage) == "object" ? fillImage.url : fillImage; }, /** * Renders a FillImage to an element. * * @param {#FillImage} fillImage the FillImage (may be null) * @param {Element} element the target element * @param {Number} flags (optional) the rendering flags, one or more of the following values: * <ul> * <li><code>FLAG_ENABLE_IE_PNG_ALPHA_FILTER</code></li> * <ul> */ render: function(fillImage, element, flags) { if (fillImage == null) { // No image specified, do nothing. return; } var isObject = typeof(fillImage) == "object"; var url = isObject ? fillImage.url : fillImage; if (Core.Web.Env.PROPRIETARY_IE_PNG_ALPHA_FILTER_REQUIRED && flags && (flags & this.FLAG_ENABLE_IE_PNG_ALPHA_FILTER)) { // IE6 PNG workaround required. element.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + url + "', sizingMethod='scale')"; } else { // IE6 PNG workaround not required.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -