Upgrade to ExtJS 3.0.3 - Released 10/11/2009
[extjs.git] / examples / image-organizer / SWFUpload / plugins / swfupload.cookies.js
1 /*!
2  * Ext JS Library 3.0.3
3  * Copyright(c) 2006-2009 Ext JS, LLC
4  * licensing@extjs.com
5  * http://www.extjs.com/license
6  */
7 /*\r
8         Cookie Plug-in\r
9         \r
10         This plug in automatically gets all the cookies for this site and adds them to the post_params.\r
11         Cookies are loaded only on initialization.  The refreshCookies function can be called to update the post_params.\r
12         The cookies will override any other post params with the same name.\r
13 */\r
14 \r
15 var SWFUpload;\r
16 if (typeof(SWFUpload) === "function") {\r
17         SWFUpload.prototype.initSettings = function (oldInitSettings) {\r
18                 return function () {\r
19                         if (typeof(oldInitSettings) === "function") {\r
20                                 oldInitSettings.call(this);\r
21                         }\r
22                         \r
23                         this.refreshCookies(false);     // The false parameter must be sent since SWFUpload has not initialzed at this point\r
24                 };\r
25         }(SWFUpload.prototype.initSettings);\r
26         \r
27         // refreshes the post_params and updates SWFUpload.  The sendToFlash parameters is optional and defaults to True\r
28         SWFUpload.prototype.refreshCookies = function (sendToFlash) {\r
29                 if (sendToFlash === undefined) {\r
30                         sendToFlash = true;\r
31                 }\r
32                 sendToFlash = !!sendToFlash;\r
33                 \r
34                 // Get the post_params object\r
35                 var postParams = this.settings.post_params;\r
36                 \r
37                 // Get the cookies\r
38                 var i, cookieArray = document.cookie.split(';'), caLength = cookieArray.length, c, eqIndex, name, value;\r
39                 for (i = 0; i < caLength; i++) {\r
40                         c = cookieArray[i];\r
41                         \r
42                         // Left Trim spaces\r
43                         while (c.charAt(0) === " ") {\r
44                                 c = c.substring(1, c.length);\r
45                         }\r
46                         eqIndex = c.indexOf("=");\r
47                         if (eqIndex > 0) {\r
48                                 name = c.substring(0, eqIndex);\r
49                                 value = c.substring(eqIndex + 1);\r
50                                 postParams[name] = value;\r
51                         }\r
52                 }\r
53                 \r
54                 if (sendToFlash) {\r
55                         this.setPostParams(postParams);\r
56                 }\r
57         };\r
58 \r
59 }\r