⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 swfupload.js

📁 WordPress是一个Blog程序,用它你可以架设完全属于你自己的Blog. 而WordPress现在的应用又不仅仅只是在Blog方面,因为其强大的扩展性,部分网站甚至已经开始使用WordPress
💻 JS
📖 第 1 页 / 共 3 页
字号:
/** * SWFUpload: http://www.swfupload.org, http://swfupload.googlecode.com * * mmSWFUpload 1.0: Flash upload dialog - http://profandesign.se/swfupload/,  http://www.vinterwebb.se/ * * SWFUpload is (c) 2006-2007 Lars Huring, Olov Nilz閚 and Mammon Media and is released under the MIT License: * http://www.opensource.org/licenses/mit-license.php * * SWFUpload 2 is (c) 2007-2008 Jake Roberts and is released under the MIT License: * http://www.opensource.org/licenses/mit-license.php * *//* ******************* *//* Constructor & Init  *//* ******************* */var SWFUpload;if (SWFUpload == undefined) {	SWFUpload = function (settings) {		this.initSWFUpload(settings);	};}SWFUpload.prototype.initSWFUpload = function (settings) {	try {		this.customSettings = {};	// A container where developers can place their own settings associated with this instance.		this.settings = settings;		this.eventQueue = [];		this.movieName = "SWFUpload_" + SWFUpload.movieCount++;		this.movieElement = null;		// Setup global control tracking		SWFUpload.instances[this.movieName] = this;		// Load the settings.  Load the Flash movie.		this.initSettings();		this.loadFlash();		this.displayDebugInfo();	} catch (ex) {		delete SWFUpload.instances[this.movieName];		throw ex;	}};/* *************** *//* Static Members  *//* *************** */SWFUpload.instances = {};SWFUpload.movieCount = 0;SWFUpload.version = "2.2.0 Beta 2";SWFUpload.QUEUE_ERROR = {	QUEUE_LIMIT_EXCEEDED	  		: -100,	FILE_EXCEEDS_SIZE_LIMIT  		: -110,	ZERO_BYTE_FILE			  		: -120,	INVALID_FILETYPE		  		: -130};SWFUpload.UPLOAD_ERROR = {	HTTP_ERROR				  		: -200,	MISSING_UPLOAD_URL	      		: -210,	IO_ERROR				  		: -220,	SECURITY_ERROR			  		: -230,	UPLOAD_LIMIT_EXCEEDED	  		: -240,	UPLOAD_FAILED			  		: -250,	SPECIFIED_FILE_ID_NOT_FOUND		: -260,	FILE_VALIDATION_FAILED	  		: -270,	FILE_CANCELLED			  		: -280,	UPLOAD_STOPPED					: -290};SWFUpload.FILE_STATUS = {	QUEUED		 : -1,	IN_PROGRESS	 : -2,	ERROR		 : -3,	COMPLETE	 : -4,	CANCELLED	 : -5};SWFUpload.BUTTON_ACTION = {	SELECT_FILE  : -100,	SELECT_FILES : -110,	START_UPLOAD : -120};SWFUpload.CURSOR = {	ARROW : -1,	HAND : -2};SWFUpload.WINDOW_MODE = {	WINDOW : "window",	TRANSPARENT : "transparent",	OPAQUE : "opaque"};/* ******************** *//* Instance Members  *//* ******************** */// Private: initSettings ensures that all the// settings are set, getting a default value if one was not assigned.SWFUpload.prototype.initSettings = function () {	this.ensureDefault = function (settingName, defaultValue) {		this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];	};		// Upload backend settings	this.ensureDefault("upload_url", "");	this.ensureDefault("file_post_name", "Filedata");	this.ensureDefault("post_params", {});	this.ensureDefault("use_query_string", false);	this.ensureDefault("requeue_on_error", false);	this.ensureDefault("http_success", []);		// File Settings	this.ensureDefault("file_types", "*.*");	this.ensureDefault("file_types_description", "All Files");	this.ensureDefault("file_size_limit", 0);	// Default zero means "unlimited"	this.ensureDefault("file_upload_limit", 0);	this.ensureDefault("file_queue_limit", 0);	// Flash Settings	this.ensureDefault("flash_url", "swfupload.swf");	this.ensureDefault("prevent_swf_caching", true);		// Button Settings	this.ensureDefault("button_image_url", "");	this.ensureDefault("button_width", 1);	this.ensureDefault("button_height", 1);	this.ensureDefault("button_text", "");	this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;");	this.ensureDefault("button_text_top_padding", 0);	this.ensureDefault("button_text_left_padding", 0);	this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES);	this.ensureDefault("button_disabled", false);	this.ensureDefault("button_placeholder_id", null);	this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW);	this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW);		// Debug Settings	this.ensureDefault("debug", false);	this.settings.debug_enabled = this.settings.debug;	// Here to maintain v2 API		// Event Handlers	this.settings.return_upload_start_handler = this.returnUploadStart;	this.ensureDefault("swfupload_loaded_handler", null);	this.ensureDefault("file_dialog_start_handler", null);	this.ensureDefault("file_queued_handler", null);	this.ensureDefault("file_queue_error_handler", null);	this.ensureDefault("file_dialog_complete_handler", null);		this.ensureDefault("upload_start_handler", null);	this.ensureDefault("upload_progress_handler", null);	this.ensureDefault("upload_error_handler", null);	this.ensureDefault("upload_success_handler", null);	this.ensureDefault("upload_complete_handler", null);		this.ensureDefault("debug_handler", this.debugMessage);	this.ensureDefault("custom_settings", {});	// Other settings	this.customSettings = this.settings.custom_settings;		// Update the flash url if needed	if (this.settings.prevent_swf_caching) {		this.settings.flash_url = this.settings.flash_url + "?swfuploadrnd=" + Math.floor(Math.random() * 999999999);	}		delete this.ensureDefault;};SWFUpload.prototype.loadFlash = function () {	if (this.settings.button_placeholder_id !== "") {		this.replaceWithFlash();	} else {		this.appendFlash();	}};// Private: appendFlash gets the HTML tag for the Flash// It then appends the flash to the bodySWFUpload.prototype.appendFlash = function () {	var targetElement, container;	// Make sure an element with the ID we are going to use doesn't already exist	if (document.getElementById(this.movieName) !== null) {		throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";	}	// Get the body tag where we will be adding the flash movie	targetElement = document.getElementsByTagName("body")[0];	if (targetElement == undefined) {		throw "Could not find the 'body' element.";	}	// Append the container and load the flash	container = document.createElement("div");	container.style.width = "1px";	container.style.height = "1px";	container.style.overflow = "hidden";	targetElement.appendChild(container);	container.innerHTML = this.getFlashHTML();	// Using innerHTML is non-standard but the only sensible way to dynamically add Flash in IE (and maybe other browsers)};// Private: replaceWithFlash replaces the button_placeholder element with the flash movie.SWFUpload.prototype.replaceWithFlash = function () {	var targetElement, tempParent;	// Make sure an element with the ID we are going to use doesn't already exist	if (document.getElementById(this.movieName) !== null) {		throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";	}	// Get the element where we will be placing the flash movie	targetElement = document.getElementById(this.settings.button_placeholder_id);	if (targetElement == undefined) {		throw "Could not find the placeholder element.";	}	// Append the container and load the flash	tempParent = document.createElement("div");	tempParent.innerHTML = this.getFlashHTML();	// Using innerHTML is non-standard but the only sensible way to dynamically add Flash in IE (and maybe other browsers)	targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement);};// Private: getFlashHTML generates the object tag needed to embed the flash in to the documentSWFUpload.prototype.getFlashHTML = function () {	// Flash Satay object syntax: http://www.alistapart.com/articles/flashsatay	return ['<object id="', this.movieName, '" type="application/x-shockwave-flash" data="', this.settings.flash_url, '" width="', this.settings.button_width, '" height="', this.settings.button_height, '" class="swfupload">',				'<param name="wmode" value="', this.settings.button_window_mode , '" />',				'<param name="movie" value="', this.settings.flash_url, '" />',				'<param name="quality" value="high" />',				'<param name="menu" value="false" />',				'<param name="allowScriptAccess" value="always" />',				'<param name="flashvars" value="' + this.getFlashVars() + '" />',				'</object>'].join("");};// Private: getFlashVars builds the parameter string that will be passed// to flash in the flashvars param.SWFUpload.prototype.getFlashVars = function () {	// Build a string from the post param object	var paramString = this.buildParamString();	var httpSuccessString = this.settings.http_success.join(",");		// Build the parameter string	return ["movieName=", encodeURIComponent(this.movieName),			"&amp;uploadURL=", encodeURIComponent(this.settings.upload_url),			"&amp;useQueryString=", encodeURIComponent(this.settings.use_query_string),			"&amp;requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),			"&amp;httpSuccess=", encodeURIComponent(httpSuccessString),			"&amp;params=", encodeURIComponent(paramString),			"&amp;filePostName=", encodeURIComponent(this.settings.file_post_name),			"&amp;fileTypes=", encodeURIComponent(this.settings.file_types),			"&amp;fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),			"&amp;fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),			"&amp;fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),			"&amp;fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),			"&amp;debugEnabled=", encodeURIComponent(this.settings.debug_enabled),			"&amp;buttonImageURL=", encodeURIComponent(this.settings.button_image_url),			"&amp;buttonWidth=", encodeURIComponent(this.settings.button_width),			"&amp;buttonHeight=", encodeURIComponent(this.settings.button_height),			"&amp;buttonText=", encodeURIComponent(this.settings.button_text),			"&amp;buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding),			"&amp;buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding),			"&amp;buttonTextStyle=", encodeURIComponent(this.settings.button_text_style),			"&amp;buttonAction=", encodeURIComponent(this.settings.button_action),			"&amp;buttonDisabled=", encodeURIComponent(this.settings.button_disabled),			"&amp;buttonCursor=", encodeURIComponent(this.settings.button_cursor)		].join("");};// Public: getMovieElement retrieves the DOM reference to the Flash element added by SWFUpload// The element is cached after the first lookupSWFUpload.prototype.getMovieElement = function () {	if (this.movieElement == undefined) {		this.movieElement = document.getElementById(this.movieName);	}	if (this.movieElement === null) {		throw "Could not find Flash element";	}		return this.movieElement;};// Private: buildParamString takes the name/value pairs in the post_params setting object// and joins them up in to a string formatted "name=value&amp;name=value"SWFUpload.prototype.buildParamString = function () {	var postParams = this.settings.post_params; 	var paramStringPairs = [];	if (typeof(postParams) === "object") {		for (var name in postParams) {			if (postParams.hasOwnProperty(name)) {				paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString()));			}		}	}	return paramStringPairs.join("&amp;");};// Public: Used to remove a SWFUpload instance from the page. This method strives to remove// all references to the SWF, and other objects so memory is properly freed.// Returns true if everything was destroyed. Returns a false if a failure occurs leaving SWFUpload in an inconsistant state.SWFUpload.prototype.destroy = function () {	try {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -