Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / examples / image-organizer / SWFUpload / plugins / swfupload.cookies.js
diff --git a/examples/image-organizer/SWFUpload/plugins/swfupload.cookies.js b/examples/image-organizer/SWFUpload/plugins/swfupload.cookies.js
new file mode 100644 (file)
index 0000000..c5370ec
--- /dev/null
@@ -0,0 +1,59 @@
+/*!
+ * Ext JS Library 3.0.0
+ * Copyright(c) 2006-2009 Ext JS, LLC
+ * licensing@extjs.com
+ * http://www.extjs.com/license
+ */
+/*\r
+       Cookie Plug-in\r
+       \r
+       This plug in automatically gets all the cookies for this site and adds them to the post_params.\r
+       Cookies are loaded only on initialization.  The refreshCookies function can be called to update the post_params.\r
+       The cookies will override any other post params with the same name.\r
+*/\r
+\r
+var SWFUpload;\r
+if (typeof(SWFUpload) === "function") {\r
+       SWFUpload.prototype.initSettings = function (oldInitSettings) {\r
+               return function () {\r
+                       if (typeof(oldInitSettings) === "function") {\r
+                               oldInitSettings.call(this);\r
+                       }\r
+                       \r
+                       this.refreshCookies(false);     // The false parameter must be sent since SWFUpload has not initialzed at this point\r
+               };\r
+       }(SWFUpload.prototype.initSettings);\r
+       \r
+       // refreshes the post_params and updates SWFUpload.  The sendToFlash parameters is optional and defaults to True\r
+       SWFUpload.prototype.refreshCookies = function (sendToFlash) {\r
+               if (sendToFlash === undefined) {\r
+                       sendToFlash = true;\r
+               }\r
+               sendToFlash = !!sendToFlash;\r
+               \r
+               // Get the post_params object\r
+               var postParams = this.settings.post_params;\r
+               \r
+               // Get the cookies\r
+               var i, cookieArray = document.cookie.split(';'), caLength = cookieArray.length, c, eqIndex, name, value;\r
+               for (i = 0; i < caLength; i++) {\r
+                       c = cookieArray[i];\r
+                       \r
+                       // Left Trim spaces\r
+                       while (c.charAt(0) === " ") {\r
+                               c = c.substring(1, c.length);\r
+                       }\r
+                       eqIndex = c.indexOf("=");\r
+                       if (eqIndex > 0) {\r
+                               name = c.substring(0, eqIndex);\r
+                               value = c.substring(eqIndex + 1);\r
+                               postParams[name] = value;\r
+                       }\r
+               }\r
+               \r
+               if (sendToFlash) {\r
+                       this.setPostParams(postParams);\r
+               }\r
+       };\r
+\r
+}\r