📄 colorpicker-debug.js
字号:
Event.on(this.getElement(this.ID.CONTROLS_LABEL), "click", function(e) { this.set(o.SHOW_CONTROLS, !this.get(o.SHOW_CONTROLS)); Event.preventDefault(e); }, this, true); _attachRGBHSV.call(this, this.ID.R, this.OPT.RED); _attachRGBHSV.call(this, this.ID.G, this.OPT.GREEN); _attachRGBHSV.call(this, this.ID.B, this.OPT.BLUE); _attachRGBHSV.call(this, this.ID.H, this.OPT.HUE); _attachRGBHSV.call(this, this.ID.S, this.OPT.SATURATION); _attachRGBHSV.call(this, this.ID.V, this.OPT.VALUE); Event.on(this.getElement(this.ID.HEX), "keydown", function(e, me) { _hexFieldKeypress.call(me, e, this, me.OPT.HEX); }, this); Event.on(this.getElement(this.ID.HEX), "keypress", _hexOnly, this); Event.on(this.getElement(this.ID.HEX), "blur", function(e, me) { _useFieldValue.call(me, e, this, me.OPT.HEX); }, this); _updateRGB.call(this); }; /** * Updates the RGB values from the current state of the HSV * values. Executed when the one of the HSV form fields are * updated * _updateRGBFromHSV * @private */ var _updateRGBFromHSV = function() { var hsv = [this.get(this.OPT.HUE), this.get(this.OPT.SATURATION)/100, this.get(this.OPT.VALUE)/100]; var rgb = Color.hsv2rgb(hsv); this.logger.log("HSV converted to RGB " + hsv + " : " + rgb); this.set(this.OPT.RGB, rgb); _updateSliders.call(this); }; /** * Parses the hex string to normalize shorthand values, converts * the hex value to rgb and updates the rgb attribute (which * updates the state for all of the other values) * method _updateHex * @private */ var _updateHex = function() { var hex = this.get(this.OPT.HEX), l=hex.length; // support #369 -> #336699 shorthand if (l === 3) { var c = hex.split(""), i; for (i=0; i<l; i=i+1) { c[i] = c[i] + c[i]; } hex = c.join(""); } if (hex.length !== 6) { this.logger.log(this.get(this.TXT.ILLEGAL_HEX), "error"); return false; } var rgb = Color.hex2rgb(hex); this.logger.log(sub("Hex value set to {hex} ({rgb})", { hex: hex, rgb: rgb })); this.setValue(rgb); //_updateSliders.call(this); }; /** * Sets up the config attributes and the change listeners for this * properties * @method initAttributes * @param attr An object containing default attribute values */ proto.initAttributes = function(attr) { attr = attr || {}; YAHOO.widget.ColorPicker.superclass.initAttributes.call(this, attr); /** * The size of the picker. Trying to change this is not recommended. * @attribute pickersize * @default 180 * @type int */ this.setAttributeConfig(this.OPT.PICKER_SIZE, { value: attr.size || this.DEFAULT.PICKER_SIZE }); /** * The current hue value 0-360 * @attribute hue * @type int */ this.setAttributeConfig(this.OPT.HUE, { value: attr.hue || 0, validator: lang.isNumber }); /** * The current saturation value 0-100 * @attribute saturation * @type int */ this.setAttributeConfig(this.OPT.SATURATION, { value: attr.saturation || 0, validator: lang.isNumber }); /** * The current value/brightness value 0-100 * @attribute value * @type int */ this.setAttributeConfig(this.OPT.VALUE, { value: lang.isNumber(attr.value) ? attr.value : 100, validator: lang.isNumber }); /** * The current red value 0-255 * @attribute red * @type int */ this.setAttributeConfig(this.OPT.RED, { value: lang.isNumber(attr.red) ? attr.red : 255, validator: lang.isNumber }); /** * The current green value 0-255 * @attribute green * @type int */ this.setAttributeConfig(this.OPT.GREEN, { value: lang.isNumber(attr.green) ? attr.green : 255, validator: lang.isNumber }); /** * The current blue value 0-255 * @attribute blue * @type int */ this.setAttributeConfig(this.OPT.BLUE, { value: lang.isNumber(attr.blue) ? attr.blue : 255, validator: lang.isNumber }); /** * The current hex value #000000-#FFFFFF, without the # * @attribute hex * @type string */ this.setAttributeConfig(this.OPT.HEX, { value: attr.hex || "FFFFFF", validator: lang.isString }); /** * The current rgb value. Updates the state of all of the * other value fields. Read-only: use setValue to set the * controls rgb value. * @attribute hex * @type [int, int, int] * @readonly */ this.setAttributeConfig(this.OPT.RGB, { value: attr.rgb || [255,255,255], method: function(rgb) { this.set(this.OPT.RED, rgb[0], true); this.set(this.OPT.GREEN, rgb[1], true); this.set(this.OPT.BLUE, rgb[2], true); var websafe = Color.websafe(rgb); this.set(this.OPT.WEBSAFE, websafe, true); var hex = Color.rgb2hex(rgb); this.set(this.OPT.HEX, hex, true); var hsv = Color.rgb2hsv(rgb); this.logger.log(sub("RGB value set to {rgb} (hsv: {hsv})", { "hsv": hsv, "rgb": rgb })); this.set(this.OPT.HUE, hsv[0], true); this.set(this.OPT.SATURATION, Math.round(hsv[1]*100), true); this.set(this.OPT.VALUE, Math.round(hsv[2]*100), true); }, readonly: true }); /** * If the color picker will live inside of a container object, * set, provide a reference to it so the control can use the * container's events. * @attribute container * @type YAHOO.widget.Panel */ this.setAttributeConfig(this.OPT.CONTAINER, { value: null, method: function(container) { if (container) { // Position can get out of sync when the // control is manipulated while display is // none. Resetting the slider constraints // when it is visible gets the state back in // order. container.showEvent.subscribe(function() { // this.pickerSlider.thumb.resetConstraints(); // this.hueSlider.thumb.resetConstraints(); this.pickerSlider.focus(); }, this, true); } } }); /** * The closest current websafe value * @attribute websafe * @type int */ this.setAttributeConfig(this.OPT.WEBSAFE, { value: attr.websafe || [255,255,255] }); var ids = attr.ids || lang.merge({}, this.ID); if (!attr.ids && _pickercount > 1) { for (var i in ids) { if (lang.hasOwnProperty(ids, i)) { ids[i] = ids[i] + _pickercount; } } } /** * A list of element ids and/or element references used by the * control. The default is the this.ID list, and can be customized * by passing a list in the contructor * @attribute ids * @type {referenceid: realid} * @writeonce */ this.setAttributeConfig(this.OPT.IDS, { value: ids, writeonce: true }); /** * A list of txt strings for internationalization. Default * is this.TXT * @attribute txt * @type {key: txt} * @writeonce */ this.setAttributeConfig(this.OPT.TXT, { value: attr.txt || this.TXT, writeonce: true }); /** * The img src default list * is this.IMAGES * @attribute images * @type {key: image} * @writeonce */ this.setAttributeConfig(this.OPT.IMAGES, { value: attr.images || this.IMAGE, writeonce: true }); /** * The element refs used by this control. Set at initialization * @attribute elements * @type {id: HTMLElement} * @readonly */ this.setAttributeConfig(this.OPT.ELEMENTS, { value: {}, readonly: true }); /** * Returns the cached element reference. If the id is not a string, it * is assumed that it is an element and this is returned. * @param id {string|HTMLElement} the element key, id, or ref * @param on {boolean} hide or show. If true, show * @private */ var _hideShowEl = function(id, on) { var el = (lang.isString(id) ? this.getElement(id) : id); //Dom.setStyle(id, "visibility", (on) ? "" : "hidden"); Dom.setStyle(el, "display", (on) ? "" : "none"); }; /** * Hide/show the entire set of controls * @attribute showcontrols * @type boolean * @default true */ this.setAttributeConfig(this.OPT.SHOW_CONTROLS, { value: lang.isBoolean(attr.showcontrols) ? attr.showcontrols : true, method: function(on) { var el = Dom.getElementsByClassName("bd", "div", this.getElement(this.ID.CONTROLS))[0]; _hideShowEl.call(this, el, on); this.getElement(this.ID.CONTROLS_LABEL).innerHTML = (on) ? this.get(this.OPT.TXT).HIDE_CONTROLS : this.get(this.OPT.TXT).SHOW_CONTROLS; } }); /** * Hide/show the rgb controls * @attribute showrgbcontrols * @type boolean * @default true */ this.setAttributeConfig(this.OPT.SHOW_RGB_CONTROLS, { value: lang.isBoolean(attr.showrgbcontrols) ? attr.showrgbcontrols : true, method: function(on) { //Dom.setStyle(this.getElement(this.ID.RBG_CONTROLS), "visibility", (on) ? "" : "hidden"); _hideShowEl.call(this, this.ID.RGB_CONTROLS, on); } }); /** * Hide/show the hsv controls * @attribute showhsvcontrols * @type boolean * @default false */ this.setAttributeConfig(this.OPT.SHOW_HSV_CONTROLS, { value: lang.isBoolean(attr.showhsvcontrols) ? attr.showhsvcontrols : false, method: function(on) { //Dom.setStyle(this.getElement(this.ID.HSV_CONTROLS), "visibility", (on) ? "" : "hidden"); _hideShowEl.call(this, this.ID.HSV_CONTROLS, on); // can't show both the hsv controls and the rbg hex summary if (on && this.get(this.OPT.SHOW_HEX_SUMMARY)) { this.set(this.OPT.SHOW_HEX_SUMMARY, false); } } }); /** * Hide/show the hex controls * @attribute showhexcontrols * @type boolean * @default true */ this.setAttributeConfig(this.OPT.SHOW_HEX_CONTROLS, { value: lang.isBoolean(attr.showhexcontrols) ? attr.showhexcontrols : false, method: function(on) { _hideShowEl.call(this, this.ID.HEX_CONTROLS, on); } }); /** * Hide/show the websafe swatch * @attribute showwebsafe * @type boolean * @default true */ this.setAttributeConfig(this.OPT.SHOW_WEBSAFE, { value: lang.isBoolean(attr.showwebsafe) ? attr.showwebsafe : true, method: function(on) { _hideShowEl.call(this, this.ID.WEBSAFE_SWATCH, on); } }); /** * Hide/show the hex summary * @attribute showhexsummary * @type boolean * @default true */ this.setAttributeConfig(this.OPT.SHOW_HEX_SUMMARY, { value: lang.isBoolean(attr.showhexsummary) ? attr.showhexsummary : true, method: function(on) { _hideShowEl.call(this, this.ID.HEX_SUMMARY, on); // can't show both the hsv controls and the rbg hex summary if (on && this.get(this.OPT.SHOW_HSV_CONTROLS)) { this.set(this.OPT.SHOW_HSV_CONTROLS, false); } } }); this.setAttributeConfig(this.OPT.ANIMATE, { value: lang.isBoolean(attr.animate) ? attr.animate : true, method: function(on) { this.pickerSlider.animate = on; this.hueSlider.animate = on; } }); this.on(this.OPT.HUE + "Change", _updateRGBFromHSV, this, true); this.on(this.OPT.SATURATION + "Change", _updateRGBFromHSV, this, true); this.on(this.OPT.VALUE + "Change", _updatePickerSlider, this, true); this.on(this.OPT.RED + "Change", _updateRGB, this, true); this.on(this.OPT.GREEN + "Change", _updateRGB, this, true); this.on(this.OPT.BLUE + "Change", _updateRGB, this, true); this.on(this.OPT.HEX + "Change", _updateHex, this, true); this.initPicker(); };})();YAHOO.register("colorpicker", YAHOO.widget.ColorPicker, {version: "2.6.0", build: "1321"});
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -