raw
mp-wp_genesis           1 /**
mp-wp_genesis 2 * SWFUpload: http://www.swfupload.org, http://swfupload.googlecode.com
mp-wp_genesis 3 *
mp-wp_genesis 4 * mmSWFUpload 1.0: Flash upload dialog - http://profandesign.se/swfupload/, http://www.vinterwebb.se/
mp-wp_genesis 5 *
mp-wp_genesis 6 * SWFUpload is (c) 2006-2007 Lars Huring, Olov Nilzen and Mammon Media and is released under the MIT License:
mp-wp_genesis 7 * http://www.opensource.org/licenses/mit-license.php
mp-wp_genesis 8 *
mp-wp_genesis 9 * SWFUpload 2 is (c) 2007-2008 Jake Roberts and is released under the MIT License:
mp-wp_genesis 10 * http://www.opensource.org/licenses/mit-license.php
mp-wp_genesis 11 *
mp-wp_genesis 12 */
mp-wp_genesis 13
mp-wp_genesis 14
mp-wp_genesis 15 /* ******************* */
mp-wp_genesis 16 /* Constructor & Init */
mp-wp_genesis 17 /* ******************* */
mp-wp_genesis 18 var SWFUpload;
mp-wp_genesis 19
mp-wp_genesis 20 if (SWFUpload == undefined) {
mp-wp_genesis 21 SWFUpload = function (settings) {
mp-wp_genesis 22 this.initSWFUpload(settings);
mp-wp_genesis 23 };
mp-wp_genesis 24 }
mp-wp_genesis 25
mp-wp_genesis 26 SWFUpload.prototype.initSWFUpload = function (settings) {
mp-wp_genesis 27 try {
mp-wp_genesis 28 this.customSettings = {}; // A container where developers can place their own settings associated with this instance.
mp-wp_genesis 29 this.settings = settings;
mp-wp_genesis 30 this.eventQueue = [];
mp-wp_genesis 31 this.movieName = "SWFUpload_" + SWFUpload.movieCount++;
mp-wp_genesis 32 this.movieElement = null;
mp-wp_genesis 33
mp-wp_genesis 34 // Setup global control tracking
mp-wp_genesis 35 SWFUpload.instances[this.movieName] = this;
mp-wp_genesis 36
mp-wp_genesis 37 // Load the settings. Load the Flash movie.
mp-wp_genesis 38 this.initSettings();
mp-wp_genesis 39 this.loadFlash();
mp-wp_genesis 40 this.displayDebugInfo();
mp-wp_genesis 41 } catch (ex) {
mp-wp_genesis 42 delete SWFUpload.instances[this.movieName];
mp-wp_genesis 43 throw ex;
mp-wp_genesis 44 }
mp-wp_genesis 45 };
mp-wp_genesis 46
mp-wp_genesis 47 /* *************** */
mp-wp_genesis 48 /* Static Members */
mp-wp_genesis 49 /* *************** */
mp-wp_genesis 50 SWFUpload.instances = {};
mp-wp_genesis 51 SWFUpload.movieCount = 0;
mp-wp_genesis 52 SWFUpload.version = "2.2.0 Beta 2";
mp-wp_genesis 53 SWFUpload.QUEUE_ERROR = {
mp-wp_genesis 54 QUEUE_LIMIT_EXCEEDED : -100,
mp-wp_genesis 55 FILE_EXCEEDS_SIZE_LIMIT : -110,
mp-wp_genesis 56 ZERO_BYTE_FILE : -120,
mp-wp_genesis 57 INVALID_FILETYPE : -130
mp-wp_genesis 58 };
mp-wp_genesis 59 SWFUpload.UPLOAD_ERROR = {
mp-wp_genesis 60 HTTP_ERROR : -200,
mp-wp_genesis 61 MISSING_UPLOAD_URL : -210,
mp-wp_genesis 62 IO_ERROR : -220,
mp-wp_genesis 63 SECURITY_ERROR : -230,
mp-wp_genesis 64 UPLOAD_LIMIT_EXCEEDED : -240,
mp-wp_genesis 65 UPLOAD_FAILED : -250,
mp-wp_genesis 66 SPECIFIED_FILE_ID_NOT_FOUND : -260,
mp-wp_genesis 67 FILE_VALIDATION_FAILED : -270,
mp-wp_genesis 68 FILE_CANCELLED : -280,
mp-wp_genesis 69 UPLOAD_STOPPED : -290
mp-wp_genesis 70 };
mp-wp_genesis 71 SWFUpload.FILE_STATUS = {
mp-wp_genesis 72 QUEUED : -1,
mp-wp_genesis 73 IN_PROGRESS : -2,
mp-wp_genesis 74 ERROR : -3,
mp-wp_genesis 75 COMPLETE : -4,
mp-wp_genesis 76 CANCELLED : -5
mp-wp_genesis 77 };
mp-wp_genesis 78 SWFUpload.BUTTON_ACTION = {
mp-wp_genesis 79 SELECT_FILE : -100,
mp-wp_genesis 80 SELECT_FILES : -110,
mp-wp_genesis 81 START_UPLOAD : -120
mp-wp_genesis 82 };
mp-wp_genesis 83 SWFUpload.CURSOR = {
mp-wp_genesis 84 ARROW : -1,
mp-wp_genesis 85 HAND : -2
mp-wp_genesis 86 };
mp-wp_genesis 87 SWFUpload.WINDOW_MODE = {
mp-wp_genesis 88 WINDOW : "window",
mp-wp_genesis 89 TRANSPARENT : "transparent",
mp-wp_genesis 90 OPAQUE : "opaque"
mp-wp_genesis 91 };
mp-wp_genesis 92
mp-wp_genesis 93 /* ******************** */
mp-wp_genesis 94 /* Instance Members */
mp-wp_genesis 95 /* ******************** */
mp-wp_genesis 96
mp-wp_genesis 97 // Private: initSettings ensures that all the
mp-wp_genesis 98 // settings are set, getting a default value if one was not assigned.
mp-wp_genesis 99 SWFUpload.prototype.initSettings = function () {
mp-wp_genesis 100 this.ensureDefault = function (settingName, defaultValue) {
mp-wp_genesis 101 this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
mp-wp_genesis 102 };
mp-wp_genesis 103
mp-wp_genesis 104 // Upload backend settings
mp-wp_genesis 105 this.ensureDefault("upload_url", "");
mp-wp_genesis 106 this.ensureDefault("file_post_name", "Filedata");
mp-wp_genesis 107 this.ensureDefault("post_params", {});
mp-wp_genesis 108 this.ensureDefault("use_query_string", false);
mp-wp_genesis 109 this.ensureDefault("requeue_on_error", false);
mp-wp_genesis 110 this.ensureDefault("http_success", []);
mp-wp_genesis 111
mp-wp_genesis 112 // File Settings
mp-wp_genesis 113 this.ensureDefault("file_types", "*.*");
mp-wp_genesis 114 this.ensureDefault("file_types_description", "All Files");
mp-wp_genesis 115 this.ensureDefault("file_size_limit", 0); // Default zero means "unlimited"
mp-wp_genesis 116 this.ensureDefault("file_upload_limit", 0);
mp-wp_genesis 117 this.ensureDefault("file_queue_limit", 0);
mp-wp_genesis 118
mp-wp_genesis 119 // Flash Settings
mp-wp_genesis 120 this.ensureDefault("flash_url", "swfupload.swf");
mp-wp_genesis 121 this.ensureDefault("prevent_swf_caching", true);
mp-wp_genesis 122
mp-wp_genesis 123 // Button Settings
mp-wp_genesis 124 this.ensureDefault("button_image_url", "");
mp-wp_genesis 125 this.ensureDefault("button_width", 1);
mp-wp_genesis 126 this.ensureDefault("button_height", 1);
mp-wp_genesis 127 this.ensureDefault("button_text", "");
mp-wp_genesis 128 this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;");
mp-wp_genesis 129 this.ensureDefault("button_text_top_padding", 0);
mp-wp_genesis 130 this.ensureDefault("button_text_left_padding", 0);
mp-wp_genesis 131 this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES);
mp-wp_genesis 132 this.ensureDefault("button_disabled", false);
mp-wp_genesis 133 this.ensureDefault("button_placeholder_id", null);
mp-wp_genesis 134 this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW);
mp-wp_genesis 135 this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW);
mp-wp_genesis 136
mp-wp_genesis 137 // Debug Settings
mp-wp_genesis 138 this.ensureDefault("debug", false);
mp-wp_genesis 139 this.settings.debug_enabled = this.settings.debug; // Here to maintain v2 API
mp-wp_genesis 140
mp-wp_genesis 141 // Event Handlers
mp-wp_genesis 142 this.settings.return_upload_start_handler = this.returnUploadStart;
mp-wp_genesis 143 this.ensureDefault("swfupload_loaded_handler", null);
mp-wp_genesis 144 this.ensureDefault("file_dialog_start_handler", null);
mp-wp_genesis 145 this.ensureDefault("file_queued_handler", null);
mp-wp_genesis 146 this.ensureDefault("file_queue_error_handler", null);
mp-wp_genesis 147 this.ensureDefault("file_dialog_complete_handler", null);
mp-wp_genesis 148
mp-wp_genesis 149 this.ensureDefault("upload_start_handler", null);
mp-wp_genesis 150 this.ensureDefault("upload_progress_handler", null);
mp-wp_genesis 151 this.ensureDefault("upload_error_handler", null);
mp-wp_genesis 152 this.ensureDefault("upload_success_handler", null);
mp-wp_genesis 153 this.ensureDefault("upload_complete_handler", null);
mp-wp_genesis 154
mp-wp_genesis 155 this.ensureDefault("debug_handler", this.debugMessage);
mp-wp_genesis 156
mp-wp_genesis 157 this.ensureDefault("custom_settings", {});
mp-wp_genesis 158
mp-wp_genesis 159 // Other settings
mp-wp_genesis 160 this.customSettings = this.settings.custom_settings;
mp-wp_genesis 161
mp-wp_genesis 162 // Update the flash url if needed
mp-wp_genesis 163 if (this.settings.prevent_swf_caching) {
mp-wp_genesis 164 this.settings.flash_url = this.settings.flash_url + "?swfuploadrnd=" + Math.floor(Math.random() * 999999999);
mp-wp_genesis 165 }
mp-wp_genesis 166
mp-wp_genesis 167 delete this.ensureDefault;
mp-wp_genesis 168 };
mp-wp_genesis 169
mp-wp_genesis 170 SWFUpload.prototype.loadFlash = function () {
mp-wp_genesis 171 if (this.settings.button_placeholder_id !== "") {
mp-wp_genesis 172 this.replaceWithFlash();
mp-wp_genesis 173 } else {
mp-wp_genesis 174 this.appendFlash();
mp-wp_genesis 175 }
mp-wp_genesis 176 };
mp-wp_genesis 177
mp-wp_genesis 178 // Private: appendFlash gets the HTML tag for the Flash
mp-wp_genesis 179 // It then appends the flash to the body
mp-wp_genesis 180 SWFUpload.prototype.appendFlash = function () {
mp-wp_genesis 181 var targetElement, container;
mp-wp_genesis 182
mp-wp_genesis 183 // Make sure an element with the ID we are going to use doesn't already exist
mp-wp_genesis 184 if (document.getElementById(this.movieName) !== null) {
mp-wp_genesis 185 throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
mp-wp_genesis 186 }
mp-wp_genesis 187
mp-wp_genesis 188 // Get the body tag where we will be adding the flash movie
mp-wp_genesis 189 targetElement = document.getElementsByTagName("body")[0];
mp-wp_genesis 190
mp-wp_genesis 191 if (targetElement == undefined) {
mp-wp_genesis 192 throw "Could not find the 'body' element.";
mp-wp_genesis 193 }
mp-wp_genesis 194
mp-wp_genesis 195 // Append the container and load the flash
mp-wp_genesis 196 container = document.createElement("div");
mp-wp_genesis 197 container.style.width = "1px";
mp-wp_genesis 198 container.style.height = "1px";
mp-wp_genesis 199 container.style.overflow = "hidden";
mp-wp_genesis 200
mp-wp_genesis 201 targetElement.appendChild(container);
mp-wp_genesis 202 container.innerHTML = this.getFlashHTML(); // Using innerHTML is non-standard but the only sensible way to dynamically add Flash in IE (and maybe other browsers)
mp-wp_genesis 203 };
mp-wp_genesis 204
mp-wp_genesis 205 // Private: replaceWithFlash replaces the button_placeholder element with the flash movie.
mp-wp_genesis 206 SWFUpload.prototype.replaceWithFlash = function () {
mp-wp_genesis 207 var targetElement, tempParent;
mp-wp_genesis 208
mp-wp_genesis 209 // Make sure an element with the ID we are going to use doesn't already exist
mp-wp_genesis 210 if (document.getElementById(this.movieName) !== null) {
mp-wp_genesis 211 throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
mp-wp_genesis 212 }
mp-wp_genesis 213
mp-wp_genesis 214 // Get the element where we will be placing the flash movie
mp-wp_genesis 215 targetElement = document.getElementById(this.settings.button_placeholder_id);
mp-wp_genesis 216
mp-wp_genesis 217 if (targetElement == undefined) {
mp-wp_genesis 218 throw "Could not find the placeholder element.";
mp-wp_genesis 219 }
mp-wp_genesis 220
mp-wp_genesis 221 // Append the container and load the flash
mp-wp_genesis 222 tempParent = document.createElement("div");
mp-wp_genesis 223 tempParent.innerHTML = this.getFlashHTML(); // Using innerHTML is non-standard but the only sensible way to dynamically add Flash in IE (and maybe other browsers)
mp-wp_genesis 224 targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement);
mp-wp_genesis 225
mp-wp_genesis 226 };
mp-wp_genesis 227
mp-wp_genesis 228 // Private: getFlashHTML generates the object tag needed to embed the flash in to the document
mp-wp_genesis 229 SWFUpload.prototype.getFlashHTML = function () {
mp-wp_genesis 230 // Flash Satay object syntax: http://www.alistapart.com/articles/flashsatay
mp-wp_genesis 231 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">',
mp-wp_genesis 232 '<param name="wmode" value="', this.settings.button_window_mode , '" />',
mp-wp_genesis 233 '<param name="movie" value="', this.settings.flash_url, '" />',
mp-wp_genesis 234 '<param name="quality" value="high" />',
mp-wp_genesis 235 '<param name="menu" value="false" />',
mp-wp_genesis 236 '<param name="allowScriptAccess" value="always" />',
mp-wp_genesis 237 '<param name="flashvars" value="' + this.getFlashVars() + '" />',
mp-wp_genesis 238 '</object>'].join("");
mp-wp_genesis 239 };
mp-wp_genesis 240
mp-wp_genesis 241 // Private: getFlashVars builds the parameter string that will be passed
mp-wp_genesis 242 // to flash in the flashvars param.
mp-wp_genesis 243 SWFUpload.prototype.getFlashVars = function () {
mp-wp_genesis 244 // Build a string from the post param object
mp-wp_genesis 245 var paramString = this.buildParamString();
mp-wp_genesis 246 var httpSuccessString = this.settings.http_success.join(",");
mp-wp_genesis 247
mp-wp_genesis 248 // Build the parameter string
mp-wp_genesis 249 return ["movieName=", encodeURIComponent(this.movieName),
mp-wp_genesis 250 "&amp;uploadURL=", encodeURIComponent(this.settings.upload_url),
mp-wp_genesis 251 "&amp;useQueryString=", encodeURIComponent(this.settings.use_query_string),
mp-wp_genesis 252 "&amp;requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),
mp-wp_genesis 253 "&amp;httpSuccess=", encodeURIComponent(httpSuccessString),
mp-wp_genesis 254 "&amp;params=", encodeURIComponent(paramString),
mp-wp_genesis 255 "&amp;filePostName=", encodeURIComponent(this.settings.file_post_name),
mp-wp_genesis 256 "&amp;fileTypes=", encodeURIComponent(this.settings.file_types),
mp-wp_genesis 257 "&amp;fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),
mp-wp_genesis 258 "&amp;fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),
mp-wp_genesis 259 "&amp;fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),
mp-wp_genesis 260 "&amp;fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),
mp-wp_genesis 261 "&amp;debugEnabled=", encodeURIComponent(this.settings.debug_enabled),
mp-wp_genesis 262 "&amp;buttonImageURL=", encodeURIComponent(this.settings.button_image_url),
mp-wp_genesis 263 "&amp;buttonWidth=", encodeURIComponent(this.settings.button_width),
mp-wp_genesis 264 "&amp;buttonHeight=", encodeURIComponent(this.settings.button_height),
mp-wp_genesis 265 "&amp;buttonText=", encodeURIComponent(this.settings.button_text),
mp-wp_genesis 266 "&amp;buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding),
mp-wp_genesis 267 "&amp;buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding),
mp-wp_genesis 268 "&amp;buttonTextStyle=", encodeURIComponent(this.settings.button_text_style),
mp-wp_genesis 269 "&amp;buttonAction=", encodeURIComponent(this.settings.button_action),
mp-wp_genesis 270 "&amp;buttonDisabled=", encodeURIComponent(this.settings.button_disabled),
mp-wp_genesis 271 "&amp;buttonCursor=", encodeURIComponent(this.settings.button_cursor)
mp-wp_genesis 272 ].join("");
mp-wp_genesis 273 };
mp-wp_genesis 274
mp-wp_genesis 275 // Public: getMovieElement retrieves the DOM reference to the Flash element added by SWFUpload
mp-wp_genesis 276 // The element is cached after the first lookup
mp-wp_genesis 277 SWFUpload.prototype.getMovieElement = function () {
mp-wp_genesis 278 if (this.movieElement == undefined) {
mp-wp_genesis 279 this.movieElement = document.getElementById(this.movieName);
mp-wp_genesis 280 }
mp-wp_genesis 281
mp-wp_genesis 282 if (this.movieElement === null) {
mp-wp_genesis 283 throw "Could not find Flash element";
mp-wp_genesis 284 }
mp-wp_genesis 285
mp-wp_genesis 286 return this.movieElement;
mp-wp_genesis 287 };
mp-wp_genesis 288
mp-wp_genesis 289 // Private: buildParamString takes the name/value pairs in the post_params setting object
mp-wp_genesis 290 // and joins them up in to a string formatted "name=value&amp;name=value"
mp-wp_genesis 291 SWFUpload.prototype.buildParamString = function () {
mp-wp_genesis 292 var postParams = this.settings.post_params;
mp-wp_genesis 293 var paramStringPairs = [];
mp-wp_genesis 294
mp-wp_genesis 295 if (typeof(postParams) === "object") {
mp-wp_genesis 296 for (var name in postParams) {
mp-wp_genesis 297 if (postParams.hasOwnProperty(name)) {
mp-wp_genesis 298 paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString()));
mp-wp_genesis 299 }
mp-wp_genesis 300 }
mp-wp_genesis 301 }
mp-wp_genesis 302
mp-wp_genesis 303 return paramStringPairs.join("&amp;");
mp-wp_genesis 304 };
mp-wp_genesis 305
mp-wp_genesis 306 // Public: Used to remove a SWFUpload instance from the page. This method strives to remove
mp-wp_genesis 307 // all references to the SWF, and other objects so memory is properly freed.
mp-wp_genesis 308 // Returns true if everything was destroyed. Returns a false if a failure occurs leaving SWFUpload in an inconsistant state.
mp-wp_genesis 309 SWFUpload.prototype.destroy = function () {
mp-wp_genesis 310 try {
mp-wp_genesis 311 // Make sure Flash is done before we try to remove it
mp-wp_genesis 312 this.stopUpload();
mp-wp_genesis 313
mp-wp_genesis 314 // Remove the SWFUpload DOM nodes
mp-wp_genesis 315 var movieElement = null;
mp-wp_genesis 316 try {
mp-wp_genesis 317 movieElement = this.getMovieElement();
mp-wp_genesis 318 } catch (ex) {
mp-wp_genesis 319 }
mp-wp_genesis 320
mp-wp_genesis 321 if (movieElement != undefined && movieElement.parentNode != undefined && typeof movieElement.parentNode.removeChild === "function") {
mp-wp_genesis 322 var container = movieElement.parentNode;
mp-wp_genesis 323 if (container != undefined) {
mp-wp_genesis 324 container.removeChild(movieElement);
mp-wp_genesis 325 if (container.parentNode != undefined && typeof container.parentNode.removeChild === "function") {
mp-wp_genesis 326 container.parentNode.removeChild(container);
mp-wp_genesis 327 }
mp-wp_genesis 328 }
mp-wp_genesis 329 }
mp-wp_genesis 330
mp-wp_genesis 331 // Destroy references
mp-wp_genesis 332 SWFUpload.instances[this.movieName] = null;
mp-wp_genesis 333 delete SWFUpload.instances[this.movieName];
mp-wp_genesis 334
mp-wp_genesis 335 delete this.movieElement;
mp-wp_genesis 336 delete this.settings;
mp-wp_genesis 337 delete this.customSettings;
mp-wp_genesis 338 delete this.eventQueue;
mp-wp_genesis 339 delete this.movieName;
mp-wp_genesis 340
mp-wp_genesis 341 delete window[this.movieName];
mp-wp_genesis 342
mp-wp_genesis 343 return true;
mp-wp_genesis 344 } catch (ex1) {
mp-wp_genesis 345 return false;
mp-wp_genesis 346 }
mp-wp_genesis 347 };
mp-wp_genesis 348
mp-wp_genesis 349 // Public: displayDebugInfo prints out settings and configuration
mp-wp_genesis 350 // information about this SWFUpload instance.
mp-wp_genesis 351 // This function (and any references to it) can be deleted when placing
mp-wp_genesis 352 // SWFUpload in production.
mp-wp_genesis 353 SWFUpload.prototype.displayDebugInfo = function () {
mp-wp_genesis 354 this.debug(
mp-wp_genesis 355 [
mp-wp_genesis 356 "---SWFUpload Instance Info---\n",
mp-wp_genesis 357 "Version: ", SWFUpload.version, "\n",
mp-wp_genesis 358 "Movie Name: ", this.movieName, "\n",
mp-wp_genesis 359 "Settings:\n",
mp-wp_genesis 360 "\t", "upload_url: ", this.settings.upload_url, "\n",
mp-wp_genesis 361 "\t", "flash_url: ", this.settings.flash_url, "\n",
mp-wp_genesis 362 "\t", "use_query_string: ", this.settings.use_query_string.toString(), "\n",
mp-wp_genesis 363 "\t", "requeue_on_error: ", this.settings.requeue_on_error.toString(), "\n",
mp-wp_genesis 364 "\t", "http_success: ", this.settings.http_success.join(", "), "\n",
mp-wp_genesis 365 "\t", "file_post_name: ", this.settings.file_post_name, "\n",
mp-wp_genesis 366 "\t", "post_params: ", this.settings.post_params.toString(), "\n",
mp-wp_genesis 367 "\t", "file_types: ", this.settings.file_types, "\n",
mp-wp_genesis 368 "\t", "file_types_description: ", this.settings.file_types_description, "\n",
mp-wp_genesis 369 "\t", "file_size_limit: ", this.settings.file_size_limit, "\n",
mp-wp_genesis 370 "\t", "file_upload_limit: ", this.settings.file_upload_limit, "\n",
mp-wp_genesis 371 "\t", "file_queue_limit: ", this.settings.file_queue_limit, "\n",
mp-wp_genesis 372 "\t", "debug: ", this.settings.debug.toString(), "\n",
mp-wp_genesis 373
mp-wp_genesis 374 "\t", "prevent_swf_caching: ", this.settings.prevent_swf_caching.toString(), "\n",
mp-wp_genesis 375
mp-wp_genesis 376 "\t", "button_placeholder_id: ", this.settings.button_placeholder_id.toString(), "\n",
mp-wp_genesis 377 "\t", "button_image_url: ", this.settings.button_image_url.toString(), "\n",
mp-wp_genesis 378 "\t", "button_width: ", this.settings.button_width.toString(), "\n",
mp-wp_genesis 379 "\t", "button_height: ", this.settings.button_height.toString(), "\n",
mp-wp_genesis 380 "\t", "button_text: ", this.settings.button_text.toString(), "\n",
mp-wp_genesis 381 "\t", "button_text_style: ", this.settings.button_text_style.toString(), "\n",
mp-wp_genesis 382 "\t", "button_text_top_padding: ", this.settings.button_text_top_padding.toString(), "\n",
mp-wp_genesis 383 "\t", "button_text_left_padding: ", this.settings.button_text_left_padding.toString(), "\n",
mp-wp_genesis 384 "\t", "button_action: ", this.settings.button_action.toString(), "\n",
mp-wp_genesis 385 "\t", "button_disabled: ", this.settings.button_disabled.toString(), "\n",
mp-wp_genesis 386
mp-wp_genesis 387 "\t", "custom_settings: ", this.settings.custom_settings.toString(), "\n",
mp-wp_genesis 388 "Event Handlers:\n",
mp-wp_genesis 389 "\t", "swfupload_loaded_handler assigned: ", (typeof this.settings.swfupload_loaded_handler === "function").toString(), "\n",
mp-wp_genesis 390 "\t", "file_dialog_start_handler assigned: ", (typeof this.settings.file_dialog_start_handler === "function").toString(), "\n",
mp-wp_genesis 391 "\t", "file_queued_handler assigned: ", (typeof this.settings.file_queued_handler === "function").toString(), "\n",
mp-wp_genesis 392 "\t", "file_queue_error_handler assigned: ", (typeof this.settings.file_queue_error_handler === "function").toString(), "\n",
mp-wp_genesis 393 "\t", "upload_start_handler assigned: ", (typeof this.settings.upload_start_handler === "function").toString(), "\n",
mp-wp_genesis 394 "\t", "upload_progress_handler assigned: ", (typeof this.settings.upload_progress_handler === "function").toString(), "\n",
mp-wp_genesis 395 "\t", "upload_error_handler assigned: ", (typeof this.settings.upload_error_handler === "function").toString(), "\n",
mp-wp_genesis 396 "\t", "upload_success_handler assigned: ", (typeof this.settings.upload_success_handler === "function").toString(), "\n",
mp-wp_genesis 397 "\t", "upload_complete_handler assigned: ", (typeof this.settings.upload_complete_handler === "function").toString(), "\n",
mp-wp_genesis 398 "\t", "debug_handler assigned: ", (typeof this.settings.debug_handler === "function").toString(), "\n"
mp-wp_genesis 399 ].join("")
mp-wp_genesis 400 );
mp-wp_genesis 401 };
mp-wp_genesis 402
mp-wp_genesis 403 /* Note: addSetting and getSetting are no longer used by SWFUpload but are included
mp-wp_genesis 404 the maintain v2 API compatibility
mp-wp_genesis 405 */
mp-wp_genesis 406 // Public: (Deprecated) addSetting adds a setting value. If the value given is undefined or null then the default_value is used.
mp-wp_genesis 407 SWFUpload.prototype.addSetting = function (name, value, default_value) {
mp-wp_genesis 408 if (value == undefined) {
mp-wp_genesis 409 return (this.settings[name] = default_value);
mp-wp_genesis 410 } else {
mp-wp_genesis 411 return (this.settings[name] = value);
mp-wp_genesis 412 }
mp-wp_genesis 413 };
mp-wp_genesis 414
mp-wp_genesis 415 // Public: (Deprecated) getSetting gets a setting. Returns an empty string if the setting was not found.
mp-wp_genesis 416 SWFUpload.prototype.getSetting = function (name) {
mp-wp_genesis 417 if (this.settings[name] != undefined) {
mp-wp_genesis 418 return this.settings[name];
mp-wp_genesis 419 }
mp-wp_genesis 420
mp-wp_genesis 421 return "";
mp-wp_genesis 422 };
mp-wp_genesis 423
mp-wp_genesis 424
mp-wp_genesis 425
mp-wp_genesis 426 // Private: callFlash handles function calls made to the Flash element.
mp-wp_genesis 427 // Calls are made with a setTimeout for some functions to work around
mp-wp_genesis 428 // bugs in the ExternalInterface library.
mp-wp_genesis 429 SWFUpload.prototype.callFlash = function (functionName, argumentArray) {
mp-wp_genesis 430 argumentArray = argumentArray || [];
mp-wp_genesis 431
mp-wp_genesis 432 var movieElement = this.getMovieElement();
mp-wp_genesis 433 var returnValue;
mp-wp_genesis 434
mp-wp_genesis 435 if (typeof movieElement[functionName] === "function") {
mp-wp_genesis 436 // 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.
mp-wp_genesis 437 if (argumentArray.length === 0) {
mp-wp_genesis 438 returnValue = movieElement[functionName]();
mp-wp_genesis 439 } else if (argumentArray.length === 1) {
mp-wp_genesis 440 returnValue = movieElement[functionName](argumentArray[0]);
mp-wp_genesis 441 } else if (argumentArray.length === 2) {
mp-wp_genesis 442 returnValue = movieElement[functionName](argumentArray[0], argumentArray[1]);
mp-wp_genesis 443 } else if (argumentArray.length === 3) {
mp-wp_genesis 444 returnValue = movieElement[functionName](argumentArray[0], argumentArray[1], argumentArray[2]);
mp-wp_genesis 445 } else {
mp-wp_genesis 446 throw "Too many arguments";
mp-wp_genesis 447 }
mp-wp_genesis 448
mp-wp_genesis 449 // Unescape file post param values
mp-wp_genesis 450 if (returnValue != undefined && typeof returnValue.post === "object") {
mp-wp_genesis 451 returnValue = this.unescapeFilePostParams(returnValue);
mp-wp_genesis 452 }
mp-wp_genesis 453
mp-wp_genesis 454 return returnValue;
mp-wp_genesis 455 } else {
mp-wp_genesis 456 throw "Invalid function name: " + functionName;
mp-wp_genesis 457 }
mp-wp_genesis 458 };
mp-wp_genesis 459
mp-wp_genesis 460
mp-wp_genesis 461 /* *****************************
mp-wp_genesis 462 -- Flash control methods --
mp-wp_genesis 463 Your UI should use these
mp-wp_genesis 464 to operate SWFUpload
mp-wp_genesis 465 ***************************** */
mp-wp_genesis 466
mp-wp_genesis 467 // Public: selectFile causes a File Selection Dialog window to appear. This
mp-wp_genesis 468 // dialog only allows 1 file to be selected. WARNING: this function does not work in Flash Player 10
mp-wp_genesis 469 SWFUpload.prototype.selectFile = function () {
mp-wp_genesis 470 this.callFlash("SelectFile");
mp-wp_genesis 471 };
mp-wp_genesis 472
mp-wp_genesis 473 // Public: selectFiles causes a File Selection Dialog window to appear/ This
mp-wp_genesis 474 // dialog allows the user to select any number of files
mp-wp_genesis 475 // Flash Bug Warning: Flash limits the number of selectable files based on the combined length of the file names.
mp-wp_genesis 476 // If the selection name length is too long the dialog will fail in an unpredictable manner. There is no work-around
mp-wp_genesis 477 // for this bug. WARNING: this function does not work in Flash Player 10
mp-wp_genesis 478 SWFUpload.prototype.selectFiles = function () {
mp-wp_genesis 479 this.callFlash("SelectFiles");
mp-wp_genesis 480 };
mp-wp_genesis 481
mp-wp_genesis 482
mp-wp_genesis 483 // Public: startUpload starts uploading the first file in the queue unless
mp-wp_genesis 484 // the optional parameter 'fileID' specifies the ID
mp-wp_genesis 485 SWFUpload.prototype.startUpload = function (fileID) {
mp-wp_genesis 486 this.callFlash("StartUpload", [fileID]);
mp-wp_genesis 487 };
mp-wp_genesis 488
mp-wp_genesis 489 // Public: cancelUpload cancels any queued file. The fileID parameter may be the file ID or index.
mp-wp_genesis 490 // If you do not specify a fileID the current uploading file or first file in the queue is cancelled.
mp-wp_genesis 491 // If you do not want the uploadError event to trigger you can specify false for the triggerErrorEvent parameter.
mp-wp_genesis 492 SWFUpload.prototype.cancelUpload = function (fileID, triggerErrorEvent) {
mp-wp_genesis 493 if (triggerErrorEvent !== false) {
mp-wp_genesis 494 triggerErrorEvent = true;
mp-wp_genesis 495 }
mp-wp_genesis 496 this.callFlash("CancelUpload", [fileID, triggerErrorEvent]);
mp-wp_genesis 497 };
mp-wp_genesis 498
mp-wp_genesis 499 // Public: stopUpload stops the current upload and requeues the file at the beginning of the queue.
mp-wp_genesis 500 // If nothing is currently uploading then nothing happens.
mp-wp_genesis 501 SWFUpload.prototype.stopUpload = function () {
mp-wp_genesis 502 this.callFlash("StopUpload");
mp-wp_genesis 503 };
mp-wp_genesis 504
mp-wp_genesis 505 /* ************************
mp-wp_genesis 506 * Settings methods
mp-wp_genesis 507 * These methods change the SWFUpload settings.
mp-wp_genesis 508 * SWFUpload settings should not be changed directly on the settings object
mp-wp_genesis 509 * since many of the settings need to be passed to Flash in order to take
mp-wp_genesis 510 * effect.
mp-wp_genesis 511 * *********************** */
mp-wp_genesis 512
mp-wp_genesis 513 // Public: getStats gets the file statistics object.
mp-wp_genesis 514 SWFUpload.prototype.getStats = function () {
mp-wp_genesis 515 return this.callFlash("GetStats");
mp-wp_genesis 516 };
mp-wp_genesis 517
mp-wp_genesis 518 // Public: setStats changes the SWFUpload statistics. You shouldn't need to
mp-wp_genesis 519 // change the statistics but you can. Changing the statistics does not
mp-wp_genesis 520 // affect SWFUpload accept for the successful_uploads count which is used
mp-wp_genesis 521 // by the upload_limit setting to determine how many files the user may upload.
mp-wp_genesis 522 SWFUpload.prototype.setStats = function (statsObject) {
mp-wp_genesis 523 this.callFlash("SetStats", [statsObject]);
mp-wp_genesis 524 };
mp-wp_genesis 525
mp-wp_genesis 526 // Public: getFile retrieves a File object by ID or Index. If the file is
mp-wp_genesis 527 // not found then 'null' is returned.
mp-wp_genesis 528 SWFUpload.prototype.getFile = function (fileID) {
mp-wp_genesis 529 if (typeof(fileID) === "number") {
mp-wp_genesis 530 return this.callFlash("GetFileByIndex", [fileID]);
mp-wp_genesis 531 } else {
mp-wp_genesis 532 return this.callFlash("GetFile", [fileID]);
mp-wp_genesis 533 }
mp-wp_genesis 534 };
mp-wp_genesis 535
mp-wp_genesis 536 // Public: addFileParam sets a name/value pair that will be posted with the
mp-wp_genesis 537 // file specified by the Files ID. If the name already exists then the
mp-wp_genesis 538 // exiting value will be overwritten.
mp-wp_genesis 539 SWFUpload.prototype.addFileParam = function (fileID, name, value) {
mp-wp_genesis 540 return this.callFlash("AddFileParam", [fileID, name, value]);
mp-wp_genesis 541 };
mp-wp_genesis 542
mp-wp_genesis 543 // Public: removeFileParam removes a previously set (by addFileParam) name/value
mp-wp_genesis 544 // pair from the specified file.
mp-wp_genesis 545 SWFUpload.prototype.removeFileParam = function (fileID, name) {
mp-wp_genesis 546 this.callFlash("RemoveFileParam", [fileID, name]);
mp-wp_genesis 547 };
mp-wp_genesis 548
mp-wp_genesis 549 // Public: setUploadUrl changes the upload_url setting.
mp-wp_genesis 550 SWFUpload.prototype.setUploadURL = function (url) {
mp-wp_genesis 551 this.settings.upload_url = url.toString();
mp-wp_genesis 552 this.callFlash("SetUploadURL", [url]);
mp-wp_genesis 553 };
mp-wp_genesis 554
mp-wp_genesis 555 // Public: setPostParams changes the post_params setting
mp-wp_genesis 556 SWFUpload.prototype.setPostParams = function (paramsObject) {
mp-wp_genesis 557 this.settings.post_params = paramsObject;
mp-wp_genesis 558 this.callFlash("SetPostParams", [paramsObject]);
mp-wp_genesis 559 };
mp-wp_genesis 560
mp-wp_genesis 561 // Public: addPostParam adds post name/value pair. Each name can have only one value.
mp-wp_genesis 562 SWFUpload.prototype.addPostParam = function (name, value) {
mp-wp_genesis 563 this.settings.post_params[name] = value;
mp-wp_genesis 564 this.callFlash("SetPostParams", [this.settings.post_params]);
mp-wp_genesis 565 };
mp-wp_genesis 566
mp-wp_genesis 567 // Public: removePostParam deletes post name/value pair.
mp-wp_genesis 568 SWFUpload.prototype.removePostParam = function (name) {
mp-wp_genesis 569 delete this.settings.post_params[name];
mp-wp_genesis 570 this.callFlash("SetPostParams", [this.settings.post_params]);
mp-wp_genesis 571 };
mp-wp_genesis 572
mp-wp_genesis 573 // Public: setFileTypes changes the file_types setting and the file_types_description setting
mp-wp_genesis 574 SWFUpload.prototype.setFileTypes = function (types, description) {
mp-wp_genesis 575 this.settings.file_types = types;
mp-wp_genesis 576 this.settings.file_types_description = description;
mp-wp_genesis 577 this.callFlash("SetFileTypes", [types, description]);
mp-wp_genesis 578 };
mp-wp_genesis 579
mp-wp_genesis 580 // Public: setFileSizeLimit changes the file_size_limit setting
mp-wp_genesis 581 SWFUpload.prototype.setFileSizeLimit = function (fileSizeLimit) {
mp-wp_genesis 582 this.settings.file_size_limit = fileSizeLimit;
mp-wp_genesis 583 this.callFlash("SetFileSizeLimit", [fileSizeLimit]);
mp-wp_genesis 584 };
mp-wp_genesis 585
mp-wp_genesis 586 // Public: setFileUploadLimit changes the file_upload_limit setting
mp-wp_genesis 587 SWFUpload.prototype.setFileUploadLimit = function (fileUploadLimit) {
mp-wp_genesis 588 this.settings.file_upload_limit = fileUploadLimit;
mp-wp_genesis 589 this.callFlash("SetFileUploadLimit", [fileUploadLimit]);
mp-wp_genesis 590 };
mp-wp_genesis 591
mp-wp_genesis 592 // Public: setFileQueueLimit changes the file_queue_limit setting
mp-wp_genesis 593 SWFUpload.prototype.setFileQueueLimit = function (fileQueueLimit) {
mp-wp_genesis 594 this.settings.file_queue_limit = fileQueueLimit;
mp-wp_genesis 595 this.callFlash("SetFileQueueLimit", [fileQueueLimit]);
mp-wp_genesis 596 };
mp-wp_genesis 597
mp-wp_genesis 598 // Public: setFilePostName changes the file_post_name setting
mp-wp_genesis 599 SWFUpload.prototype.setFilePostName = function (filePostName) {
mp-wp_genesis 600 this.settings.file_post_name = filePostName;
mp-wp_genesis 601 this.callFlash("SetFilePostName", [filePostName]);
mp-wp_genesis 602 };
mp-wp_genesis 603
mp-wp_genesis 604 // Public: setUseQueryString changes the use_query_string setting
mp-wp_genesis 605 SWFUpload.prototype.setUseQueryString = function (useQueryString) {
mp-wp_genesis 606 this.settings.use_query_string = useQueryString;
mp-wp_genesis 607 this.callFlash("SetUseQueryString", [useQueryString]);
mp-wp_genesis 608 };
mp-wp_genesis 609
mp-wp_genesis 610 // Public: setRequeueOnError changes the requeue_on_error setting
mp-wp_genesis 611 SWFUpload.prototype.setRequeueOnError = function (requeueOnError) {
mp-wp_genesis 612 this.settings.requeue_on_error = requeueOnError;
mp-wp_genesis 613 this.callFlash("SetRequeueOnError", [requeueOnError]);
mp-wp_genesis 614 };
mp-wp_genesis 615
mp-wp_genesis 616 // Public: setHTTPSuccess changes the http_success setting
mp-wp_genesis 617 SWFUpload.prototype.setHTTPSuccess = function (http_status_codes) {
mp-wp_genesis 618 if (typeof http_status_codes === "string") {
mp-wp_genesis 619 http_status_codes = http_status_codes.replace(" ", "").split(",");
mp-wp_genesis 620 }
mp-wp_genesis 621
mp-wp_genesis 622 this.settings.http_success = http_status_codes;
mp-wp_genesis 623 this.callFlash("SetHTTPSuccess", [http_status_codes]);
mp-wp_genesis 624 };
mp-wp_genesis 625
mp-wp_genesis 626
mp-wp_genesis 627 // Public: setDebugEnabled changes the debug_enabled setting
mp-wp_genesis 628 SWFUpload.prototype.setDebugEnabled = function (debugEnabled) {
mp-wp_genesis 629 this.settings.debug_enabled = debugEnabled;
mp-wp_genesis 630 this.callFlash("SetDebugEnabled", [debugEnabled]);
mp-wp_genesis 631 };
mp-wp_genesis 632
mp-wp_genesis 633 // Public: setButtonImageURL loads a button image sprite
mp-wp_genesis 634 SWFUpload.prototype.setButtonImageURL = function (buttonImageURL) {
mp-wp_genesis 635 if (buttonImageURL == undefined) {
mp-wp_genesis 636 buttonImageURL = "";
mp-wp_genesis 637 }
mp-wp_genesis 638
mp-wp_genesis 639 this.settings.button_image_url = buttonImageURL;
mp-wp_genesis 640 this.callFlash("SetButtonImageURL", [buttonImageURL]);
mp-wp_genesis 641 };
mp-wp_genesis 642
mp-wp_genesis 643 // Public: setButtonDimensions resizes the Flash Movie and button
mp-wp_genesis 644 SWFUpload.prototype.setButtonDimensions = function (width, height) {
mp-wp_genesis 645 this.settings.button_width = width;
mp-wp_genesis 646 this.settings.button_height = height;
mp-wp_genesis 647
mp-wp_genesis 648 var movie = this.getMovieElement();
mp-wp_genesis 649 if (movie != undefined) {
mp-wp_genesis 650 movie.style.width = width + "px";
mp-wp_genesis 651 movie.style.height = height + "px";
mp-wp_genesis 652 }
mp-wp_genesis 653
mp-wp_genesis 654 this.callFlash("SetButtonDimensions", [width, height]);
mp-wp_genesis 655 };
mp-wp_genesis 656 // Public: setButtonText Changes the text overlaid on the button
mp-wp_genesis 657 SWFUpload.prototype.setButtonText = function (html) {
mp-wp_genesis 658 this.settings.button_text = html;
mp-wp_genesis 659 this.callFlash("SetButtonText", [html]);
mp-wp_genesis 660 };
mp-wp_genesis 661 // Public: setButtonTextPadding changes the top and left padding of the text overlay
mp-wp_genesis 662 SWFUpload.prototype.setButtonTextPadding = function (left, top) {
mp-wp_genesis 663 this.settings.button_text_top_padding = top;
mp-wp_genesis 664 this.settings.button_text_left_padding = left;
mp-wp_genesis 665 this.callFlash("SetButtonTextPadding", [left, top]);
mp-wp_genesis 666 };
mp-wp_genesis 667
mp-wp_genesis 668 // Public: setButtonTextStyle changes the CSS used to style the HTML/Text overlaid on the button
mp-wp_genesis 669 SWFUpload.prototype.setButtonTextStyle = function (css) {
mp-wp_genesis 670 this.settings.button_text_style = css;
mp-wp_genesis 671 this.callFlash("SetButtonTextStyle", [css]);
mp-wp_genesis 672 };
mp-wp_genesis 673 // Public: setButtonDisabled disables/enables the button
mp-wp_genesis 674 SWFUpload.prototype.setButtonDisabled = function (isDisabled) {
mp-wp_genesis 675 this.settings.button_disabled = isDisabled;
mp-wp_genesis 676 this.callFlash("SetButtonDisabled", [isDisabled]);
mp-wp_genesis 677 };
mp-wp_genesis 678 // Public: setButtonAction sets the action that occurs when the button is clicked
mp-wp_genesis 679 SWFUpload.prototype.setButtonAction = function (buttonAction) {
mp-wp_genesis 680 this.settings.button_action = buttonAction;
mp-wp_genesis 681 this.callFlash("SetButtonAction", [buttonAction]);
mp-wp_genesis 682 };
mp-wp_genesis 683
mp-wp_genesis 684 // Public: setButtonCursor changes the mouse cursor displayed when hovering over the button
mp-wp_genesis 685 SWFUpload.prototype.setButtonCursor = function (cursor) {
mp-wp_genesis 686 this.settings.button_cursor = cursor;
mp-wp_genesis 687 this.callFlash("SetButtonCursor", [cursor]);
mp-wp_genesis 688 };
mp-wp_genesis 689
mp-wp_genesis 690 /* *******************************
mp-wp_genesis 691 Flash Event Interfaces
mp-wp_genesis 692 These functions are used by Flash to trigger the various
mp-wp_genesis 693 events.
mp-wp_genesis 694
mp-wp_genesis 695 All these functions a Private.
mp-wp_genesis 696
mp-wp_genesis 697 Because the ExternalInterface library is buggy the event calls
mp-wp_genesis 698 are added to a queue and the queue then executed by a setTimeout.
mp-wp_genesis 699 This ensures that events are executed in a determinate order and that
mp-wp_genesis 700 the ExternalInterface bugs are avoided.
mp-wp_genesis 701 ******************************* */
mp-wp_genesis 702
mp-wp_genesis 703 SWFUpload.prototype.queueEvent = function (handlerName, argumentArray) {
mp-wp_genesis 704 // Warning: Don't call this.debug inside here or you'll create an infinite loop
mp-wp_genesis 705
mp-wp_genesis 706 if (argumentArray == undefined) {
mp-wp_genesis 707 argumentArray = [];
mp-wp_genesis 708 } else if (!(argumentArray instanceof Array)) {
mp-wp_genesis 709 argumentArray = [argumentArray];
mp-wp_genesis 710 }
mp-wp_genesis 711
mp-wp_genesis 712 var self = this;
mp-wp_genesis 713 if (typeof this.settings[handlerName] === "function") {
mp-wp_genesis 714 // Queue the event
mp-wp_genesis 715 this.eventQueue.push(function () {
mp-wp_genesis 716 this.settings[handlerName].apply(this, argumentArray);
mp-wp_genesis 717 });
mp-wp_genesis 718
mp-wp_genesis 719 // Execute the next queued event
mp-wp_genesis 720 setTimeout(function () {
mp-wp_genesis 721 self.executeNextEvent();
mp-wp_genesis 722 }, 0);
mp-wp_genesis 723
mp-wp_genesis 724 } else if (this.settings[handlerName] !== null) {
mp-wp_genesis 725 throw "Event handler " + handlerName + " is unknown or is not a function";
mp-wp_genesis 726 }
mp-wp_genesis 727 };
mp-wp_genesis 728
mp-wp_genesis 729 // Private: Causes the next event in the queue to be executed. Since events are queued using a setTimeout
mp-wp_genesis 730 // we must queue them in order to garentee that they are executed in order.
mp-wp_genesis 731 SWFUpload.prototype.executeNextEvent = function () {
mp-wp_genesis 732 // Warning: Don't call this.debug inside here or you'll create an infinite loop
mp-wp_genesis 733
mp-wp_genesis 734 var f = this.eventQueue ? this.eventQueue.shift() : null;
mp-wp_genesis 735 if (typeof(f) === "function") {
mp-wp_genesis 736 f.apply(this);
mp-wp_genesis 737 }
mp-wp_genesis 738 };
mp-wp_genesis 739
mp-wp_genesis 740 // Private: unescapeFileParams is part of a workaround for a flash bug where objects passed through ExternalInterface cannot have
mp-wp_genesis 741 // properties that contain characters that are not valid for JavaScript identifiers. To work around this
mp-wp_genesis 742 // the Flash Component escapes the parameter names and we must unescape again before passing them along.
mp-wp_genesis 743 SWFUpload.prototype.unescapeFilePostParams = function (file) {
mp-wp_genesis 744 var reg = /[$]([0-9a-f]{4})/i;
mp-wp_genesis 745 var unescapedPost = {};
mp-wp_genesis 746 var uk;
mp-wp_genesis 747
mp-wp_genesis 748 if (file != undefined) {
mp-wp_genesis 749 for (var k in file.post) {
mp-wp_genesis 750 if (file.post.hasOwnProperty(k)) {
mp-wp_genesis 751 uk = k;
mp-wp_genesis 752 var match;
mp-wp_genesis 753 while ((match = reg.exec(uk)) !== null) {
mp-wp_genesis 754 uk = uk.replace(match[0], String.fromCharCode(parseInt("0x" + match[1], 16)));
mp-wp_genesis 755 }
mp-wp_genesis 756 unescapedPost[uk] = file.post[k];
mp-wp_genesis 757 }
mp-wp_genesis 758 }
mp-wp_genesis 759
mp-wp_genesis 760 file.post = unescapedPost;
mp-wp_genesis 761 }
mp-wp_genesis 762
mp-wp_genesis 763 return file;
mp-wp_genesis 764 };
mp-wp_genesis 765
mp-wp_genesis 766 SWFUpload.prototype.flashReady = function () {
mp-wp_genesis 767 // Check that the movie element is loaded correctly with its ExternalInterface methods defined
mp-wp_genesis 768 var movieElement = this.getMovieElement();
mp-wp_genesis 769 if (typeof movieElement.StartUpload !== "function") {
mp-wp_genesis 770 throw "ExternalInterface methods failed to initialize.";
mp-wp_genesis 771 }
mp-wp_genesis 772
mp-wp_genesis 773 // Fix IE Flash/Form bug
mp-wp_genesis 774 if (window[this.movieName] == undefined) {
mp-wp_genesis 775 window[this.movieName] = movieElement;
mp-wp_genesis 776 }
mp-wp_genesis 777
mp-wp_genesis 778 this.queueEvent("swfupload_loaded_handler");
mp-wp_genesis 779 };
mp-wp_genesis 780
mp-wp_genesis 781
mp-wp_genesis 782 /* This is a chance to do something before the browse window opens */
mp-wp_genesis 783 SWFUpload.prototype.fileDialogStart = function () {
mp-wp_genesis 784 this.queueEvent("file_dialog_start_handler");
mp-wp_genesis 785 };
mp-wp_genesis 786
mp-wp_genesis 787
mp-wp_genesis 788 /* Called when a file is successfully added to the queue. */
mp-wp_genesis 789 SWFUpload.prototype.fileQueued = function (file) {
mp-wp_genesis 790 file = this.unescapeFilePostParams(file);
mp-wp_genesis 791 this.queueEvent("file_queued_handler", file);
mp-wp_genesis 792 };
mp-wp_genesis 793
mp-wp_genesis 794
mp-wp_genesis 795 /* Handle errors that occur when an attempt to queue a file fails. */
mp-wp_genesis 796 SWFUpload.prototype.fileQueueError = function (file, errorCode, message) {
mp-wp_genesis 797 file = this.unescapeFilePostParams(file);
mp-wp_genesis 798 this.queueEvent("file_queue_error_handler", [file, errorCode, message]);
mp-wp_genesis 799 };
mp-wp_genesis 800
mp-wp_genesis 801 /* Called after the file dialog has closed and the selected files have been queued.
mp-wp_genesis 802 You could call startUpload here if you want the queued files to begin uploading immediately. */
mp-wp_genesis 803 SWFUpload.prototype.fileDialogComplete = function (numFilesSelected, numFilesQueued) {
mp-wp_genesis 804 this.queueEvent("file_dialog_complete_handler", [numFilesSelected, numFilesQueued]);
mp-wp_genesis 805 };
mp-wp_genesis 806
mp-wp_genesis 807 SWFUpload.prototype.uploadStart = function (file) {
mp-wp_genesis 808 file = this.unescapeFilePostParams(file);
mp-wp_genesis 809 this.queueEvent("return_upload_start_handler", file);
mp-wp_genesis 810 };
mp-wp_genesis 811
mp-wp_genesis 812 SWFUpload.prototype.returnUploadStart = function (file) {
mp-wp_genesis 813 var returnValue;
mp-wp_genesis 814 if (typeof this.settings.upload_start_handler === "function") {
mp-wp_genesis 815 file = this.unescapeFilePostParams(file);
mp-wp_genesis 816 returnValue = this.settings.upload_start_handler.call(this, file);
mp-wp_genesis 817 } else if (this.settings.upload_start_handler != undefined) {
mp-wp_genesis 818 throw "upload_start_handler must be a function";
mp-wp_genesis 819 }
mp-wp_genesis 820
mp-wp_genesis 821 // Convert undefined to true so if nothing is returned from the upload_start_handler it is
mp-wp_genesis 822 // interpretted as 'true'.
mp-wp_genesis 823 if (returnValue === undefined) {
mp-wp_genesis 824 returnValue = true;
mp-wp_genesis 825 }
mp-wp_genesis 826
mp-wp_genesis 827 returnValue = !!returnValue;
mp-wp_genesis 828
mp-wp_genesis 829 this.callFlash("ReturnUploadStart", [returnValue]);
mp-wp_genesis 830 };
mp-wp_genesis 831
mp-wp_genesis 832
mp-wp_genesis 833
mp-wp_genesis 834 SWFUpload.prototype.uploadProgress = function (file, bytesComplete, bytesTotal) {
mp-wp_genesis 835 file = this.unescapeFilePostParams(file);
mp-wp_genesis 836 this.queueEvent("upload_progress_handler", [file, bytesComplete, bytesTotal]);
mp-wp_genesis 837 };
mp-wp_genesis 838
mp-wp_genesis 839 SWFUpload.prototype.uploadError = function (file, errorCode, message) {
mp-wp_genesis 840 file = this.unescapeFilePostParams(file);
mp-wp_genesis 841 this.queueEvent("upload_error_handler", [file, errorCode, message]);
mp-wp_genesis 842 };
mp-wp_genesis 843
mp-wp_genesis 844 SWFUpload.prototype.uploadSuccess = function (file, serverData) {
mp-wp_genesis 845 file = this.unescapeFilePostParams(file);
mp-wp_genesis 846 this.queueEvent("upload_success_handler", [file, serverData]);
mp-wp_genesis 847 };
mp-wp_genesis 848
mp-wp_genesis 849 SWFUpload.prototype.uploadComplete = function (file) {
mp-wp_genesis 850 file = this.unescapeFilePostParams(file);
mp-wp_genesis 851 this.queueEvent("upload_complete_handler", file);
mp-wp_genesis 852 };
mp-wp_genesis 853
mp-wp_genesis 854 /* Called by SWFUpload JavaScript and Flash functions when debug is enabled. By default it writes messages to the
mp-wp_genesis 855 internal debug console. You can override this event and have messages written where you want. */
mp-wp_genesis 856 SWFUpload.prototype.debug = function (message) {
mp-wp_genesis 857 this.queueEvent("debug_handler", message);
mp-wp_genesis 858 };
mp-wp_genesis 859
mp-wp_genesis 860
mp-wp_genesis 861 /* **********************************
mp-wp_genesis 862 Debug Console
mp-wp_genesis 863 The debug console is a self contained, in page location
mp-wp_genesis 864 for debug message to be sent. The Debug Console adds
mp-wp_genesis 865 itself to the body if necessary.
mp-wp_genesis 866
mp-wp_genesis 867 The console is automatically scrolled as messages appear.
mp-wp_genesis 868
mp-wp_genesis 869 If you are using your own debug handler or when you deploy to production and
mp-wp_genesis 870 have debug disabled you can remove these functions to reduce the file size
mp-wp_genesis 871 and complexity.
mp-wp_genesis 872 ********************************** */
mp-wp_genesis 873
mp-wp_genesis 874 // Private: debugMessage is the default debug_handler. If you want to print debug messages
mp-wp_genesis 875 // call the debug() function. When overriding the function your own function should
mp-wp_genesis 876 // check to see if the debug setting is true before outputting debug information.
mp-wp_genesis 877 SWFUpload.prototype.debugMessage = function (message) {
mp-wp_genesis 878 if (this.settings.debug) {
mp-wp_genesis 879 var exceptionMessage, exceptionValues = [];
mp-wp_genesis 880
mp-wp_genesis 881 // Check for an exception object and print it nicely
mp-wp_genesis 882 if (typeof message === "object" && typeof message.name === "string" && typeof message.message === "string") {
mp-wp_genesis 883 for (var key in message) {
mp-wp_genesis 884 if (message.hasOwnProperty(key)) {
mp-wp_genesis 885 exceptionValues.push(key + ": " + message[key]);
mp-wp_genesis 886 }
mp-wp_genesis 887 }
mp-wp_genesis 888 exceptionMessage = exceptionValues.join("\n") || "";
mp-wp_genesis 889 exceptionValues = exceptionMessage.split("\n");
mp-wp_genesis 890 exceptionMessage = "EXCEPTION: " + exceptionValues.join("\nEXCEPTION: ");
mp-wp_genesis 891 SWFUpload.Console.writeLine(exceptionMessage);
mp-wp_genesis 892 } else {
mp-wp_genesis 893 SWFUpload.Console.writeLine(message);
mp-wp_genesis 894 }
mp-wp_genesis 895 }
mp-wp_genesis 896 };
mp-wp_genesis 897
mp-wp_genesis 898 SWFUpload.Console = {};
mp-wp_genesis 899 SWFUpload.Console.writeLine = function (message) {
mp-wp_genesis 900 var console, documentForm;
mp-wp_genesis 901
mp-wp_genesis 902 try {
mp-wp_genesis 903 console = document.getElementById("SWFUpload_Console");
mp-wp_genesis 904
mp-wp_genesis 905 if (!console) {
mp-wp_genesis 906 documentForm = document.createElement("form");
mp-wp_genesis 907 document.getElementsByTagName("body")[0].appendChild(documentForm);
mp-wp_genesis 908
mp-wp_genesis 909 console = document.createElement("textarea");
mp-wp_genesis 910 console.id = "SWFUpload_Console";
mp-wp_genesis 911 console.style.fontFamily = "monospace";
mp-wp_genesis 912 console.setAttribute("wrap", "off");
mp-wp_genesis 913 console.wrap = "off";
mp-wp_genesis 914 console.style.overflow = "auto";
mp-wp_genesis 915 console.style.width = "700px";
mp-wp_genesis 916 console.style.height = "350px";
mp-wp_genesis 917 console.style.margin = "5px";
mp-wp_genesis 918 documentForm.appendChild(console);
mp-wp_genesis 919 }
mp-wp_genesis 920
mp-wp_genesis 921 console.value += message + "\n";
mp-wp_genesis 922
mp-wp_genesis 923 console.scrollTop = console.scrollHeight - console.clientHeight;
mp-wp_genesis 924 } catch (ex) {
mp-wp_genesis 925 alert("Exception: " + ex.name + " Message: " + ex.message);
mp-wp_genesis 926 }
mp-wp_genesis 927 };