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

📄 cookie.js

📁 这是YUI的源码及相关示例。里面有很多很炫的Javascript效果。
💻 JS
📖 第 1 页 / 共 2 页
字号:
        var lang = YAHOO.lang;            var hash /*:Variant*/ = this.getSubs(name);          if (hash !== null) {                        if (!lang.isString(subName) || subName === ""){                throw new TypeError("Cookie.getSub(): Subcookie name must be a non-empty string.");            }                        if (lang.isUndefined(hash[subName])){                return null;            }                                if (!lang.isFunction(converter)){                return hash[subName];            } else {                return converter(hash[subName]);            }        } else {            return null;        }        },        /**     * Returns an object containing name-value pairs stored in the cookie with the given name.     * @param {String} name The name of the cookie to retrieve.     * @return {Object} An object of name-value pairs if the cookie with the given name     *      exists, null if it does not.     * @method getHash     * @static     */    getSubs : function (name /*:String*/) /*:Object*/ {                //check cookie name        if (!YAHOO.lang.isString(name) || name === ""){            throw new TypeError("Cookie.getSubs(): Cookie name must be a non-empty string.");        }                var cookies = this._parseCookieString(document.cookie, false);        if (YAHOO.lang.isString(cookies[name])){            return this._parseCookieHash(cookies[name]);        }        return null;    },        /**     * Removes a cookie from the machine by setting its expiration date to     * sometime in the past.     * @param {String} name The name of the cookie to remove.     * @param {Object} options (Optional) An object containing one or more     *      cookie options: path (a string), domain (a string),      *      and secure (true/false). The expires option will be overwritten     *      by the method.     * @return {String} The created cookie string.     * @method remove     * @static     */    remove : function (name /*:String*/, options /*:Object*/) /*:String*/ {                //check cookie name        if (!YAHOO.lang.isString(name) || name === ""){            throw new TypeError("Cookie.remove(): Cookie name must be a non-empty string.");        }                //set options        options = options || {};        options.expires = new Date(0);                //set cookie        return this.set(name, "", options);    },    /**     * Removes a sub cookie with a given name.     * @param {String} name The name of the cookie in which the subcookie exists.     * @param {String} subName The name of the subcookie to remove.     * @param {Object} options (Optional) An object containing one or more     *      cookie options: path (a string), domain (a string), expires (a Date object),     *      and secure (true/false). This must be the same settings as the original     *      subcookie.     * @return {String} The created cookie string.     * @method removeSub     * @static     */    removeSub : function(name /*:String*/, subName /*:String*/, options /*:Object*/) /*:String*/ {            //check cookie name        if (!YAHOO.lang.isString(name) || name === ""){            throw new TypeError("Cookie.removeSub(): Cookie name must be a non-empty string.");        }                //check subcookie name        if (!YAHOO.lang.isString(subName) || subName === ""){            throw new TypeError("Cookie.removeSub(): Subcookie name must be a non-empty string.");        }                //get all subcookies for this cookie        var subs = this.getSubs(name);                //delete the indicated subcookie        if (YAHOO.lang.isObject(subs) && YAHOO.lang.hasOwnProperty(subs, subName)){            delete subs[subName];                        //reset the cookie            return this.setSubs(name, subs, options);        } else {            return "";        }            },    /**     * Sets a cookie with a given name and value.     * @param {String} name The name of the cookie to set.     * @param {Variant} value The value to set for the cookie.     * @param {Object} options (Optional) An object containing one or more     *      cookie options: path (a string), domain (a string), expires (a Date object),     *      and secure (true/false).     * @return {String} The created cookie string.     * @method set     * @static     */    set : function (name /*:String*/, value /*:Variant*/, options /*:Object*/) /*:String*/ {            var lang = YAHOO.lang;            if (!lang.isString(name)){            throw new TypeError("Cookie.set(): Cookie name must be a string.");        }                if (lang.isUndefined(value)){            throw new TypeError("Cookie.set(): Value cannot be undefined.");        }                    var text /*:String*/ = this._createCookieString(name, value, true, options);        document.cookie = text;        return text;    },            /**     * Sets a sub cookie with a given name to a particular value.     * @param {String} name The name of the cookie to set.     * @param {String} subName The name of the subcookie to set.     * @param {Variant} value The value to set.     * @param {Object} options (Optional) An object containing one or more     *      cookie options: path (a string), domain (a string), expires (a Date object),     *      and secure (true/false).     * @return {String} The created cookie string.     * @method setSub     * @static     */    setSub : function (name /*:String*/, subName /*:String*/, value /*:Variant*/, options /*:Object*/) /*:String*/ {                var lang = YAHOO.lang;        if (!lang.isString(name) || name === ""){            throw new TypeError("Cookie.setSub(): Cookie name must be a non-empty string.");        }        if (!lang.isString(subName) || subName === ""){            throw new TypeError("Cookie.setSub(): Subcookie name must be a non-empty string.");        }                if (lang.isUndefined(value)){            throw new TypeError("Cookie.setSub(): Subcookie value cannot be undefined.");        }        var hash /*:Object*/ = this.getSubs(name);                if (!lang.isObject(hash)){            hash = new Object();        }                hash[subName] = value;                        return this.setSubs(name, hash, options);            },        /**     * Sets a cookie with a given name to contain a hash of name-value pairs.     * @param {String} name The name of the cookie to set.     * @param {Object} value An object containing name-value pairs.     * @param {Object} options (Optional) An object containing one or more     *      cookie options: path (a string), domain (a string), expires (a Date object),     *      and secure (true/false).     * @return {String} The created cookie string.     * @method setSubs     * @static     */    setSubs : function (name /*:String*/, value /*:Object*/, options /*:Object*/) /*:String*/ {                var lang = YAHOO.lang;                if (!lang.isString(name)){            throw new TypeError("Cookie.setSubs(): Cookie name must be a string.");        }                if (!lang.isObject(value)){            throw new TypeError("Cookie.setSubs(): Cookie value must be an object.");        }            var text /*:String*/ = this._createCookieString(name, this._createCookieHashString(value), false, options);        document.cookie = text;        return text;            }    };YAHOO.register("cookie", YAHOO.util.Cookie, {version: "2.6.0", build: "1321"});

⌨️ 快捷键说明

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