swfupload.cookies.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. Cookie Plug-in
  3. This plug in automatically gets all the cookies for this site and adds them to the post_params.
  4. Cookies are loaded only on initialization. The refreshCookies function can be called to update the post_params.
  5. The cookies will override any other post params with the same name.
  6. */
  7. var SWFUpload;
  8. if (typeof(SWFUpload) === "function") {
  9. SWFUpload.prototype.initSettings = function (oldInitSettings) {
  10. return function () {
  11. if (typeof(oldInitSettings) === "function") {
  12. oldInitSettings.call(this);
  13. }
  14. this.refreshCookies(false); // The false parameter must be sent since SWFUpload has not initialzed at this point
  15. };
  16. }(SWFUpload.prototype.initSettings);
  17. // refreshes the post_params and updates SWFUpload. The sendToFlash parameters is optional and defaults to True
  18. SWFUpload.prototype.refreshCookies = function (sendToFlash) {
  19. if (sendToFlash === undefined) {
  20. sendToFlash = true;
  21. }
  22. sendToFlash = !!sendToFlash;
  23. // Get the post_params object
  24. var postParams = this.settings.post_params;
  25. // Get the cookies
  26. var i, cookieArray = document.cookie.split(';'), caLength = cookieArray.length, c, eqIndex, name, value;
  27. for (i = 0; i < caLength; i++) {
  28. c = cookieArray[i];
  29. // Left Trim spaces
  30. while (c.charAt(0) === " ") {
  31. c = c.substring(1, c.length);
  32. }
  33. eqIndex = c.indexOf("=");
  34. if (eqIndex > 0) {
  35. name = c.substring(0, eqIndex);
  36. value = c.substring(eqIndex + 1);
  37. postParams[name] = value;
  38. }
  39. }
  40. if (sendToFlash) {
  41. this.setPostParams(postParams);
  42. }
  43. };
  44. }