diff --git a/wp-includes/js/swfupload/plugins/swfupload.cookies.js b/wp-includes/js/swfupload/plugins/swfupload.cookies.js index dd3b78bbc..4d41612df 100644 --- a/wp-includes/js/swfupload/plugins/swfupload.cookies.js +++ b/wp-includes/js/swfupload/plugins/swfupload.cookies.js @@ -8,45 +8,42 @@ var SWFUpload; if (typeof(SWFUpload) === "function") { - SWFUpload.prototype.initSettings = function (oldInitSettings) { - return function () { - if (typeof(oldInitSettings) === "function") { - oldInitSettings.call(this); + SWFUpload.prototype.initSettings = function (old_initSettings) { + return function (init_settings) { + if (typeof(old_initSettings) === "function") { + old_initSettings.call(this, init_settings); } this.refreshCookies(false); // The false parameter must be sent since SWFUpload has not initialzed at this point }; }(SWFUpload.prototype.initSettings); - // refreshes the post_params and updates SWFUpload. The sendToFlash parameters is optional and defaults to True - SWFUpload.prototype.refreshCookies = function (sendToFlash) { - if (sendToFlash === undefined) { - sendToFlash = true; - } - sendToFlash = !!sendToFlash; + // refreshes the post_params and updates SWFUpload. The send_to_flash parameters is optional and defaults to True + SWFUpload.prototype.refreshCookies = function (send_to_flash) { + if (send_to_flash !== false) send_to_flash = true; // Get the post_params object - var postParams = this.settings.post_params; + var post_params = this.getSetting("post_params"); // Get the cookies - var i, cookieArray = document.cookie.split(';'), caLength = cookieArray.length, c, eqIndex, name, value; - for (i = 0; i < caLength; i++) { - c = cookieArray[i]; + var i, cookie_array = document.cookie.split(';'), ca_length = cookie_array.length, c, eq_index, name, value; + for(i = 0; i < ca_length; i++) { + c = cookie_array[i]; // Left Trim spaces - while (c.charAt(0) === " ") { + while (c.charAt(0) == " ") { c = c.substring(1, c.length); } - eqIndex = c.indexOf("="); - if (eqIndex > 0) { - name = c.substring(0, eqIndex); - value = c.substring(eqIndex + 1); - postParams[name] = value; + eq_index = c.indexOf("="); + if (eq_index > 0) { + name = c.substring(0, eq_index); + value = c.substring(eq_index+1); + post_params[name] = value; } } - if (sendToFlash) { - this.setPostParams(postParams); + if (send_to_flash) { + this.setPostParams(post_params); } }; diff --git a/wp-includes/js/swfupload/plugins/swfupload.documentready.js b/wp-includes/js/swfupload/plugins/swfupload.documentready.js new file mode 100644 index 000000000..a95bac54e --- /dev/null +++ b/wp-includes/js/swfupload/plugins/swfupload.documentready.js @@ -0,0 +1,102 @@ +/* + DocumentReady Plug-in + + This plugin loads SWFUpload as soon as the document is ready. You should not load SWFUpload inside window.onload using this plugin. + You can also chain other functions by calling SWFUpload.DocumentReady(your function). + + Warning: Embedded Ads or other scripts that overwrite window.onload or use their own document ready functions may interfer with this plugin. You + should not set window.onload when using this plugin. + + Usage Example: + + var swfu = new SWFUpload(your settings object); + SWFUpload.DocumentReady(function () { alert('Document Ready!'; }); + +*/ + +var SWFUpload; +if (typeof(SWFUpload) === "function") { + // Override iniSWFUpload so SWFUpload gets inited when the document is ready rather than immediately + SWFUpload.prototype.initSWFUpload = function (old_initSWFUpload) { + return function (init_settings) { + var self = this; + if (typeof(old_initSWFUpload) === "function") { + SWFUpload.DocumentReady(function () { + old_initSWFUpload.call(self, init_settings); + }); + } + } + + }(SWFUpload.prototype.initSWFUpload); + + + // The DocumentReady function adds the passed in function to + // the functions that will be executed when the document is ready/loaded + SWFUpload.DocumentReady = function (fn) { + // Add the function to the chain + SWFUpload.DocumentReady.InternalOnloadChain = function (previous_link_fn) { + return function () { + if (typeof(previous_link_fn) === "function") { + previous_link_fn(); + } + fn(); + }; + }(SWFUpload.DocumentReady.InternalOnloadChain); + }; + SWFUpload.DocumentReady.InternalOnloadChain = null; + SWFUpload.DocumentReady.Onload = function () { + // Execute the onload function chain + if (typeof(SWFUpload.DocumentReady.InternalOnloadChain) === "function") { + SWFUpload.DocumentReady.InternalOnloadChain(); + } + }; + SWFUpload.DocumentReady.SetupComplete = false; + + + /* ******************************************** + This portion of the code gets executed as soon it is loaded. + It binds the proper event for executing JavaScript is + early as possible. This is a per browser function and so + some browser sniffing is used. + + This solution still has the "exposed" issue (See the Global Delegation section at http://peter.michaux.ca/article/553 ) + + Base solution from http://dean.edwards.name/weblog/2006/06/again/ and http://dean.edwards.name/weblog/2005/09/busted/ + ******************************************** */ + if (!SWFUpload.DocumentReady.SetupComplete) { + // for Internet Explorer (using conditional comments) + /*@cc_on @*/ + /*@if (@_win32) + document.write(" - - Notes: - You must provide set minimum_flash_version setting to "8" if you are using SWFUpload for Flash Player 8. - The swfuploadLoadFailed event is only fired if the minimum version of Flash Player is not met. Other issues such as missing SWF files, browser bugs - or corrupt Flash Player installations will not trigger this event. - The swfuploadPreLoad event is fired as soon as the minimum version of Flash Player is found. It does not wait for SWFUpload to load and can - be used to prepare the SWFUploadUI and hide alternate content. - swfobject's onDomReady event is cross-browser safe but will default to the window.onload event when DOMReady is not supported by the browser. - Early DOM Loading is supported in major modern browsers but cannot be guaranteed for every browser ever made. -*/ - - -/* SWFObject v2.0 rc4 - Copyright (c) 2007 Geoff Stearns, Michael Williams, and Bobby van der Sluis - This software is released under the MIT License -*/ -var swfobject=function(){var X="undefined",P="object",a="visibility:visible",e="visibility:hidden",B="Shockwave Flash",h="ShockwaveFlash.ShockwaveFlash",V="application/x-shockwave-flash",K="SWFObjectExprInst",G=window,g=document,N=navigator,f=[],H=[],Q=null,L=null,S=false,C=false;var Y=function(){var l=typeof g.getElementById!=X&&typeof g.getElementsByTagName!=X&&typeof g.createElement!=X&&typeof g.appendChild!=X&&typeof g.replaceChild!=X&&typeof g.removeChild!=X&&typeof g.cloneNode!=X,t=[0,0,0],n=null;if(typeof N.plugins!=X&&typeof N.plugins[B]==P){n=N.plugins[B].description;if(n){n=n.replace(/^.*\s+(\S+\s+\S+$)/,"$1");t[0]=parseInt(n.replace(/^(.*)\..*$/,"$1"),10);t[1]=parseInt(n.replace(/^.*\.(.*)\s.*$/,"$1"),10);t[2]=/r/.test(n)?parseInt(n.replace(/^.*r(.*)$/,"$1"),10):0}}else{if(typeof G.ActiveXObject!=X){var o=null,s=false;try{o=new ActiveXObject(h+".7")}catch(k){try{o=new ActiveXObject(h+".6");t=[6,0,21];o.AllowScriptAccess="always"}catch(k){if(t[0]==6){s=true}}if(!s){try{o=new ActiveXObject(h)}catch(k){}}}if(!s&&o){try{n=o.GetVariable("$version");if(n){n=n.split(" ")[1].split(",");t=[parseInt(n[0],10),parseInt(n[1],10),parseInt(n[2],10)]}}catch(k){}}}}var v=N.userAgent.toLowerCase(),j=N.platform.toLowerCase(),r=/webkit/.test(v)?parseFloat(v.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):false,i=false,q=j?/win/.test(j):/win/.test(v),m=j?/mac/.test(j):/mac/.test(v);/*@cc_on i=true;@if(@_win32)q=true;@elif(@_mac)m=true;@end@*/return{w3cdom:l,pv:t,webkit:r,ie:i,win:q,mac:m}}();var d=function(){if(!Y.w3cdom){return }J(I);if(Y.ie&&Y.win){try{g.write("