-
+ E9770A9BF2E8D9BF9312109E46472D91287DB84DAD35ADFCE458109E2E36E5EDBFF08E9AE3476BEE0DA64375BBFDC4544541B95400EB58846C050EDDD281B9FD
mp-wp/wp-includes/js/swfupload/swfupload.js
(0 . 0)(1 . 927)
116828 /**
116829 * SWFUpload: http://www.swfupload.org, http://swfupload.googlecode.com
116830 *
116831 * mmSWFUpload 1.0: Flash upload dialog - http://profandesign.se/swfupload/, http://www.vinterwebb.se/
116832 *
116833 * SWFUpload is (c) 2006-2007 Lars Huring, Olov Nilzen and Mammon Media and is released under the MIT License:
116834 * http://www.opensource.org/licenses/mit-license.php
116835 *
116836 * SWFUpload 2 is (c) 2007-2008 Jake Roberts and is released under the MIT License:
116837 * http://www.opensource.org/licenses/mit-license.php
116838 *
116839 */
116840
116841
116842 /* ******************* */
116843 /* Constructor & Init */
116844 /* ******************* */
116845 var SWFUpload;
116846
116847 if (SWFUpload == undefined) {
116848 SWFUpload = function (settings) {
116849 this.initSWFUpload(settings);
116850 };
116851 }
116852
116853 SWFUpload.prototype.initSWFUpload = function (settings) {
116854 try {
116855 this.customSettings = {}; // A container where developers can place their own settings associated with this instance.
116856 this.settings = settings;
116857 this.eventQueue = [];
116858 this.movieName = "SWFUpload_" + SWFUpload.movieCount++;
116859 this.movieElement = null;
116860
116861 // Setup global control tracking
116862 SWFUpload.instances[this.movieName] = this;
116863
116864 // Load the settings. Load the Flash movie.
116865 this.initSettings();
116866 this.loadFlash();
116867 this.displayDebugInfo();
116868 } catch (ex) {
116869 delete SWFUpload.instances[this.movieName];
116870 throw ex;
116871 }
116872 };
116873
116874 /* *************** */
116875 /* Static Members */
116876 /* *************** */
116877 SWFUpload.instances = {};
116878 SWFUpload.movieCount = 0;
116879 SWFUpload.version = "2.2.0 Beta 2";
116880 SWFUpload.QUEUE_ERROR = {
116881 QUEUE_LIMIT_EXCEEDED : -100,
116882 FILE_EXCEEDS_SIZE_LIMIT : -110,
116883 ZERO_BYTE_FILE : -120,
116884 INVALID_FILETYPE : -130
116885 };
116886 SWFUpload.UPLOAD_ERROR = {
116887 HTTP_ERROR : -200,
116888 MISSING_UPLOAD_URL : -210,
116889 IO_ERROR : -220,
116890 SECURITY_ERROR : -230,
116891 UPLOAD_LIMIT_EXCEEDED : -240,
116892 UPLOAD_FAILED : -250,
116893 SPECIFIED_FILE_ID_NOT_FOUND : -260,
116894 FILE_VALIDATION_FAILED : -270,
116895 FILE_CANCELLED : -280,
116896 UPLOAD_STOPPED : -290
116897 };
116898 SWFUpload.FILE_STATUS = {
116899 QUEUED : -1,
116900 IN_PROGRESS : -2,
116901 ERROR : -3,
116902 COMPLETE : -4,
116903 CANCELLED : -5
116904 };
116905 SWFUpload.BUTTON_ACTION = {
116906 SELECT_FILE : -100,
116907 SELECT_FILES : -110,
116908 START_UPLOAD : -120
116909 };
116910 SWFUpload.CURSOR = {
116911 ARROW : -1,
116912 HAND : -2
116913 };
116914 SWFUpload.WINDOW_MODE = {
116915 WINDOW : "window",
116916 TRANSPARENT : "transparent",
116917 OPAQUE : "opaque"
116918 };
116919
116920 /* ******************** */
116921 /* Instance Members */
116922 /* ******************** */
116923
116924 // Private: initSettings ensures that all the
116925 // settings are set, getting a default value if one was not assigned.
116926 SWFUpload.prototype.initSettings = function () {
116927 this.ensureDefault = function (settingName, defaultValue) {
116928 this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
116929 };
116930
116931 // Upload backend settings
116932 this.ensureDefault("upload_url", "");
116933 this.ensureDefault("file_post_name", "Filedata");
116934 this.ensureDefault("post_params", {});
116935 this.ensureDefault("use_query_string", false);
116936 this.ensureDefault("requeue_on_error", false);
116937 this.ensureDefault("http_success", []);
116938
116939 // File Settings
116940 this.ensureDefault("file_types", "*.*");
116941 this.ensureDefault("file_types_description", "All Files");
116942 this.ensureDefault("file_size_limit", 0); // Default zero means "unlimited"
116943 this.ensureDefault("file_upload_limit", 0);
116944 this.ensureDefault("file_queue_limit", 0);
116945
116946 // Flash Settings
116947 this.ensureDefault("flash_url", "swfupload.swf");
116948 this.ensureDefault("prevent_swf_caching", true);
116949
116950 // Button Settings
116951 this.ensureDefault("button_image_url", "");
116952 this.ensureDefault("button_width", 1);
116953 this.ensureDefault("button_height", 1);
116954 this.ensureDefault("button_text", "");
116955 this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;");
116956 this.ensureDefault("button_text_top_padding", 0);
116957 this.ensureDefault("button_text_left_padding", 0);
116958 this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES);
116959 this.ensureDefault("button_disabled", false);
116960 this.ensureDefault("button_placeholder_id", null);
116961 this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW);
116962 this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW);
116963
116964 // Debug Settings
116965 this.ensureDefault("debug", false);
116966 this.settings.debug_enabled = this.settings.debug; // Here to maintain v2 API
116967
116968 // Event Handlers
116969 this.settings.return_upload_start_handler = this.returnUploadStart;
116970 this.ensureDefault("swfupload_loaded_handler", null);
116971 this.ensureDefault("file_dialog_start_handler", null);
116972 this.ensureDefault("file_queued_handler", null);
116973 this.ensureDefault("file_queue_error_handler", null);
116974 this.ensureDefault("file_dialog_complete_handler", null);
116975
116976 this.ensureDefault("upload_start_handler", null);
116977 this.ensureDefault("upload_progress_handler", null);
116978 this.ensureDefault("upload_error_handler", null);
116979 this.ensureDefault("upload_success_handler", null);
116980 this.ensureDefault("upload_complete_handler", null);
116981
116982 this.ensureDefault("debug_handler", this.debugMessage);
116983
116984 this.ensureDefault("custom_settings", {});
116985
116986 // Other settings
116987 this.customSettings = this.settings.custom_settings;
116988
116989 // Update the flash url if needed
116990 if (this.settings.prevent_swf_caching) {
116991 this.settings.flash_url = this.settings.flash_url + "?swfuploadrnd=" + Math.floor(Math.random() * 999999999);
116992 }
116993
116994 delete this.ensureDefault;
116995 };
116996
116997 SWFUpload.prototype.loadFlash = function () {
116998 if (this.settings.button_placeholder_id !== "") {
116999 this.replaceWithFlash();
117000 } else {
117001 this.appendFlash();
117002 }
117003 };
117004
117005 // Private: appendFlash gets the HTML tag for the Flash
117006 // It then appends the flash to the body
117007 SWFUpload.prototype.appendFlash = function () {
117008 var targetElement, container;
117009
117010 // Make sure an element with the ID we are going to use doesn't already exist
117011 if (document.getElementById(this.movieName) !== null) {
117012 throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
117013 }
117014
117015 // Get the body tag where we will be adding the flash movie
117016 targetElement = document.getElementsByTagName("body")[0];
117017
117018 if (targetElement == undefined) {
117019 throw "Could not find the 'body' element.";
117020 }
117021
117022 // Append the container and load the flash
117023 container = document.createElement("div");
117024 container.style.width = "1px";
117025 container.style.height = "1px";
117026 container.style.overflow = "hidden";
117027
117028 targetElement.appendChild(container);
117029 container.innerHTML = this.getFlashHTML(); // Using innerHTML is non-standard but the only sensible way to dynamically add Flash in IE (and maybe other browsers)
117030 };
117031
117032 // Private: replaceWithFlash replaces the button_placeholder element with the flash movie.
117033 SWFUpload.prototype.replaceWithFlash = function () {
117034 var targetElement, tempParent;
117035
117036 // Make sure an element with the ID we are going to use doesn't already exist
117037 if (document.getElementById(this.movieName) !== null) {
117038 throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
117039 }
117040
117041 // Get the element where we will be placing the flash movie
117042 targetElement = document.getElementById(this.settings.button_placeholder_id);
117043
117044 if (targetElement == undefined) {
117045 throw "Could not find the placeholder element.";
117046 }
117047
117048 // Append the container and load the flash
117049 tempParent = document.createElement("div");
117050 tempParent.innerHTML = this.getFlashHTML(); // Using innerHTML is non-standard but the only sensible way to dynamically add Flash in IE (and maybe other browsers)
117051 targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement);
117052
117053 };
117054
117055 // Private: getFlashHTML generates the object tag needed to embed the flash in to the document
117056 SWFUpload.prototype.getFlashHTML = function () {
117057 // Flash Satay object syntax: http://www.alistapart.com/articles/flashsatay
117058 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">',
117059 '<param name="wmode" value="', this.settings.button_window_mode , '" />',
117060 '<param name="movie" value="', this.settings.flash_url, '" />',
117061 '<param name="quality" value="high" />',
117062 '<param name="menu" value="false" />',
117063 '<param name="allowScriptAccess" value="always" />',
117064 '<param name="flashvars" value="' + this.getFlashVars() + '" />',
117065 '</object>'].join("");
117066 };
117067
117068 // Private: getFlashVars builds the parameter string that will be passed
117069 // to flash in the flashvars param.
117070 SWFUpload.prototype.getFlashVars = function () {
117071 // Build a string from the post param object
117072 var paramString = this.buildParamString();
117073 var httpSuccessString = this.settings.http_success.join(",");
117074
117075 // Build the parameter string
117076 return ["movieName=", encodeURIComponent(this.movieName),
117077 "&uploadURL=", encodeURIComponent(this.settings.upload_url),
117078 "&useQueryString=", encodeURIComponent(this.settings.use_query_string),
117079 "&requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),
117080 "&httpSuccess=", encodeURIComponent(httpSuccessString),
117081 "&params=", encodeURIComponent(paramString),
117082 "&filePostName=", encodeURIComponent(this.settings.file_post_name),
117083 "&fileTypes=", encodeURIComponent(this.settings.file_types),
117084 "&fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),
117085 "&fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),
117086 "&fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),
117087 "&fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),
117088 "&debugEnabled=", encodeURIComponent(this.settings.debug_enabled),
117089 "&buttonImageURL=", encodeURIComponent(this.settings.button_image_url),
117090 "&buttonWidth=", encodeURIComponent(this.settings.button_width),
117091 "&buttonHeight=", encodeURIComponent(this.settings.button_height),
117092 "&buttonText=", encodeURIComponent(this.settings.button_text),
117093 "&buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding),
117094 "&buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding),
117095 "&buttonTextStyle=", encodeURIComponent(this.settings.button_text_style),
117096 "&buttonAction=", encodeURIComponent(this.settings.button_action),
117097 "&buttonDisabled=", encodeURIComponent(this.settings.button_disabled),
117098 "&buttonCursor=", encodeURIComponent(this.settings.button_cursor)
117099 ].join("");
117100 };
117101
117102 // Public: getMovieElement retrieves the DOM reference to the Flash element added by SWFUpload
117103 // The element is cached after the first lookup
117104 SWFUpload.prototype.getMovieElement = function () {
117105 if (this.movieElement == undefined) {
117106 this.movieElement = document.getElementById(this.movieName);
117107 }
117108
117109 if (this.movieElement === null) {
117110 throw "Could not find Flash element";
117111 }
117112
117113 return this.movieElement;
117114 };
117115
117116 // Private: buildParamString takes the name/value pairs in the post_params setting object
117117 // and joins them up in to a string formatted "name=value&name=value"
117118 SWFUpload.prototype.buildParamString = function () {
117119 var postParams = this.settings.post_params;
117120 var paramStringPairs = [];
117121
117122 if (typeof(postParams) === "object") {
117123 for (var name in postParams) {
117124 if (postParams.hasOwnProperty(name)) {
117125 paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString()));
117126 }
117127 }
117128 }
117129
117130 return paramStringPairs.join("&");
117131 };
117132
117133 // Public: Used to remove a SWFUpload instance from the page. This method strives to remove
117134 // all references to the SWF, and other objects so memory is properly freed.
117135 // Returns true if everything was destroyed. Returns a false if a failure occurs leaving SWFUpload in an inconsistant state.
117136 SWFUpload.prototype.destroy = function () {
117137 try {
117138 // Make sure Flash is done before we try to remove it
117139 this.stopUpload();
117140
117141 // Remove the SWFUpload DOM nodes
117142 var movieElement = null;
117143 try {
117144 movieElement = this.getMovieElement();
117145 } catch (ex) {
117146 }
117147
117148 if (movieElement != undefined && movieElement.parentNode != undefined && typeof movieElement.parentNode.removeChild === "function") {
117149 var container = movieElement.parentNode;
117150 if (container != undefined) {
117151 container.removeChild(movieElement);
117152 if (container.parentNode != undefined && typeof container.parentNode.removeChild === "function") {
117153 container.parentNode.removeChild(container);
117154 }
117155 }
117156 }
117157
117158 // Destroy references
117159 SWFUpload.instances[this.movieName] = null;
117160 delete SWFUpload.instances[this.movieName];
117161
117162 delete this.movieElement;
117163 delete this.settings;
117164 delete this.customSettings;
117165 delete this.eventQueue;
117166 delete this.movieName;
117167
117168 delete window[this.movieName];
117169
117170 return true;
117171 } catch (ex1) {
117172 return false;
117173 }
117174 };
117175
117176 // Public: displayDebugInfo prints out settings and configuration
117177 // information about this SWFUpload instance.
117178 // This function (and any references to it) can be deleted when placing
117179 // SWFUpload in production.
117180 SWFUpload.prototype.displayDebugInfo = function () {
117181 this.debug(
117182 [
117183 "---SWFUpload Instance Info---\n",
117184 "Version: ", SWFUpload.version, "\n",
117185 "Movie Name: ", this.movieName, "\n",
117186 "Settings:\n",
117187 "\t", "upload_url: ", this.settings.upload_url, "\n",
117188 "\t", "flash_url: ", this.settings.flash_url, "\n",
117189 "\t", "use_query_string: ", this.settings.use_query_string.toString(), "\n",
117190 "\t", "requeue_on_error: ", this.settings.requeue_on_error.toString(), "\n",
117191 "\t", "http_success: ", this.settings.http_success.join(", "), "\n",
117192 "\t", "file_post_name: ", this.settings.file_post_name, "\n",
117193 "\t", "post_params: ", this.settings.post_params.toString(), "\n",
117194 "\t", "file_types: ", this.settings.file_types, "\n",
117195 "\t", "file_types_description: ", this.settings.file_types_description, "\n",
117196 "\t", "file_size_limit: ", this.settings.file_size_limit, "\n",
117197 "\t", "file_upload_limit: ", this.settings.file_upload_limit, "\n",
117198 "\t", "file_queue_limit: ", this.settings.file_queue_limit, "\n",
117199 "\t", "debug: ", this.settings.debug.toString(), "\n",
117200
117201 "\t", "prevent_swf_caching: ", this.settings.prevent_swf_caching.toString(), "\n",
117202
117203 "\t", "button_placeholder_id: ", this.settings.button_placeholder_id.toString(), "\n",
117204 "\t", "button_image_url: ", this.settings.button_image_url.toString(), "\n",
117205 "\t", "button_width: ", this.settings.button_width.toString(), "\n",
117206 "\t", "button_height: ", this.settings.button_height.toString(), "\n",
117207 "\t", "button_text: ", this.settings.button_text.toString(), "\n",
117208 "\t", "button_text_style: ", this.settings.button_text_style.toString(), "\n",
117209 "\t", "button_text_top_padding: ", this.settings.button_text_top_padding.toString(), "\n",
117210 "\t", "button_text_left_padding: ", this.settings.button_text_left_padding.toString(), "\n",
117211 "\t", "button_action: ", this.settings.button_action.toString(), "\n",
117212 "\t", "button_disabled: ", this.settings.button_disabled.toString(), "\n",
117213
117214 "\t", "custom_settings: ", this.settings.custom_settings.toString(), "\n",
117215 "Event Handlers:\n",
117216 "\t", "swfupload_loaded_handler assigned: ", (typeof this.settings.swfupload_loaded_handler === "function").toString(), "\n",
117217 "\t", "file_dialog_start_handler assigned: ", (typeof this.settings.file_dialog_start_handler === "function").toString(), "\n",
117218 "\t", "file_queued_handler assigned: ", (typeof this.settings.file_queued_handler === "function").toString(), "\n",
117219 "\t", "file_queue_error_handler assigned: ", (typeof this.settings.file_queue_error_handler === "function").toString(), "\n",
117220 "\t", "upload_start_handler assigned: ", (typeof this.settings.upload_start_handler === "function").toString(), "\n",
117221 "\t", "upload_progress_handler assigned: ", (typeof this.settings.upload_progress_handler === "function").toString(), "\n",
117222 "\t", "upload_error_handler assigned: ", (typeof this.settings.upload_error_handler === "function").toString(), "\n",
117223 "\t", "upload_success_handler assigned: ", (typeof this.settings.upload_success_handler === "function").toString(), "\n",
117224 "\t", "upload_complete_handler assigned: ", (typeof this.settings.upload_complete_handler === "function").toString(), "\n",
117225 "\t", "debug_handler assigned: ", (typeof this.settings.debug_handler === "function").toString(), "\n"
117226 ].join("")
117227 );
117228 };
117229
117230 /* Note: addSetting and getSetting are no longer used by SWFUpload but are included
117231 the maintain v2 API compatibility
117232 */
117233 // Public: (Deprecated) addSetting adds a setting value. If the value given is undefined or null then the default_value is used.
117234 SWFUpload.prototype.addSetting = function (name, value, default_value) {
117235 if (value == undefined) {
117236 return (this.settings[name] = default_value);
117237 } else {
117238 return (this.settings[name] = value);
117239 }
117240 };
117241
117242 // Public: (Deprecated) getSetting gets a setting. Returns an empty string if the setting was not found.
117243 SWFUpload.prototype.getSetting = function (name) {
117244 if (this.settings[name] != undefined) {
117245 return this.settings[name];
117246 }
117247
117248 return "";
117249 };
117250
117251
117252
117253 // Private: callFlash handles function calls made to the Flash element.
117254 // Calls are made with a setTimeout for some functions to work around
117255 // bugs in the ExternalInterface library.
117256 SWFUpload.prototype.callFlash = function (functionName, argumentArray) {
117257 argumentArray = argumentArray || [];
117258
117259 var movieElement = this.getMovieElement();
117260 var returnValue;
117261
117262 if (typeof movieElement[functionName] === "function") {
117263 // We have to go through all this if/else stuff because the Flash functions don't have apply() and only accept the exact number of arguments.
117264 if (argumentArray.length === 0) {
117265 returnValue = movieElement[functionName]();
117266 } else if (argumentArray.length === 1) {
117267 returnValue = movieElement[functionName](argumentArray[0]);
117268 } else if (argumentArray.length === 2) {
117269 returnValue = movieElement[functionName](argumentArray[0], argumentArray[1]);
117270 } else if (argumentArray.length === 3) {
117271 returnValue = movieElement[functionName](argumentArray[0], argumentArray[1], argumentArray[2]);
117272 } else {
117273 throw "Too many arguments";
117274 }
117275
117276 // Unescape file post param values
117277 if (returnValue != undefined && typeof returnValue.post === "object") {
117278 returnValue = this.unescapeFilePostParams(returnValue);
117279 }
117280
117281 return returnValue;
117282 } else {
117283 throw "Invalid function name: " + functionName;
117284 }
117285 };
117286
117287
117288 /* *****************************
117289 -- Flash control methods --
117290 Your UI should use these
117291 to operate SWFUpload
117292 ***************************** */
117293
117294 // Public: selectFile causes a File Selection Dialog window to appear. This
117295 // dialog only allows 1 file to be selected. WARNING: this function does not work in Flash Player 10
117296 SWFUpload.prototype.selectFile = function () {
117297 this.callFlash("SelectFile");
117298 };
117299
117300 // Public: selectFiles causes a File Selection Dialog window to appear/ This
117301 // dialog allows the user to select any number of files
117302 // Flash Bug Warning: Flash limits the number of selectable files based on the combined length of the file names.
117303 // If the selection name length is too long the dialog will fail in an unpredictable manner. There is no work-around
117304 // for this bug. WARNING: this function does not work in Flash Player 10
117305 SWFUpload.prototype.selectFiles = function () {
117306 this.callFlash("SelectFiles");
117307 };
117308
117309
117310 // Public: startUpload starts uploading the first file in the queue unless
117311 // the optional parameter 'fileID' specifies the ID
117312 SWFUpload.prototype.startUpload = function (fileID) {
117313 this.callFlash("StartUpload", [fileID]);
117314 };
117315
117316 // Public: cancelUpload cancels any queued file. The fileID parameter may be the file ID or index.
117317 // If you do not specify a fileID the current uploading file or first file in the queue is cancelled.
117318 // If you do not want the uploadError event to trigger you can specify false for the triggerErrorEvent parameter.
117319 SWFUpload.prototype.cancelUpload = function (fileID, triggerErrorEvent) {
117320 if (triggerErrorEvent !== false) {
117321 triggerErrorEvent = true;
117322 }
117323 this.callFlash("CancelUpload", [fileID, triggerErrorEvent]);
117324 };
117325
117326 // Public: stopUpload stops the current upload and requeues the file at the beginning of the queue.
117327 // If nothing is currently uploading then nothing happens.
117328 SWFUpload.prototype.stopUpload = function () {
117329 this.callFlash("StopUpload");
117330 };
117331
117332 /* ************************
117333 * Settings methods
117334 * These methods change the SWFUpload settings.
117335 * SWFUpload settings should not be changed directly on the settings object
117336 * since many of the settings need to be passed to Flash in order to take
117337 * effect.
117338 * *********************** */
117339
117340 // Public: getStats gets the file statistics object.
117341 SWFUpload.prototype.getStats = function () {
117342 return this.callFlash("GetStats");
117343 };
117344
117345 // Public: setStats changes the SWFUpload statistics. You shouldn't need to
117346 // change the statistics but you can. Changing the statistics does not
117347 // affect SWFUpload accept for the successful_uploads count which is used
117348 // by the upload_limit setting to determine how many files the user may upload.
117349 SWFUpload.prototype.setStats = function (statsObject) {
117350 this.callFlash("SetStats", [statsObject]);
117351 };
117352
117353 // Public: getFile retrieves a File object by ID or Index. If the file is
117354 // not found then 'null' is returned.
117355 SWFUpload.prototype.getFile = function (fileID) {
117356 if (typeof(fileID) === "number") {
117357 return this.callFlash("GetFileByIndex", [fileID]);
117358 } else {
117359 return this.callFlash("GetFile", [fileID]);
117360 }
117361 };
117362
117363 // Public: addFileParam sets a name/value pair that will be posted with the
117364 // file specified by the Files ID. If the name already exists then the
117365 // exiting value will be overwritten.
117366 SWFUpload.prototype.addFileParam = function (fileID, name, value) {
117367 return this.callFlash("AddFileParam", [fileID, name, value]);
117368 };
117369
117370 // Public: removeFileParam removes a previously set (by addFileParam) name/value
117371 // pair from the specified file.
117372 SWFUpload.prototype.removeFileParam = function (fileID, name) {
117373 this.callFlash("RemoveFileParam", [fileID, name]);
117374 };
117375
117376 // Public: setUploadUrl changes the upload_url setting.
117377 SWFUpload.prototype.setUploadURL = function (url) {
117378 this.settings.upload_url = url.toString();
117379 this.callFlash("SetUploadURL", [url]);
117380 };
117381
117382 // Public: setPostParams changes the post_params setting
117383 SWFUpload.prototype.setPostParams = function (paramsObject) {
117384 this.settings.post_params = paramsObject;
117385 this.callFlash("SetPostParams", [paramsObject]);
117386 };
117387
117388 // Public: addPostParam adds post name/value pair. Each name can have only one value.
117389 SWFUpload.prototype.addPostParam = function (name, value) {
117390 this.settings.post_params[name] = value;
117391 this.callFlash("SetPostParams", [this.settings.post_params]);
117392 };
117393
117394 // Public: removePostParam deletes post name/value pair.
117395 SWFUpload.prototype.removePostParam = function (name) {
117396 delete this.settings.post_params[name];
117397 this.callFlash("SetPostParams", [this.settings.post_params]);
117398 };
117399
117400 // Public: setFileTypes changes the file_types setting and the file_types_description setting
117401 SWFUpload.prototype.setFileTypes = function (types, description) {
117402 this.settings.file_types = types;
117403 this.settings.file_types_description = description;
117404 this.callFlash("SetFileTypes", [types, description]);
117405 };
117406
117407 // Public: setFileSizeLimit changes the file_size_limit setting
117408 SWFUpload.prototype.setFileSizeLimit = function (fileSizeLimit) {
117409 this.settings.file_size_limit = fileSizeLimit;
117410 this.callFlash("SetFileSizeLimit", [fileSizeLimit]);
117411 };
117412
117413 // Public: setFileUploadLimit changes the file_upload_limit setting
117414 SWFUpload.prototype.setFileUploadLimit = function (fileUploadLimit) {
117415 this.settings.file_upload_limit = fileUploadLimit;
117416 this.callFlash("SetFileUploadLimit", [fileUploadLimit]);
117417 };
117418
117419 // Public: setFileQueueLimit changes the file_queue_limit setting
117420 SWFUpload.prototype.setFileQueueLimit = function (fileQueueLimit) {
117421 this.settings.file_queue_limit = fileQueueLimit;
117422 this.callFlash("SetFileQueueLimit", [fileQueueLimit]);
117423 };
117424
117425 // Public: setFilePostName changes the file_post_name setting
117426 SWFUpload.prototype.setFilePostName = function (filePostName) {
117427 this.settings.file_post_name = filePostName;
117428 this.callFlash("SetFilePostName", [filePostName]);
117429 };
117430
117431 // Public: setUseQueryString changes the use_query_string setting
117432 SWFUpload.prototype.setUseQueryString = function (useQueryString) {
117433 this.settings.use_query_string = useQueryString;
117434 this.callFlash("SetUseQueryString", [useQueryString]);
117435 };
117436
117437 // Public: setRequeueOnError changes the requeue_on_error setting
117438 SWFUpload.prototype.setRequeueOnError = function (requeueOnError) {
117439 this.settings.requeue_on_error = requeueOnError;
117440 this.callFlash("SetRequeueOnError", [requeueOnError]);
117441 };
117442
117443 // Public: setHTTPSuccess changes the http_success setting
117444 SWFUpload.prototype.setHTTPSuccess = function (http_status_codes) {
117445 if (typeof http_status_codes === "string") {
117446 http_status_codes = http_status_codes.replace(" ", "").split(",");
117447 }
117448
117449 this.settings.http_success = http_status_codes;
117450 this.callFlash("SetHTTPSuccess", [http_status_codes]);
117451 };
117452
117453
117454 // Public: setDebugEnabled changes the debug_enabled setting
117455 SWFUpload.prototype.setDebugEnabled = function (debugEnabled) {
117456 this.settings.debug_enabled = debugEnabled;
117457 this.callFlash("SetDebugEnabled", [debugEnabled]);
117458 };
117459
117460 // Public: setButtonImageURL loads a button image sprite
117461 SWFUpload.prototype.setButtonImageURL = function (buttonImageURL) {
117462 if (buttonImageURL == undefined) {
117463 buttonImageURL = "";
117464 }
117465
117466 this.settings.button_image_url = buttonImageURL;
117467 this.callFlash("SetButtonImageURL", [buttonImageURL]);
117468 };
117469
117470 // Public: setButtonDimensions resizes the Flash Movie and button
117471 SWFUpload.prototype.setButtonDimensions = function (width, height) {
117472 this.settings.button_width = width;
117473 this.settings.button_height = height;
117474
117475 var movie = this.getMovieElement();
117476 if (movie != undefined) {
117477 movie.style.width = width + "px";
117478 movie.style.height = height + "px";
117479 }
117480
117481 this.callFlash("SetButtonDimensions", [width, height]);
117482 };
117483 // Public: setButtonText Changes the text overlaid on the button
117484 SWFUpload.prototype.setButtonText = function (html) {
117485 this.settings.button_text = html;
117486 this.callFlash("SetButtonText", [html]);
117487 };
117488 // Public: setButtonTextPadding changes the top and left padding of the text overlay
117489 SWFUpload.prototype.setButtonTextPadding = function (left, top) {
117490 this.settings.button_text_top_padding = top;
117491 this.settings.button_text_left_padding = left;
117492 this.callFlash("SetButtonTextPadding", [left, top]);
117493 };
117494
117495 // Public: setButtonTextStyle changes the CSS used to style the HTML/Text overlaid on the button
117496 SWFUpload.prototype.setButtonTextStyle = function (css) {
117497 this.settings.button_text_style = css;
117498 this.callFlash("SetButtonTextStyle", [css]);
117499 };
117500 // Public: setButtonDisabled disables/enables the button
117501 SWFUpload.prototype.setButtonDisabled = function (isDisabled) {
117502 this.settings.button_disabled = isDisabled;
117503 this.callFlash("SetButtonDisabled", [isDisabled]);
117504 };
117505 // Public: setButtonAction sets the action that occurs when the button is clicked
117506 SWFUpload.prototype.setButtonAction = function (buttonAction) {
117507 this.settings.button_action = buttonAction;
117508 this.callFlash("SetButtonAction", [buttonAction]);
117509 };
117510
117511 // Public: setButtonCursor changes the mouse cursor displayed when hovering over the button
117512 SWFUpload.prototype.setButtonCursor = function (cursor) {
117513 this.settings.button_cursor = cursor;
117514 this.callFlash("SetButtonCursor", [cursor]);
117515 };
117516
117517 /* *******************************
117518 Flash Event Interfaces
117519 These functions are used by Flash to trigger the various
117520 events.
117521
117522 All these functions a Private.
117523
117524 Because the ExternalInterface library is buggy the event calls
117525 are added to a queue and the queue then executed by a setTimeout.
117526 This ensures that events are executed in a determinate order and that
117527 the ExternalInterface bugs are avoided.
117528 ******************************* */
117529
117530 SWFUpload.prototype.queueEvent = function (handlerName, argumentArray) {
117531 // Warning: Don't call this.debug inside here or you'll create an infinite loop
117532
117533 if (argumentArray == undefined) {
117534 argumentArray = [];
117535 } else if (!(argumentArray instanceof Array)) {
117536 argumentArray = [argumentArray];
117537 }
117538
117539 var self = this;
117540 if (typeof this.settings[handlerName] === "function") {
117541 // Queue the event
117542 this.eventQueue.push(function () {
117543 this.settings[handlerName].apply(this, argumentArray);
117544 });
117545
117546 // Execute the next queued event
117547 setTimeout(function () {
117548 self.executeNextEvent();
117549 }, 0);
117550
117551 } else if (this.settings[handlerName] !== null) {
117552 throw "Event handler " + handlerName + " is unknown or is not a function";
117553 }
117554 };
117555
117556 // Private: Causes the next event in the queue to be executed. Since events are queued using a setTimeout
117557 // we must queue them in order to garentee that they are executed in order.
117558 SWFUpload.prototype.executeNextEvent = function () {
117559 // Warning: Don't call this.debug inside here or you'll create an infinite loop
117560
117561 var f = this.eventQueue ? this.eventQueue.shift() : null;
117562 if (typeof(f) === "function") {
117563 f.apply(this);
117564 }
117565 };
117566
117567 // Private: unescapeFileParams is part of a workaround for a flash bug where objects passed through ExternalInterface cannot have
117568 // properties that contain characters that are not valid for JavaScript identifiers. To work around this
117569 // the Flash Component escapes the parameter names and we must unescape again before passing them along.
117570 SWFUpload.prototype.unescapeFilePostParams = function (file) {
117571 var reg = /[$]([0-9a-f]{4})/i;
117572 var unescapedPost = {};
117573 var uk;
117574
117575 if (file != undefined) {
117576 for (var k in file.post) {
117577 if (file.post.hasOwnProperty(k)) {
117578 uk = k;
117579 var match;
117580 while ((match = reg.exec(uk)) !== null) {
117581 uk = uk.replace(match[0], String.fromCharCode(parseInt("0x" + match[1], 16)));
117582 }
117583 unescapedPost[uk] = file.post[k];
117584 }
117585 }
117586
117587 file.post = unescapedPost;
117588 }
117589
117590 return file;
117591 };
117592
117593 SWFUpload.prototype.flashReady = function () {
117594 // Check that the movie element is loaded correctly with its ExternalInterface methods defined
117595 var movieElement = this.getMovieElement();
117596 if (typeof movieElement.StartUpload !== "function") {
117597 throw "ExternalInterface methods failed to initialize.";
117598 }
117599
117600 // Fix IE Flash/Form bug
117601 if (window[this.movieName] == undefined) {
117602 window[this.movieName] = movieElement;
117603 }
117604
117605 this.queueEvent("swfupload_loaded_handler");
117606 };
117607
117608
117609 /* This is a chance to do something before the browse window opens */
117610 SWFUpload.prototype.fileDialogStart = function () {
117611 this.queueEvent("file_dialog_start_handler");
117612 };
117613
117614
117615 /* Called when a file is successfully added to the queue. */
117616 SWFUpload.prototype.fileQueued = function (file) {
117617 file = this.unescapeFilePostParams(file);
117618 this.queueEvent("file_queued_handler", file);
117619 };
117620
117621
117622 /* Handle errors that occur when an attempt to queue a file fails. */
117623 SWFUpload.prototype.fileQueueError = function (file, errorCode, message) {
117624 file = this.unescapeFilePostParams(file);
117625 this.queueEvent("file_queue_error_handler", [file, errorCode, message]);
117626 };
117627
117628 /* Called after the file dialog has closed and the selected files have been queued.
117629 You could call startUpload here if you want the queued files to begin uploading immediately. */
117630 SWFUpload.prototype.fileDialogComplete = function (numFilesSelected, numFilesQueued) {
117631 this.queueEvent("file_dialog_complete_handler", [numFilesSelected, numFilesQueued]);
117632 };
117633
117634 SWFUpload.prototype.uploadStart = function (file) {
117635 file = this.unescapeFilePostParams(file);
117636 this.queueEvent("return_upload_start_handler", file);
117637 };
117638
117639 SWFUpload.prototype.returnUploadStart = function (file) {
117640 var returnValue;
117641 if (typeof this.settings.upload_start_handler === "function") {
117642 file = this.unescapeFilePostParams(file);
117643 returnValue = this.settings.upload_start_handler.call(this, file);
117644 } else if (this.settings.upload_start_handler != undefined) {
117645 throw "upload_start_handler must be a function";
117646 }
117647
117648 // Convert undefined to true so if nothing is returned from the upload_start_handler it is
117649 // interpretted as 'true'.
117650 if (returnValue === undefined) {
117651 returnValue = true;
117652 }
117653
117654 returnValue = !!returnValue;
117655
117656 this.callFlash("ReturnUploadStart", [returnValue]);
117657 };
117658
117659
117660
117661 SWFUpload.prototype.uploadProgress = function (file, bytesComplete, bytesTotal) {
117662 file = this.unescapeFilePostParams(file);
117663 this.queueEvent("upload_progress_handler", [file, bytesComplete, bytesTotal]);
117664 };
117665
117666 SWFUpload.prototype.uploadError = function (file, errorCode, message) {
117667 file = this.unescapeFilePostParams(file);
117668 this.queueEvent("upload_error_handler", [file, errorCode, message]);
117669 };
117670
117671 SWFUpload.prototype.uploadSuccess = function (file, serverData) {
117672 file = this.unescapeFilePostParams(file);
117673 this.queueEvent("upload_success_handler", [file, serverData]);
117674 };
117675
117676 SWFUpload.prototype.uploadComplete = function (file) {
117677 file = this.unescapeFilePostParams(file);
117678 this.queueEvent("upload_complete_handler", file);
117679 };
117680
117681 /* Called by SWFUpload JavaScript and Flash functions when debug is enabled. By default it writes messages to the
117682 internal debug console. You can override this event and have messages written where you want. */
117683 SWFUpload.prototype.debug = function (message) {
117684 this.queueEvent("debug_handler", message);
117685 };
117686
117687
117688 /* **********************************
117689 Debug Console
117690 The debug console is a self contained, in page location
117691 for debug message to be sent. The Debug Console adds
117692 itself to the body if necessary.
117693
117694 The console is automatically scrolled as messages appear.
117695
117696 If you are using your own debug handler or when you deploy to production and
117697 have debug disabled you can remove these functions to reduce the file size
117698 and complexity.
117699 ********************************** */
117700
117701 // Private: debugMessage is the default debug_handler. If you want to print debug messages
117702 // call the debug() function. When overriding the function your own function should
117703 // check to see if the debug setting is true before outputting debug information.
117704 SWFUpload.prototype.debugMessage = function (message) {
117705 if (this.settings.debug) {
117706 var exceptionMessage, exceptionValues = [];
117707
117708 // Check for an exception object and print it nicely
117709 if (typeof message === "object" && typeof message.name === "string" && typeof message.message === "string") {
117710 for (var key in message) {
117711 if (message.hasOwnProperty(key)) {
117712 exceptionValues.push(key + ": " + message[key]);
117713 }
117714 }
117715 exceptionMessage = exceptionValues.join("\n") || "";
117716 exceptionValues = exceptionMessage.split("\n");
117717 exceptionMessage = "EXCEPTION: " + exceptionValues.join("\nEXCEPTION: ");
117718 SWFUpload.Console.writeLine(exceptionMessage);
117719 } else {
117720 SWFUpload.Console.writeLine(message);
117721 }
117722 }
117723 };
117724
117725 SWFUpload.Console = {};
117726 SWFUpload.Console.writeLine = function (message) {
117727 var console, documentForm;
117728
117729 try {
117730 console = document.getElementById("SWFUpload_Console");
117731
117732 if (!console) {
117733 documentForm = document.createElement("form");
117734 document.getElementsByTagName("body")[0].appendChild(documentForm);
117735
117736 console = document.createElement("textarea");
117737 console.id = "SWFUpload_Console";
117738 console.style.fontFamily = "monospace";
117739 console.setAttribute("wrap", "off");
117740 console.wrap = "off";
117741 console.style.overflow = "auto";
117742 console.style.width = "700px";
117743 console.style.height = "350px";
117744 console.style.margin = "5px";
117745 documentForm.appendChild(console);
117746 }
117747
117748 console.value += message + "\n";
117749
117750 console.scrollTop = console.scrollHeight - console.clientHeight;
117751 } catch (ex) {
117752 alert("Exception: " + ex.name + " Message: " + ex.message);
117753 }
117754 };