web/wp-includes/js/swfupload/plugins/swfupload.cookies.js
branchwordpress
changeset 109 03b0d1493584
child 132 4d4862461b8d
equal deleted inserted replaced
-1:000000000000 109:03b0d1493584
       
     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 (oldInitSettings) {
       
    12 		return function () {
       
    13 			if (typeof(oldInitSettings) === "function") {
       
    14 				oldInitSettings.call(this);
       
    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 sendToFlash parameters is optional and defaults to True
       
    22 	SWFUpload.prototype.refreshCookies = function (sendToFlash) {
       
    23 		if (sendToFlash === undefined) {
       
    24 			sendToFlash = true;
       
    25 		}
       
    26 		sendToFlash = !!sendToFlash;
       
    27 		
       
    28 		// Get the post_params object
       
    29 		var postParams = this.settings.post_params;
       
    30 		
       
    31 		// Get the cookies
       
    32 		var i, cookieArray = document.cookie.split(';'), caLength = cookieArray.length, c, eqIndex, name, value;
       
    33 		for (i = 0; i < caLength; i++) {
       
    34 			c = cookieArray[i];
       
    35 			
       
    36 			// Left Trim spaces
       
    37 			while (c.charAt(0) === " ") {
       
    38 				c = c.substring(1, c.length);
       
    39 			}
       
    40 			eqIndex = c.indexOf("=");
       
    41 			if (eqIndex > 0) {
       
    42 				name = c.substring(0, eqIndex);
       
    43 				value = c.substring(eqIndex + 1);
       
    44 				postParams[name] = value;
       
    45 			}
       
    46 		}
       
    47 		
       
    48 		if (sendToFlash) {
       
    49 			this.setPostParams(postParams);
       
    50 		}
       
    51 	};
       
    52 
       
    53 }