Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / docs / source / Cookies.html
index f9ee60c..6d0e4a0 100644 (file)
@@ -1,25 +1,19 @@
-<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>
-</head>
-<body  onload="prettyPrint();">
-    <pre class="prettyprint lang-js">/*!
- * Ext JS Library 3.3.1
- * Copyright(c) 2006-2010 Sencha Inc.
- * licensing@sencha.com
- * http://www.sencha.com/license
- */
-<div id="cls-Ext.util.Cookies"></div>/**
- * @class Ext.util.Cookies
- * Utility class for managing and interacting with cookies.
+<!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-util.Cookies'>/**
+</span> * @class Ext.util.Cookies
+
+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.
+
+ * @markdown
  * @singleton
  */
-Ext.util.Cookies = {
-    <div id="method-Ext.util.Cookies-set"></div>/**
-     * Create a cookie with the specified name and value. Additional settings
+Ext.define('Ext.util.Cookies', {
+    singleton: true,
+    
+<span id='Ext-util.Cookies-method-set'>    /**
+</span>     * Create 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. 
@@ -28,52 +22,54 @@ Ext.util.Cookies = {
      * cookie is to persist until.  Note that the specified Date object will
      * be converted to Greenwich Mean Time (GMT). 
      * @param {String} path (Optional) Setting a path on the cookie restricts
-     * access to pages that match that path. Defaults to all pages (<tt>'/'</tt>). 
+     * access to pages that match that path. Defaults to all pages (&lt;tt&gt;'/'&lt;/tt&gt;). 
      * @param {String} domain (Optional) Setting a domain restricts access to
      * pages on a given domain (typically used to allow cookie access across
-     * subdomains). For example, "extjs.com" will create a cookie that can be
-     * accessed from any subdomain of extjs.com, including www.extjs.com,
-     * support.extjs.com, etc.
+     * subdomains). For example, &quot;sencha.com&quot; 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 (Optional) Specify true to indicate that the cookie
      * should only be accessible via SSL on a page using the HTTPS protocol.
-     * Defaults to <tt>false</tt>. Note that this will only work if the page
+     * Defaults to &lt;tt&gt;false&lt;/tt&gt;. 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;
-        var argc = arguments.length;
-        var expires = (argc > 2) ? argv[2] : null;
-        var path = (argc > 3) ? argv[3] : '/';
-        var domain = (argc > 4) ? argv[4] : null;
-        var 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" : "");
+        var argv = arguments,
+            argc = arguments.length,
+            expires = (argc &gt; 2) ? argv[2] : null,
+            path = (argc &gt; 3) ? argv[3] : '/',
+            domain = (argc &gt; 4) ? argv[4] : null,
+            secure = (argc &gt; 5) ? argv[5] : false;
+            
+        document.cookie = name + &quot;=&quot; + escape(value) + ((expires === null) ? &quot;&quot; : (&quot;; expires=&quot; + expires.toGMTString())) + ((path === null) ? &quot;&quot; : (&quot;; path=&quot; + path)) + ((domain === null) ? &quot;&quot; : (&quot;; domain=&quot; + domain)) + ((secure === true) ? &quot;; secure&quot; : &quot;&quot;);
     },
 
-    <div id="method-Ext.util.Cookies-get"></div>/**
-     * Retrieves cookies that are accessible by the current page. If a cookie
-     * does not exist, <code>get()</code> returns <tt>null</tt>.  The following
-     * example retrieves the cookie called "valid" and stores the String value
-     * in the variable <tt>validStatus</tt>.
-     * <pre><code>
-     * var validStatus = Ext.util.Cookies.get("valid");
-     * </code></pre>
+<span id='Ext-util.Cookies-method-get'>    /**
+</span>     * Retrieves cookies that are accessible by the current page. If a cookie
+     * does not exist, &lt;code&gt;get()&lt;/code&gt; returns &lt;tt&gt;null&lt;/tt&gt;.  The following
+     * example retrieves the cookie called &quot;valid&quot; and stores the String value
+     * in the variable &lt;tt&gt;validStatus&lt;/tt&gt;.
+     * &lt;pre&gt;&lt;code&gt;
+     * var validStatus = Ext.util.Cookies.get(&quot;valid&quot;);
+     * &lt;/code&gt;&lt;/pre&gt;
      * @param {String} name The name of the cookie to get
      * @return {Mixed} Returns the cookie value for the specified name;
      * null if the cookie name does not exist.
      */
     get : function(name){
-        var arg = name + "=";
-        var alen = arg.length;
-        var clen = document.cookie.length;
-        var i = 0;
-        var j = 0;
-        while(i < clen){
+        var arg = name + &quot;=&quot;,
+            alen = arg.length,
+            clen = document.cookie.length,
+            i = 0,
+            j = 0;
+            
+        while(i &lt; clen){
             j = i + alen;
             if(document.cookie.substring(i, j) == arg){
-                return Ext.util.Cookies.getCookieVal(j);
+                return this.getCookieVal(j);
             }
-            i = document.cookie.indexOf(" ", i) + 1;
+            i = document.cookie.indexOf(&quot; &quot;, i) + 1;
             if(i === 0){
                 break;
             }
@@ -81,26 +77,28 @@ Ext.util.Cookies = {
         return null;
     },
 
-    <div id="method-Ext.util.Cookies-clear"></div>/**
-     * Removes a cookie with the provided name from the browser
+<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 (optional) The path for the cookie. This must be included if you included a path while setting the cookie.
      */
-    clear : function(name){
-        if(Ext.util.Cookies.get(name)){
-            document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
+    clear : function(name, path){
+        if(this.get(name)){
+            path = path || '/';
+            document.cookie = name + '=' + '; expires=Thu, 01-Jan-70 00:00:01 GMT; path=' + path;
         }
     },
-    /**
-     * @private
+    
+<span id='Ext-util.Cookies-method-getCookieVal'>    /**
+</span>     * @private
      */
     getCookieVal : function(offset){
-        var endstr = document.cookie.indexOf(";", offset);
+        var endstr = document.cookie.indexOf(&quot;;&quot;, offset);
         if(endstr == -1){
             endstr = document.cookie.length;
         }
         return unescape(document.cookie.substring(offset, endstr));
     }
-};</pre>    
-</body>
-</html>
\ No newline at end of file
+});
+</pre></pre></body></html>
\ No newline at end of file