| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 | <!DOCTYPE html><html><head>  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  <title>The source code</title>  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>  <style type="text/css">    .highlight { display: block; background-color: #ddd; }  </style>  <script type="text/javascript">    function highlight() {      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";    }  </script></head><body onload="prettyPrint(); highlight();">  <pre class="prettyprint lang-js"><span id='Ext-util-Cookies'>/**</span> * Utility class for setting/reading values from browser cookies. * Values can be written using the {@link #set} method. * Values can be read using the {@link #get} method. * A cookie can be invalidated on the client machine using the {@link #clear} method. */Ext.define('Ext.util.Cookies', {    singleton: true,    <span id='Ext-util-Cookies-method-set'>    /**</span>     * Creates a cookie with the specified name and value. Additional settings for the cookie may be optionally specified     * (for example: expiration, access restriction, SSL).     * @param {String} name The name of the cookie to set.     * @param {Object} value The value to set for the cookie.     * @param {Object} [expires] Specify an expiration date the cookie is to persist until. Note that the specified Date     * object will be converted to Greenwich Mean Time (GMT).     * @param {String} [path] Setting a path on the cookie restricts access to pages that match that path. Defaults to all     * pages ('/').     * @param {String} [domain] Setting a domain restricts access to pages on a given domain (typically used to allow     * cookie access across subdomains). For example, "sencha.com" will create a cookie that can be accessed from any     * subdomain of sencha.com, including www.sencha.com, support.sencha.com, etc.     * @param {Boolean} [secure] Specify true to indicate that the cookie should only be accessible via SSL on a page     * using the HTTPS protocol. Defaults to false. Note that this will only work if the page calling this code uses the     * HTTPS protocol, otherwise the cookie will be created with default options.     */    set : function(name, value){        var argv = arguments,            argc = arguments.length,            expires = (argc > 2) ? argv[2] : null,            path = (argc > 3) ? argv[3] : '/',            domain = (argc > 4) ? argv[4] : null,            secure = (argc > 5) ? argv[5] : false;                    document.cookie = name + "=" + escape(value) + ((expires === null) ? "" : ("; expires=" + expires.toGMTString())) + ((path === null) ? "" : ("; path=" + path)) + ((domain === null) ? "" : ("; domain=" + domain)) + ((secure === true) ? "; secure" : "");    },<span id='Ext-util-Cookies-method-get'>    /**</span>     * Retrieves cookies that are accessible by the current page. If a cookie does not exist, `get()` returns null. The     * following example retrieves the cookie called "valid" and stores the String value in the variable validStatus.     *     *     var validStatus = Ext.util.Cookies.get("valid");     *     * @param {String} name The name of the cookie to get     * @return {Object} Returns the cookie value for the specified name;     * null if the cookie name does not exist.     */    get : function(name){        var arg = name + "=",            alen = arg.length,            clen = document.cookie.length,            i = 0,            j = 0;                    while(i < clen){            j = i + alen;            if(document.cookie.substring(i, j) == arg){                return this.getCookieVal(j);            }            i = document.cookie.indexOf(" ", i) + 1;            if(i === 0){                break;            }        }        return null;    },<span id='Ext-util-Cookies-method-clear'>    /**</span>     * Removes a cookie with the provided name from the browser     * if found by setting its expiration date to sometime in the past.     * @param {String} name The name of the cookie to remove     * @param {String} [path] The path for the cookie.     * This must be included if you included a path while setting the cookie.     */    clear : function(name, path){        if(this.get(name)){            path = path || '/';            document.cookie = name + '=' + '; expires=Thu, 01-Jan-70 00:00:01 GMT; path=' + path;        }    },    <span id='Ext-util-Cookies-method-getCookieVal'>    /**</span>     * @private     */    getCookieVal : function(offset){        var endstr = document.cookie.indexOf(";", offset);        if(endstr == -1){            endstr = document.cookie.length;        }        return unescape(document.cookie.substring(offset, endstr));    }});</pre></body></html>
 |