⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 colorpicker-debug.js

📁 这是YUI的源码及相关示例。里面有很多很炫的Javascript效果。
💻 JS
📖 第 1 页 / 共 4 页
字号:
            case 4: // down arrow, decrement                this.set(prop, Math.max(this.get(prop)-inc, 0));                _updateFormFields.call(this);                //Event.stopEvent(e);                break;            default:        }    };    /**     * Handle keydown on the hex field     * @method _hexFieldKeypress     * @param e {Event} the keypress event     * @param el {HTMLElement} the field     * @param prop {string} the key to the linked property     * @private     */    var _hexFieldKeypress = function(e, el, prop) {        var command = _getCommand(e);        if (command === 6) { // return, update the value            _useFieldValue.apply(this, arguments);        }    };    /**      * Allows numbers and special chars, and by default allows a-f.       * Used for the hex field keypress handler.     * @method _hexOnly     * @param e {Event} the event     * @param numbersOnly omits a-f if set to true     * @private     * @return {boolean} false if we are canceling the event     */    var _hexOnly = function(e, numbersOnly) {        var command = _getCommand(e);        switch (command) {            case 6: // return            case 5: // special char            case 1: // number                break;            case 2: // hex char (a-f)                if (numbersOnly !== true) {                    break;                }                // fallthrough is intentional            default: // prevent alpha and punctuation                Event.stopEvent(e);                return false;        }    };    /**      * Allows numbers and special chars only.  Used for the     * rgb and hsv fields keypress handler.     * @method _numbersOnly     * @param e {Event} the event     * @private     * @return {boolean} false if we are canceling the event     */    var _numbersOnly = function(e) {        return _hexOnly(e, true);    };    /**     * Returns the element reference that is saved.  The id can be either     * the element id, or the key for this id in the "id" config attribute.     * For instance, the host element id can be obtained by passing its     * id (default: "yui_picker") or by its key "YUI_PICKER".     * @param id {string} the element id, or key      * @return {HTMLElement} a reference to the element     */    proto.getElement = function(id) {         return this.get(this.OPT.ELEMENTS)[this.get(this.OPT.IDS)[id]];     };    var _createElements = function() {        this.logger.log("Building markup");        var el, child, img, fld, i,             ids = this.get(this.OPT.IDS),            txt = this.get(this.OPT.TXT),            images = this.get(this.OPT.IMAGES),            Elem = function(type, o) {                var n = document.createElement(type);                if (o) {                    lang.augmentObject(n, o, true);                }                return n;            },            RGBElem = function(type, obj) {                var o = lang.merge({                        //type: "txt",                        autocomplete: "off",                        value: "0",                        size: 3,                        maxlength: 3                    }, obj);                o.name = o.id;                return new Elem(type, o);            };        var p = this.get("element");        // Picker slider (S and V) ---------------------------------------------        el = new Elem("div", {            id: ids[this.ID.PICKER_BG],            className: "yui-picker-bg",            tabIndex: -1,            hideFocus: true        });        child = new Elem("div", {            id: ids[this.ID.PICKER_THUMB],            className: "yui-picker-thumb"        });        img = new Elem("img", {            src: images.PICKER_THUMB        });        child.appendChild(img);        el.appendChild(child);        p.appendChild(el);                // Hue slider ---------------------------------------------        el = new Elem("div", {            id: ids[this.ID.HUE_BG],            className: "yui-picker-hue-bg",            tabIndex: -1,            hideFocus: true        });        child = new Elem("div", {            id: ids[this.ID.HUE_THUMB],            className: "yui-picker-hue-thumb"        });        img = new Elem("img", {            src: images.HUE_THUMB        });        child.appendChild(img);        el.appendChild(child);        p.appendChild(el);        // controls ---------------------------------------------        el = new Elem("div", {            id: ids[this.ID.CONTROLS],            className: "yui-picker-controls"        });        p.appendChild(el);        p = el;            // controls header            el = new Elem("div", {                className: "hd"            });            child = new Elem("a", {                id: ids[this.ID.CONTROLS_LABEL],                //className: "yui-picker-controls-label",                href: "#"            });            el.appendChild(child);            p.appendChild(el);            // bd            el = new Elem("div", {                className: "bd"            });            p.appendChild(el);            p = el;                // rgb                el = new Elem("ul", {                    id: ids[this.ID.RGB_CONTROLS],                    className: "yui-picker-rgb-controls"                });                child = new Elem("li");                child.appendChild(document.createTextNode(txt.R + " "));                fld = new RGBElem("input", {                    id: ids[this.ID.R],                    className: "yui-picker-r"                });                child.appendChild(fld);                el.appendChild(child);                child = new Elem("li");                child.appendChild(document.createTextNode(txt.G + " "));                fld = new RGBElem("input", {                    id: ids[this.ID.G],                    className: "yui-picker-g"                });                child.appendChild(fld);                el.appendChild(child);                child = new Elem("li");                child.appendChild(document.createTextNode(txt.B + " "));                fld = new RGBElem("input", {                    id: ids[this.ID.B],                    className: "yui-picker-b"                });                child.appendChild(fld);                el.appendChild(child);                p.appendChild(el);                // hsv                el = new Elem("ul", {                    id: ids[this.ID.HSV_CONTROLS],                    className: "yui-picker-hsv-controls"                });                child = new Elem("li");                child.appendChild(document.createTextNode(txt.H + " "));                fld = new RGBElem("input", {                    id: ids[this.ID.H],                    className: "yui-picker-h"                });                child.appendChild(fld);                child.appendChild(document.createTextNode(" " + txt.DEG));                el.appendChild(child);                child = new Elem("li");                child.appendChild(document.createTextNode(txt.S + " "));                fld = new RGBElem("input", {                    id: ids[this.ID.S],                    className: "yui-picker-s"                });                child.appendChild(fld);                child.appendChild(document.createTextNode(" " + txt.PERCENT));                el.appendChild(child);                child = new Elem("li");                child.appendChild(document.createTextNode(txt.V + " "));                fld = new RGBElem("input", {                    id: ids[this.ID.V],                    className: "yui-picker-v"                });                child.appendChild(fld);                child.appendChild(document.createTextNode(" " + txt.PERCENT));                el.appendChild(child);                p.appendChild(el);                // hex summary                el = new Elem("ul", {                    id: ids[this.ID.HEX_SUMMARY],                    className: "yui-picker-hex_summary"                });                child = new Elem("li", {                    id: ids[this.ID.R_HEX]                });                el.appendChild(child);                child = new Elem("li", {                    id: ids[this.ID.G_HEX]                });                el.appendChild(child);                child = new Elem("li", {                    id: ids[this.ID.B_HEX]                });                el.appendChild(child);                p.appendChild(el);                // hex field                el = new Elem("div", {                    id: ids[this.ID.HEX_CONTROLS],                    className: "yui-picker-hex-controls"                });                el.appendChild(document.createTextNode(txt.HEX + " "));                child = new RGBElem("input", {                    id: ids[this.ID.HEX],                    className: "yui-picker-hex",                    size: 6,                    maxlength: 6                });                el.appendChild(child);                p.appendChild(el);                p = this.get("element");                // swatch                el = new Elem("div", {                    id: ids[this.ID.SWATCH],                    className: "yui-picker-swatch"                });                p.appendChild(el);                // websafe swatch                el = new Elem("div", {                    id: ids[this.ID.WEBSAFE_SWATCH],                    className: "yui-picker-websafe-swatch"                });                p.appendChild(el);    };    var _attachRGBHSV = function(id, config) {        Event.on(this.getElement(id), "keydown", function(e, me) {                _rgbFieldKeypress.call(me, e, this, config);            }, this);        Event.on(this.getElement(id), "keypress", _numbersOnly, this);        Event.on(this.getElement(id), "blur", function(e, me) {                _useFieldValue.call(me, e, this, config);            }, this);    };    /**     * Updates the rgb attribute with the current state of the r,g,b     * fields.  This is invoked from change listeners on these     * attributes to facilitate updating these values from the     * individual form fields     * @method _updateRGB     * @private     */    var _updateRGB = function() {        var rgb = [this.get(this.OPT.RED),                    this.get(this.OPT.GREEN),                   this.get(this.OPT.BLUE)];        this.logger.log("RGB value set to " + rgb);        this.set(this.OPT.RGB, rgb);        _updateSliders.call(this);    };    /**     * Sets the initial state of the sliders     * @method initPicker     */    proto.initPicker = function () {        // bind all of our elements        var o=this.OPT,             ids = this.get(o.IDS),             els = this.get(o.ELEMENTS),                   i, el, id;        // Add the default value as a key for each element for easier lookup        for (i in this.ID) {            if (lang.hasOwnProperty(this.ID, i)) {                ids[this.ID[i]] = ids[i];            }        }        // Check for picker element, if not there, create all of them        el = Dom.get(ids[this.ID.PICKER_BG]);        if (!el) {            _createElements.call(this);        } else {            this.logger.log("Using pre-existing markup");        }        for (i in ids) {            if (lang.hasOwnProperty(ids, i)) {                // look for element                el = Dom.get(ids[i]);                // generate an id if the implementer passed in an element reference,                // and the element did not have an id already                id = Dom.generateId(el);                // update the id in case we generated the id                ids[i] = id; // key is WEBSAFE_SWATCH                ids[ids[i]] = id; // key is websafe_swatch                // store the dom ref                els[id] = el;            }        }        // set the initial visibility state of our controls            els = [o.SHOW_CONTROLS,                    o.SHOW_RGB_CONTROLS,                   o.SHOW_HSV_CONTROLS,                   o.SHOW_HEX_CONTROLS,                   o.SHOW_HEX_SUMMARY,                   o.SHOW_WEBSAFE                   ];        for (i=0; i<els.length; i=i+1) {            this.set(els[i], this.get(els[i]));        }        var s = this.get(o.PICKER_SIZE);        this.logger.log("picker size" + s);        this.hueSlider = Slider.getVertSlider(this.getElement(this.ID.HUE_BG),                                               this.getElement(this.ID.HUE_THUMB), 0, s);        this.hueSlider.subscribe("change", _onHueSliderChange, this, true);        this.pickerSlider = Slider.getSliderRegion(this.getElement(this.ID.PICKER_BG),                                                    this.getElement(this.ID.PICKER_THUMB), 0, s, 0, s);        this.pickerSlider.subscribe("change", _onPickerSliderChange, this, true);        // Set the animate state        this.set(o.ANIMATE,this.get(o.ANIMATE));        //_onHueSliderChange.call(this, 0);        Event.on(this.getElement(this.ID.WEBSAFE_SWATCH), "click", function(e) {               this.setValue(this.get(o.WEBSAFE));               //_updateSliders           }, this, true);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -