Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / docs / source / swfupload.cookies.html
1 <html>\r
2 <head>\r
3   <title>The source code</title>\r
4     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
5     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
6 </head>\r
7 <body  onload="prettyPrint();">\r
8     <pre class="prettyprint lang-js">/*\r
9         Cookie Plug-in\r
10         \r
11         This plug in automatically gets all the cookies for this site and adds them to the post_params.\r
12         Cookies are loaded only on initialization.  The refreshCookies function can be called to update the post_params.\r
13         The cookies will override any other post params with the same name.\r
14 */\r
15 \r
16 var SWFUpload;\r
17 if (typeof(SWFUpload) === "function") {\r
18         SWFUpload.prototype.initSettings = function (oldInitSettings) {\r
19                 return function () {\r
20                         if (typeof(oldInitSettings) === "function") {\r
21                                 oldInitSettings.call(this);\r
22                         }\r
23                         \r
24                         this.refreshCookies(false);     // The false parameter must be sent since SWFUpload has not initialzed at this point\r
25                 };\r
26         }(SWFUpload.prototype.initSettings);\r
27         \r
28         // refreshes the post_params and updates SWFUpload.  The sendToFlash parameters is optional and defaults to True\r
29         SWFUpload.prototype.refreshCookies = function (sendToFlash) {\r
30                 if (sendToFlash === undefined) {\r
31                         sendToFlash = true;\r
32                 }\r
33                 sendToFlash = !!sendToFlash;\r
34                 \r
35                 // Get the post_params object\r
36                 var postParams = this.settings.post_params;\r
37                 \r
38                 // Get the cookies\r
39                 var i, cookieArray = document.cookie.split(';'), caLength = cookieArray.length, c, eqIndex, name, value;\r
40                 for (i = 0; i < caLength; i++) {\r
41                         c = cookieArray[i];\r
42                         \r
43                         // Left Trim spaces\r
44                         while (c.charAt(0) === " ") {\r
45                                 c = c.substring(1, c.length);\r
46                         }\r
47                         eqIndex = c.indexOf("=");\r
48                         if (eqIndex > 0) {\r
49                                 name = c.substring(0, eqIndex);\r
50                                 value = c.substring(eqIndex + 1);\r
51                                 postParams[name] = value;\r
52                         }\r
53                 }\r
54                 \r
55                 if (sendToFlash) {\r
56                         this.setPostParams(postParams);\r
57                 }\r
58         };\r
59 \r
60 }\r
61 </pre>    \r
62 </body>\r
63 </html>