home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Blogs / wordpress2.6.exe / wordpress2.6 / wp-includes / js / swfupload / plugins / swfupload.cookies.js next >
Encoding:
JavaScript  |  2008-06-06  |  1.5 KB  |  51 lines

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