Revert [8056], didn't quite work

git-svn-id: http://svn.automattic.com/wordpress/trunk@8057 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-06-06 07:34:30 +00:00
parent 23cfaa55e9
commit ab39b3b321
7 changed files with 954 additions and 687 deletions

View File

@ -8,45 +8,42 @@
var SWFUpload; var SWFUpload;
if (typeof(SWFUpload) === "function") { if (typeof(SWFUpload) === "function") {
SWFUpload.prototype.initSettings = function (oldInitSettings) { SWFUpload.prototype.initSettings = function (old_initSettings) {
return function () { return function (init_settings) {
if (typeof(oldInitSettings) === "function") { if (typeof(old_initSettings) === "function") {
oldInitSettings.call(this); old_initSettings.call(this, init_settings);
} }
this.refreshCookies(false); // The false parameter must be sent since SWFUpload has not initialzed at this point this.refreshCookies(false); // The false parameter must be sent since SWFUpload has not initialzed at this point
}; };
}(SWFUpload.prototype.initSettings); }(SWFUpload.prototype.initSettings);
// refreshes the post_params and updates SWFUpload. The sendToFlash parameters is optional and defaults to True // refreshes the post_params and updates SWFUpload. The send_to_flash parameters is optional and defaults to True
SWFUpload.prototype.refreshCookies = function (sendToFlash) { SWFUpload.prototype.refreshCookies = function (send_to_flash) {
if (sendToFlash === undefined) { if (send_to_flash !== false) send_to_flash = true;
sendToFlash = true;
}
sendToFlash = !!sendToFlash;
// Get the post_params object // Get the post_params object
var postParams = this.settings.post_params; var post_params = this.getSetting("post_params");
// Get the cookies // Get the cookies
var i, cookieArray = document.cookie.split(';'), caLength = cookieArray.length, c, eqIndex, name, value; var i, cookie_array = document.cookie.split(';'), ca_length = cookie_array.length, c, eq_index, name, value;
for (i = 0; i < caLength; i++) { for(i = 0; i < ca_length; i++) {
c = cookieArray[i]; c = cookie_array[i];
// Left Trim spaces // Left Trim spaces
while (c.charAt(0) === " ") { while (c.charAt(0) == " ") {
c = c.substring(1, c.length); c = c.substring(1, c.length);
} }
eqIndex = c.indexOf("="); eq_index = c.indexOf("=");
if (eqIndex > 0) { if (eq_index > 0) {
name = c.substring(0, eqIndex); name = c.substring(0, eq_index);
value = c.substring(eqIndex + 1); value = c.substring(eq_index+1);
postParams[name] = value; post_params[name] = value;
} }
} }
if (sendToFlash) { if (send_to_flash) {
this.setPostParams(postParams); this.setPostParams(post_params);
} }
}; };

View File

@ -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("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
var script = document.getElementById("__ie_onload");
script.onreadystatechange = function() {
if (this.readyState == "complete") {
SWFUpload.DocumentReady.Onload(); // call the onload handler
}
};
SWFUpload.DocumentReady.SetupComplete = true;
/*@end @*/
}
if (!SWFUpload.DocumentReady.SetupComplete && /WebKit/i.test(navigator.userAgent)) { // sniff
var _timer = setInterval(function() {
if (/loaded|complete/.test(document.readyState)) {
clearInterval(_timer);
SWFUpload.DocumentReady.Onload(); // call the onload handler
}
}, 10);
SWFUpload.DocumentReady.SetupComplete = true;
}
/* for Mozilla */
if (!SWFUpload.DocumentReady.SetupComplete && document.addEventListener) {
document.addEventListener("DOMContentLoaded", SWFUpload.DocumentReady.Onload, false);
SWFUpload.DocumentReady.SetupComplete = true;
}
/* for other browsers */
if (!SWFUpload.DocumentReady.SetupComplete) {
window.onload = SWFUpload.DocumentReady.Onload;
SWFUpload.DocumentReady.SetupComplete = true;
}
}

View File

@ -19,46 +19,45 @@
var SWFUpload; var SWFUpload;
if (typeof(SWFUpload) === "function") { if (typeof(SWFUpload) === "function") {
SWFUpload.gracefulDegradation = {}; SWFUpload.gracefulDegradation = {};
SWFUpload.prototype.initSettings = (function (oldInitSettings) { SWFUpload.prototype.initSettings = function (old_initSettings) {
return function () { return function (init_settings) {
if (typeof(oldInitSettings) === "function") { if (typeof(old_initSettings) === "function") {
oldInitSettings.call(this); old_initSettings.call(this, init_settings);
} }
this.ensureDefault = function (settingName, defaultValue) { this.addSetting("swfupload_element_id", init_settings.swfupload_element_id, "swfupload_container");
this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName]; this.addSetting("degraded_element_id", init_settings.degraded_element_id, "degraded_container");
}; this.addSetting("user_swfUploadLoaded_handler", init_settings.swfupload_loaded_handler, SWFUpload.swfUploadLoaded);
this.ensureDefault("swfupload_element_id", "swfupload_container");
this.ensureDefault("degraded_element_id", "degraded_container");
this.settings.user_swfupload_loaded_handler = this.settings.swfupload_loaded_handler;
this.settings.swfupload_loaded_handler = SWFUpload.gracefulDegradation.swfUploadLoadedHandler; this.swfUploadLoaded_handler = SWFUpload.gracefulDegradation.swfUploadLoaded;
delete this.ensureDefault;
}; };
})(SWFUpload.prototype.initSettings); }(SWFUpload.prototype.initSettings);
SWFUpload.gracefulDegradation.swfUploadLoadedHandler = function () { SWFUpload.gracefulDegradation.swfUploadLoaded = function () {
var swfuploadContainerID, swfuploadContainer, degradedContainerID, degradedContainer; var swfupload_container_id, swfupload_container, degraded_container_id, degraded_container, user_swfUploadLoaded_handler;
try {
if (uploadDegradeOptions.is_lighttpd_before_150) throw "Lighttpd versions earlier than 1.5.0 aren't supported!";
swfupload_element_id = this.getSetting("swfupload_element_id");
degraded_element_id = this.getSetting("degraded_element_id");
// Show the UI container
swfupload_container = document.getElementById(swfupload_element_id);
if (swfupload_container !== null) {
swfupload_container.style.display = "block";
swfuploadContainerID = this.settings.swfupload_element_id; // Now take care of hiding the degraded UI
degradedContainerID = this.settings.degraded_element_id; degraded_container = document.getElementById(degraded_element_id);
if (degraded_container !== null) {
// Show the UI container degraded_container.style.display = "none";
swfuploadContainer = document.getElementById(swfuploadContainerID); }
if (swfuploadContainer != undefined) {
swfuploadContainer.style.display = "block";
// Now take care of hiding the degraded UI
degradedContainer = document.getElementById(degradedContainerID);
if (degradedContainer != undefined) {
degradedContainer.style.display = "none";
} }
} catch (ex) {
this.debug(ex);
} }
if (typeof(this.settings.user_swfupload_loaded_handler) === "function") { user_swfUploadLoaded_handler = this.getSetting("user_swfUploadLoaded_handler");
this.settings.user_swfupload_loaded_handler.apply(this); if (typeof(user_swfUploadLoaded_handler) === "function") {
user_swfUploadLoaded_handler.apply(this);
} }
}; };

View File

@ -2,12 +2,9 @@
Queue Plug-in Queue Plug-in
Features: Features:
*Adds a cancelQueue() method for cancelling the entire queue. cancelQueue method for cancelling the entire queue.
*All queued files are uploaded when startUpload() is called. All queued files are uploaded when startUpload() is called.
*If false is returned from uploadComplete then the queue upload is stopped. If false is returned from uploadComplete then the queue upload is stopped. If false is not returned (strict comparison) then the queue upload is continued.
If false is not returned (strict comparison) then the queue upload is continued.
*Adds a QueueComplete event that is fired when all the queued files have finished uploading.
Set the event handler with the queue_complete_handler setting.
*/ */
@ -15,63 +12,47 @@ var SWFUpload;
if (typeof(SWFUpload) === "function") { if (typeof(SWFUpload) === "function") {
SWFUpload.queue = {}; SWFUpload.queue = {};
SWFUpload.prototype.initSettings = (function (oldInitSettings) { SWFUpload.prototype.initSettings = function (old_initSettings) {
return function () { return function (init_settings) {
if (typeof(oldInitSettings) === "function") { if (typeof(old_initSettings) === "function") {
oldInitSettings.call(this); old_initSettings.call(this, init_settings);
} }
this.customSettings.queue_cancelled_flag = false; this.customSettings.queue_cancelled_flag = false;
this.customSettings.queue_upload_count = 0;
this.settings.user_upload_complete_handler = this.settings.upload_complete_handler; this.addSetting("user_upload_complete_handler", init_settings.upload_complete_handler, SWFUpload.uploadComplete);
this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler; this.uploadComplete_handler = SWFUpload.queue.uploadComplete;
this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
}; };
})(SWFUpload.prototype.initSettings); }(SWFUpload.prototype.initSettings);
SWFUpload.prototype.startUpload = function (fileID) {
this.customSettings.queue_cancelled_flag = false;
this.callFlash("StartUpload", false, [fileID]);
};
SWFUpload.prototype.cancelQueue = function () { SWFUpload.prototype.cancelQueue = function () {
this.customSettings.queue_cancelled_flag = true;
this.stopUpload();
var stats = this.getStats(); var stats = this.getStats();
while (stats.files_queued > 0) { this.customSettings.queue_cancelled_flag = false;
if (stats.in_progress > 0) {
this.customSettings.queue_cancelled_flag = true;
}
while(stats.files_queued > 0) {
this.cancelUpload(); this.cancelUpload();
stats = this.getStats(); stats = this.getStats();
} }
}; };
SWFUpload.queue.uploadCompleteHandler = function (file) { SWFUpload.queue.uploadComplete = function (file) {
var user_upload_complete_handler = this.settings.user_upload_complete_handler; var user_upload_complete_handler = this.getSetting("user_upload_complete_handler");
var continueUpload; var continue_upload = true;
if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
this.customSettings.queue_upload_count++;
}
if (typeof(user_upload_complete_handler) === "function") { if (typeof(user_upload_complete_handler) === "function") {
continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true; continue_upload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
} else {
continueUpload = true;
} }
if (continueUpload) { if (continue_upload) {
var stats = this.getStats(); var stats = this.getStats();
if (stats.files_queued > 0 && this.customSettings.queue_cancelled_flag === false) { if (stats.files_queued > 0 && this.customSettings.queue_cancelled_flag === false) {
this.startUpload(); this.startUpload();
} else if (this.customSettings.queue_cancelled_flag === false) {
this.queueEvent("queue_complete_handler", [this.customSettings.queue_upload_count]);
this.customSettings.queue_upload_count = 0;
} else { } else {
this.customSettings.queue_cancelled_flag = false; this.customSettings.queue_cancelled_flag = false;
this.customSettings.queue_upload_count = 0;
} }
} }
}; };
} }

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff