Update to swfupload 2.1.0

git-svn-id: http://svn.automattic.com/wordpress/trunk@8056 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-06-06 07:29:15 +00:00
parent 220af4a96e
commit 23cfaa55e9
7 changed files with 683 additions and 950 deletions

View File

@ -8,42 +8,45 @@
var SWFUpload;
if (typeof(SWFUpload) === "function") {
SWFUpload.prototype.initSettings = function (old_initSettings) {
return function (init_settings) {
if (typeof(old_initSettings) === "function") {
old_initSettings.call(this, init_settings);
SWFUpload.prototype.initSettings = function (oldInitSettings) {
return function () {
if (typeof(oldInitSettings) === "function") {
oldInitSettings.call(this);
}
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 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;
// 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;
// Get the post_params object
var post_params = this.getSetting("post_params");
var postParams = this.settings.post_params;
// Get the cookies
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];
var i, cookieArray = document.cookie.split(';'), caLength = cookieArray.length, c, eqIndex, name, value;
for (i = 0; i < caLength; i++) {
c = cookieArray[i];
// Left Trim spaces
while (c.charAt(0) == " ") {
while (c.charAt(0) === " ") {
c = c.substring(1, c.length);
}
eq_index = c.indexOf("=");
if (eq_index > 0) {
name = c.substring(0, eq_index);
value = c.substring(eq_index+1);
post_params[name] = value;
eqIndex = c.indexOf("=");
if (eqIndex > 0) {
name = c.substring(0, eqIndex);
value = c.substring(eqIndex + 1);
postParams[name] = value;
}
}
if (send_to_flash) {
this.setPostParams(post_params);
if (sendToFlash) {
this.setPostParams(postParams);
}
};

View File

@ -1,102 +0,0 @@
/*
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,45 +19,46 @@
var SWFUpload;
if (typeof(SWFUpload) === "function") {
SWFUpload.gracefulDegradation = {};
SWFUpload.prototype.initSettings = function (old_initSettings) {
return function (init_settings) {
if (typeof(old_initSettings) === "function") {
old_initSettings.call(this, init_settings);
SWFUpload.prototype.initSettings = (function (oldInitSettings) {
return function () {
if (typeof(oldInitSettings) === "function") {
oldInitSettings.call(this);
}
this.addSetting("swfupload_element_id", init_settings.swfupload_element_id, "swfupload_container");
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 = function (settingName, defaultValue) {
this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
};
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.swfUploadLoaded_handler = SWFUpload.gracefulDegradation.swfUploadLoaded;
this.settings.swfupload_loaded_handler = SWFUpload.gracefulDegradation.swfUploadLoadedHandler;
delete this.ensureDefault;
};
}(SWFUpload.prototype.initSettings);
})(SWFUpload.prototype.initSettings);
SWFUpload.gracefulDegradation.swfUploadLoaded = function () {
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";
SWFUpload.gracefulDegradation.swfUploadLoadedHandler = function () {
var swfuploadContainerID, swfuploadContainer, degradedContainerID, degradedContainer;
// Now take care of hiding the degraded UI
degraded_container = document.getElementById(degraded_element_id);
if (degraded_container !== null) {
degraded_container.style.display = "none";
}
swfuploadContainerID = this.settings.swfupload_element_id;
degradedContainerID = this.settings.degraded_element_id;
// Show the UI container
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);
}
user_swfUploadLoaded_handler = this.getSetting("user_swfUploadLoaded_handler");
if (typeof(user_swfUploadLoaded_handler) === "function") {
user_swfUploadLoaded_handler.apply(this);
if (typeof(this.settings.user_swfupload_loaded_handler) === "function") {
this.settings.user_swfupload_loaded_handler.apply(this);
}
};

View File

@ -2,9 +2,12 @@
Queue Plug-in
Features:
cancelQueue method for cancelling the entire queue.
All queued files are uploaded when startUpload() is called.
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.
*Adds a cancelQueue() method for cancelling the entire queue.
*All queued files are uploaded when startUpload() is called.
*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.
*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.
*/
@ -12,47 +15,63 @@ var SWFUpload;
if (typeof(SWFUpload) === "function") {
SWFUpload.queue = {};
SWFUpload.prototype.initSettings = function (old_initSettings) {
return function (init_settings) {
if (typeof(old_initSettings) === "function") {
old_initSettings.call(this, init_settings);
SWFUpload.prototype.initSettings = (function (oldInitSettings) {
return function () {
if (typeof(oldInitSettings) === "function") {
oldInitSettings.call(this);
}
this.customSettings.queue_cancelled_flag = false;
this.customSettings.queue_upload_count = 0;
this.addSetting("user_upload_complete_handler", init_settings.upload_complete_handler, SWFUpload.uploadComplete);
this.uploadComplete_handler = SWFUpload.queue.uploadComplete;
this.settings.user_upload_complete_handler = this.settings.upload_complete_handler;
this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
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 () {
var stats = this.getStats();
this.customSettings.queue_cancelled_flag = false;
if (stats.in_progress > 0) {
this.customSettings.queue_cancelled_flag = true;
}
this.customSettings.queue_cancelled_flag = true;
this.stopUpload();
while(stats.files_queued > 0) {
var stats = this.getStats();
while (stats.files_queued > 0) {
this.cancelUpload();
stats = this.getStats();
}
};
SWFUpload.queue.uploadComplete = function (file) {
var user_upload_complete_handler = this.getSetting("user_upload_complete_handler");
var continue_upload = true;
SWFUpload.queue.uploadCompleteHandler = function (file) {
var user_upload_complete_handler = this.settings.user_upload_complete_handler;
var continueUpload;
if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
this.customSettings.queue_upload_count++;
}
if (typeof(user_upload_complete_handler) === "function") {
continue_upload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
} else {
continueUpload = true;
}
if (continue_upload) {
if (continueUpload) {
var stats = this.getStats();
if (stats.files_queued > 0 && this.customSettings.queue_cancelled_flag === false) {
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 {
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