| 1 | Index: wp-includes/js/swfupload/swfupload.js |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- wp-includes/js/swfupload/swfupload.js (revision 9385) |
|---|
| 4 | +++ wp-includes/js/swfupload/swfupload.js (working copy) |
|---|
| 5 | @@ -1,41 +1,29 @@ |
|---|
| 6 | /** |
|---|
| 7 | - * SWFUpload v2.0 by Jacob Roberts, Nov 2007, http://www.swfupload.org, http://linebyline.blogspot.com |
|---|
| 8 | - * -------- -------- -------- -------- -------- -------- -------- -------- |
|---|
| 9 | - * SWFUpload is (c) 2006 Lars Huring and Mammon Media and is released under the MIT License: |
|---|
| 10 | + * SWFUpload: http://www.swfupload.org, http://swfupload.googlecode.com |
|---|
| 11 | + * |
|---|
| 12 | + * mmSWFUpload 1.0: Flash upload dialog - http://profandesign.se/swfupload/, http://www.vinterwebb.se/ |
|---|
| 13 | + * |
|---|
| 14 | + * SWFUpload is (c) 2006-2007 Lars Huring, Olov Nilzén and Mammon Media and is released under the MIT License: |
|---|
| 15 | * http://www.opensource.org/licenses/mit-license.php |
|---|
| 16 | * |
|---|
| 17 | - * See Changelog.txt for version history |
|---|
| 18 | + * SWFUpload 2 is (c) 2007-2008 Jake Roberts and is released under the MIT License: |
|---|
| 19 | + * http://www.opensource.org/licenses/mit-license.php |
|---|
| 20 | * |
|---|
| 21 | - * Development Notes: |
|---|
| 22 | - * * This version of SWFUpload requires Flash Player 9.0.28 and should autodetect the correct flash version. |
|---|
| 23 | - * * In Linux Flash Player 9 setting the post file variable name does not work. It is always set to "Filedata". |
|---|
| 24 | - * * There is a lot of repeated code that could be refactored to single functions. Feel free. |
|---|
| 25 | - * * It's dangerous to do "circular calls" between Flash and JavaScript. I've taken steps to try to work around issues |
|---|
| 26 | - * by having the event calls pipe through setTimeout. However you should still avoid calling in to Flash from |
|---|
| 27 | - * within the event handler methods. Especially the "startUpload" event since it cannot use the setTimeout hack. |
|---|
| 28 | */ |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | -/* *********** */ |
|---|
| 32 | -/* Constructor */ |
|---|
| 33 | -/* *********** */ |
|---|
| 34 | +/* ******************* */ |
|---|
| 35 | +/* Constructor & Init */ |
|---|
| 36 | +/* ******************* */ |
|---|
| 37 | |
|---|
| 38 | -var SWFUpload = function (init_settings) { |
|---|
| 39 | - this.initSWFUpload(init_settings); |
|---|
| 40 | +var SWFUpload = function (settings) { |
|---|
| 41 | + this.initSWFUpload(settings); |
|---|
| 42 | }; |
|---|
| 43 | |
|---|
| 44 | -SWFUpload.prototype.initSWFUpload = function (init_settings) { |
|---|
| 45 | - // Remove background flicker in IE (read this: http://misterpixel.blogspot.com/2006/09/forensic-analysis-of-ie6.html) |
|---|
| 46 | - // This doesn't have anything to do with SWFUpload but can help your UI behave better in IE. |
|---|
| 47 | +SWFUpload.prototype.initSWFUpload = function (settings) { |
|---|
| 48 | try { |
|---|
| 49 | - document.execCommand('BackgroundImageCache', false, true); |
|---|
| 50 | - } catch (ex1) { |
|---|
| 51 | - } |
|---|
| 52 | - |
|---|
| 53 | - |
|---|
| 54 | - try { |
|---|
| 55 | this.customSettings = {}; // A container where developers can place their own settings associated with this instance. |
|---|
| 56 | - this.settings = {}; |
|---|
| 57 | + this.settings = settings; |
|---|
| 58 | this.eventQueue = []; |
|---|
| 59 | this.movieName = "SWFUpload_" + SWFUpload.movieCount++; |
|---|
| 60 | this.movieElement = null; |
|---|
| 61 | @@ -44,21 +32,21 @@ |
|---|
| 62 | SWFUpload.instances[this.movieName] = this; |
|---|
| 63 | |
|---|
| 64 | // Load the settings. Load the Flash movie. |
|---|
| 65 | - this.initSettings(init_settings); |
|---|
| 66 | + this.initSettings(); |
|---|
| 67 | this.loadFlash(); |
|---|
| 68 | - |
|---|
| 69 | this.displayDebugInfo(); |
|---|
| 70 | - |
|---|
| 71 | - } catch (ex2) { |
|---|
| 72 | - this.debug(ex2); |
|---|
| 73 | + } catch (ex) { |
|---|
| 74 | + delete SWFUpload.instances[this.movieName]; |
|---|
| 75 | + throw ex; |
|---|
| 76 | } |
|---|
| 77 | -} |
|---|
| 78 | +}; |
|---|
| 79 | |
|---|
| 80 | /* *************** */ |
|---|
| 81 | -/* Static thingies */ |
|---|
| 82 | +/* Static Members */ |
|---|
| 83 | /* *************** */ |
|---|
| 84 | SWFUpload.instances = {}; |
|---|
| 85 | SWFUpload.movieCount = 0; |
|---|
| 86 | +SWFUpload.version = "2.2.0 Alpha"; |
|---|
| 87 | SWFUpload.QUEUE_ERROR = { |
|---|
| 88 | QUEUE_LIMIT_EXCEEDED : -100, |
|---|
| 89 | FILE_EXCEEDS_SIZE_LIMIT : -110, |
|---|
| 90 | @@ -84,912 +72,754 @@ |
|---|
| 91 | COMPLETE : -4, |
|---|
| 92 | CANCELLED : -5 |
|---|
| 93 | }; |
|---|
| 94 | +SWFUpload.BUTTON_ACTION = { |
|---|
| 95 | + SELECT_FILE : -100, |
|---|
| 96 | + SELECT_FILES : -110, |
|---|
| 97 | + START_UPLOAD : -120 |
|---|
| 98 | +}; |
|---|
| 99 | |
|---|
| 100 | +/* ******************** */ |
|---|
| 101 | +/* Instance Members */ |
|---|
| 102 | +/* ******************** */ |
|---|
| 103 | |
|---|
| 104 | -/* ***************** */ |
|---|
| 105 | -/* Instance Thingies */ |
|---|
| 106 | -/* ***************** */ |
|---|
| 107 | -// init is a private method that ensures that all the object settings are set, getting a default value if one was not assigned. |
|---|
| 108 | - |
|---|
| 109 | -SWFUpload.prototype.initSettings = function (init_settings) { |
|---|
| 110 | +// Private: initSettings ensures that all the |
|---|
| 111 | +// settings are set, getting a default value if one was not assigned. |
|---|
| 112 | +SWFUpload.prototype.initSettings = function () { |
|---|
| 113 | + this.ensureDefault = function (settingName, defaultValue) { |
|---|
| 114 | + this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName]; |
|---|
| 115 | + }; |
|---|
| 116 | + |
|---|
| 117 | // Upload backend settings |
|---|
| 118 | - this.addSetting("upload_url", init_settings.upload_url, ""); |
|---|
| 119 | - this.addSetting("file_post_name", init_settings.file_post_name, "Filedata"); |
|---|
| 120 | - this.addSetting("post_params", init_settings.post_params, {}); |
|---|
| 121 | - |
|---|
| 122 | + this.ensureDefault("upload_url", ""); |
|---|
| 123 | + this.ensureDefault("file_post_name", "Filedata"); |
|---|
| 124 | + this.ensureDefault("post_params", {}); |
|---|
| 125 | + this.ensureDefault("use_query_string", false); |
|---|
| 126 | + this.ensureDefault("requeue_on_error", false); |
|---|
| 127 | + |
|---|
| 128 | // File Settings |
|---|
| 129 | - this.addSetting("file_types", init_settings.file_types, "*.*"); |
|---|
| 130 | - this.addSetting("file_types_description", init_settings.file_types_description, "All Files"); |
|---|
| 131 | - this.addSetting("file_size_limit", init_settings.file_size_limit, "1024"); |
|---|
| 132 | - this.addSetting("file_upload_limit", init_settings.file_upload_limit, "0"); |
|---|
| 133 | - this.addSetting("file_queue_limit", init_settings.file_queue_limit, "0"); |
|---|
| 134 | + this.ensureDefault("file_types", "*.*"); |
|---|
| 135 | + this.ensureDefault("file_types_description", "All Files"); |
|---|
| 136 | + this.ensureDefault("file_size_limit", 0); // Default zero means "unlimited" |
|---|
| 137 | + this.ensureDefault("file_upload_limit", 0); |
|---|
| 138 | + this.ensureDefault("file_queue_limit", 0); |
|---|
| 139 | |
|---|
| 140 | // Flash Settings |
|---|
| 141 | - this.addSetting("flash_url", init_settings.flash_url, "swfupload.swf"); |
|---|
| 142 | - this.addSetting("flash_width", init_settings.flash_width, "1px"); |
|---|
| 143 | - this.addSetting("flash_height", init_settings.flash_height, "1px"); |
|---|
| 144 | - this.addSetting("flash_color", init_settings.flash_color, "#FFFFFF"); |
|---|
| 145 | - |
|---|
| 146 | + this.ensureDefault("flash_url", "swfupload.swf"); |
|---|
| 147 | + this.ensureDefault("prevent_swf_caching", true); |
|---|
| 148 | + |
|---|
| 149 | + // Button Settings |
|---|
| 150 | + this.ensureDefault("button_image_url", ""); |
|---|
| 151 | + this.ensureDefault("button_width", 1); |
|---|
| 152 | + this.ensureDefault("button_height", 1); |
|---|
| 153 | + this.ensureDefault("button_text", ""); |
|---|
| 154 | + this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;"); |
|---|
| 155 | + this.ensureDefault("button_text_top_padding", 0); |
|---|
| 156 | + this.ensureDefault("button_text_left_padding", 0); |
|---|
| 157 | + this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES); |
|---|
| 158 | + this.ensureDefault("button_disabled", false); |
|---|
| 159 | + this.ensureDefault("button_placeholder_id", null); |
|---|
| 160 | + |
|---|
| 161 | // Debug Settings |
|---|
| 162 | - this.addSetting("debug_enabled", init_settings.debug, false); |
|---|
| 163 | - |
|---|
| 164 | + this.ensureDefault("debug", false); |
|---|
| 165 | + this.settings.debug_enabled = this.settings.debug; // Here to maintain v2 API |
|---|
| 166 | + |
|---|
| 167 | // Event Handlers |
|---|
| 168 | - this.flashReady_handler = SWFUpload.flashReady; // This is a non-overrideable event handler |
|---|
| 169 | - this.swfUploadLoaded_handler = this.retrieveSetting(init_settings.swfupload_loaded_handler, SWFUpload.swfUploadLoaded); |
|---|
| 170 | + this.settings.return_upload_start_handler = this.returnUploadStart; |
|---|
| 171 | + this.ensureDefault("swfupload_loaded_handler", null); |
|---|
| 172 | + this.ensureDefault("file_dialog_start_handler", null); |
|---|
| 173 | + this.ensureDefault("file_queued_handler", null); |
|---|
| 174 | + this.ensureDefault("file_queue_error_handler", null); |
|---|
| 175 | + this.ensureDefault("file_dialog_complete_handler", null); |
|---|
| 176 | |
|---|
| 177 | - this.fileDialogStart_handler = this.retrieveSetting(init_settings.file_dialog_start_handler, SWFUpload.fileDialogStart); |
|---|
| 178 | - this.fileQueued_handler = this.retrieveSetting(init_settings.file_queued_handler, SWFUpload.fileQueued); |
|---|
| 179 | - this.fileQueueError_handler = this.retrieveSetting(init_settings.file_queue_error_handler, SWFUpload.fileQueueError); |
|---|
| 180 | - this.fileDialogComplete_handler = this.retrieveSetting(init_settings.file_dialog_complete_handler, SWFUpload.fileDialogComplete); |
|---|
| 181 | + this.ensureDefault("upload_start_handler", null); |
|---|
| 182 | + this.ensureDefault("upload_progress_handler", null); |
|---|
| 183 | + this.ensureDefault("upload_error_handler", null); |
|---|
| 184 | + this.ensureDefault("upload_success_handler", null); |
|---|
| 185 | + this.ensureDefault("upload_complete_handler", null); |
|---|
| 186 | |
|---|
| 187 | - this.uploadStart_handler = this.retrieveSetting(init_settings.upload_start_handler, SWFUpload.uploadStart); |
|---|
| 188 | - this.uploadProgress_handler = this.retrieveSetting(init_settings.upload_progress_handler, SWFUpload.uploadProgress); |
|---|
| 189 | - this.uploadError_handler = this.retrieveSetting(init_settings.upload_error_handler, SWFUpload.uploadError); |
|---|
| 190 | - this.uploadSuccess_handler = this.retrieveSetting(init_settings.upload_success_handler, SWFUpload.uploadSuccess); |
|---|
| 191 | - this.uploadComplete_handler = this.retrieveSetting(init_settings.upload_complete_handler, SWFUpload.uploadComplete); |
|---|
| 192 | + this.ensureDefault("debug_handler", this.debugMessage); |
|---|
| 193 | |
|---|
| 194 | - this.debug_handler = this.retrieveSetting(init_settings.debug_handler, SWFUpload.debug); |
|---|
| 195 | + this.ensureDefault("custom_settings", {}); |
|---|
| 196 | |
|---|
| 197 | // Other settings |
|---|
| 198 | - this.customSettings = this.retrieveSetting(init_settings.custom_settings, {}); |
|---|
| 199 | + this.customSettings = this.settings.custom_settings; |
|---|
| 200 | + |
|---|
| 201 | + // Update the flash url if needed |
|---|
| 202 | + if (this.settings.prevent_swf_caching) { |
|---|
| 203 | + this.settings.flash_url = this.settings.flash_url + "?swfuploadrnd=" + Math.floor(Math.random() * 999999999); |
|---|
| 204 | + } |
|---|
| 205 | + |
|---|
| 206 | + delete this.ensureDefault; |
|---|
| 207 | }; |
|---|
| 208 | |
|---|
| 209 | -// loadFlash is a private method that generates the HTML tag for the Flash |
|---|
| 210 | -// It then adds the flash to the "target" or to the body and stores a |
|---|
| 211 | -// reference to the flash element in "movieElement". |
|---|
| 212 | SWFUpload.prototype.loadFlash = function () { |
|---|
| 213 | - var html, target_element, container; |
|---|
| 214 | + if (this.settings.button_placeholder_id !== "") { |
|---|
| 215 | + this.replaceWithFlash(); |
|---|
| 216 | + } else { |
|---|
| 217 | + this.appendFlash(); |
|---|
| 218 | + } |
|---|
| 219 | +}; |
|---|
| 220 | |
|---|
| 221 | +// Private: appendFlash gets the HTML tag for the Flash |
|---|
| 222 | +// It then appends the flash to the body |
|---|
| 223 | +SWFUpload.prototype.appendFlash = function () { |
|---|
| 224 | + var targetElement, container; |
|---|
| 225 | + |
|---|
| 226 | // Make sure an element with the ID we are going to use doesn't already exist |
|---|
| 227 | if (document.getElementById(this.movieName) !== null) { |
|---|
| 228 | - return false; |
|---|
| 229 | + throw "ID " + this.movieName + " is already in use. The Flash Object could not be added"; |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | // Get the body tag where we will be adding the flash movie |
|---|
| 233 | - try { |
|---|
| 234 | - target_element = document.getElementsByTagName("body")[0]; |
|---|
| 235 | - if (typeof(target_element) === "undefined" || target_element === null) { |
|---|
| 236 | - this.debug('Could not find the BODY element. SWFUpload failed to load.'); |
|---|
| 237 | - return false; |
|---|
| 238 | - } |
|---|
| 239 | - } catch (ex) { |
|---|
| 240 | - return false; |
|---|
| 241 | + targetElement = document.getElementsByTagName("body")[0]; |
|---|
| 242 | + |
|---|
| 243 | + if (targetElement == undefined) { |
|---|
| 244 | + throw "Could not find the 'body' element."; |
|---|
| 245 | } |
|---|
| 246 | |
|---|
| 247 | // Append the container and load the flash |
|---|
| 248 | container = document.createElement("div"); |
|---|
| 249 | - container.style.width = this.getSetting("flash_width"); |
|---|
| 250 | - container.style.height = this.getSetting("flash_height"); |
|---|
| 251 | + container.style.width = "1px"; |
|---|
| 252 | + container.style.height = "1px"; |
|---|
| 253 | + container.style.overflow = "hidden"; |
|---|
| 254 | |
|---|
| 255 | - target_element.appendChild(container); |
|---|
| 256 | + targetElement.appendChild(container); |
|---|
| 257 | container.innerHTML = this.getFlashHTML(); // Using innerHTML is non-standard but the only sensible way to dynamically add Flash in IE (and maybe other browsers) |
|---|
| 258 | }; |
|---|
| 259 | |
|---|
| 260 | -// Generates the embed/object tags needed to embed the flash in to the document |
|---|
| 261 | -SWFUpload.prototype.getFlashHTML = function () { |
|---|
| 262 | - var html = ""; |
|---|
| 263 | +// Private: replaceWithFlash replaces the button_placeholder element with the flash movie. |
|---|
| 264 | +SWFUpload.prototype.replaceWithFlash = function () { |
|---|
| 265 | + var targetElement, tempParent; |
|---|
| 266 | |
|---|
| 267 | - // Create Mozilla Embed HTML |
|---|
| 268 | - if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { |
|---|
| 269 | - // Build the basic embed html |
|---|
| 270 | - html = '<embed type="application/x-shockwave-flash" src="' + this.getSetting("flash_url") + '" width="' + this.getSetting("flash_width") + '" height="' + this.getSetting("flash_height") + '"'; |
|---|
| 271 | - html += ' id="' + this.movieName + '" name="' + this.movieName + '" '; |
|---|
| 272 | - html += 'bgcolor="' + this.getSetting("flash_color") + '" quality="high" menu="false" flashvars="'; |
|---|
| 273 | + // Make sure an element with the ID we are going to use doesn't already exist |
|---|
| 274 | + if (document.getElementById(this.movieName) !== null) { |
|---|
| 275 | + throw "ID " + this.movieName + " is already in use. The Flash Object could not be added"; |
|---|
| 276 | + } |
|---|
| 277 | |
|---|
| 278 | - html += this.getFlashVars(); |
|---|
| 279 | + // Get the element where we will be placing the flash movie |
|---|
| 280 | + targetElement = document.getElementById(this.settings.button_placeholder_id); |
|---|
| 281 | |
|---|
| 282 | - html += '" />'; |
|---|
| 283 | + if (targetElement == undefined) { |
|---|
| 284 | + throw "Could not find the placeholder element."; |
|---|
| 285 | + } |
|---|
| 286 | |
|---|
| 287 | - // Create IE Object HTML |
|---|
| 288 | - } else { |
|---|
| 289 | + // Append the container and load the flash |
|---|
| 290 | + tempParent = document.createElement("div"); |
|---|
| 291 | + tempParent.innerHTML = this.getFlashHTML(); // Using innerHTML is non-standard but the only sensible way to dynamically add Flash in IE (and maybe other browsers) |
|---|
| 292 | + targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement); |
|---|
| 293 | |
|---|
| 294 | - // Build the basic Object tag |
|---|
| 295 | - html = '<object id="' + this.movieName + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + this.getSetting("flash_width") + '" height="' + this.getSetting("flash_height") + '">'; |
|---|
| 296 | - html += '<param name="movie" value="' + this.getSetting("flash_url") + '">'; |
|---|
| 297 | +}; |
|---|
| 298 | |
|---|
| 299 | - html += '<param name="bgcolor" value="' + this.getSetting("flash_color") + '" />'; |
|---|
| 300 | - html += '<param name="quality" value="high" />'; |
|---|
| 301 | - html += '<param name="menu" value="false" />'; |
|---|
| 302 | - |
|---|
| 303 | - html += '<param name="flashvars" value="' + this.getFlashVars() + '" />'; |
|---|
| 304 | - html += '</object>'; |
|---|
| 305 | - } |
|---|
| 306 | - |
|---|
| 307 | - return html; |
|---|
| 308 | +// Private: getFlashHTML generates the object tag needed to embed the flash in to the document |
|---|
| 309 | +SWFUpload.prototype.getFlashHTML = function () { |
|---|
| 310 | + var transparent = this.settings.button_image_url === "" ? true : false; |
|---|
| 311 | + |
|---|
| 312 | + // Flash Satay object syntax: http://www.alistapart.com/articles/flashsatay |
|---|
| 313 | + 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">', |
|---|
| 314 | + '<param name="wmode" value="', transparent ? "transparent" : "window", '" />', |
|---|
| 315 | + '<param name="movie" value="', this.settings.flash_url, '" />', |
|---|
| 316 | + '<param name="quality" value="high" />', |
|---|
| 317 | + '<param name="menu" value="false" />', |
|---|
| 318 | + '<param name="allowScriptAccess" value="always" />', |
|---|
| 319 | + '<param name="flashvars" value="' + this.getFlashVars() + '" />', |
|---|
| 320 | + '</object>'].join(""); |
|---|
| 321 | }; |
|---|
| 322 | |
|---|
| 323 | -// This private method builds the parameter string that will be passed |
|---|
| 324 | -// to flash. |
|---|
| 325 | +// Private: getFlashVars builds the parameter string that will be passed |
|---|
| 326 | +// to flash in the flashvars param. |
|---|
| 327 | SWFUpload.prototype.getFlashVars = function () { |
|---|
| 328 | // Build a string from the post param object |
|---|
| 329 | - var param_string = this.buildParamString(); |
|---|
| 330 | + var paramString = this.buildParamString(); |
|---|
| 331 | |
|---|
| 332 | // Build the parameter string |
|---|
| 333 | - var html = ""; |
|---|
| 334 | - html += "movieName=" + encodeURIComponent(this.movieName); |
|---|
| 335 | - html += "&uploadURL=" + encodeURIComponent(this.getSetting("upload_url")); |
|---|
| 336 | - html += "¶ms=" + encodeURIComponent(param_string); |
|---|
| 337 | - html += "&filePostName=" + encodeURIComponent(this.getSetting("file_post_name")); |
|---|
| 338 | - html += "&fileTypes=" + encodeURIComponent(this.getSetting("file_types")); |
|---|
| 339 | - html += "&fileTypesDescription=" + encodeURIComponent(this.getSetting("file_types_description")); |
|---|
| 340 | - html += "&fileSizeLimit=" + encodeURIComponent(this.getSetting("file_size_limit")); |
|---|
| 341 | - html += "&fileUploadLimit=" + encodeURIComponent(this.getSetting("file_upload_limit")); |
|---|
| 342 | - html += "&fileQueueLimit=" + encodeURIComponent(this.getSetting("file_queue_limit")); |
|---|
| 343 | - html += "&debugEnabled=" + encodeURIComponent(this.getSetting("debug_enabled")); |
|---|
| 344 | - |
|---|
| 345 | - return html; |
|---|
| 346 | + return ["movieName=", encodeURIComponent(this.movieName), |
|---|
| 347 | + "&uploadURL=", encodeURIComponent(this.settings.upload_url), |
|---|
| 348 | + "&useQueryString=", encodeURIComponent(this.settings.use_query_string), |
|---|
| 349 | + "&requeueOnError=", encodeURIComponent(this.settings.requeue_on_error), |
|---|
| 350 | + "&params=", encodeURIComponent(paramString), |
|---|
| 351 | + "&filePostName=", encodeURIComponent(this.settings.file_post_name), |
|---|
| 352 | + "&fileTypes=", encodeURIComponent(this.settings.file_types), |
|---|
| 353 | + "&fileTypesDescription=", encodeURIComponent(this.settings.file_types_description), |
|---|
| 354 | + "&fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit), |
|---|
| 355 | + "&fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit), |
|---|
| 356 | + "&fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit), |
|---|
| 357 | + "&debugEnabled=", encodeURIComponent(this.settings.debug_enabled), |
|---|
| 358 | + "&buttonImageURL=", encodeURIComponent(this.settings.button_image_url), |
|---|
| 359 | + "&buttonWidth=", encodeURIComponent(this.settings.button_width), |
|---|
| 360 | + "&buttonHeight=", encodeURIComponent(this.settings.button_height), |
|---|
| 361 | + "&buttonText=", encodeURIComponent(this.settings.button_text), |
|---|
| 362 | + "&buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding), |
|---|
| 363 | + "&buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding), |
|---|
| 364 | + "&buttonTextStyle=", encodeURIComponent(this.settings.button_text_style), |
|---|
| 365 | + "&buttonAction=", encodeURIComponent(this.settings.button_action), |
|---|
| 366 | + "&buttonDisabled=", encodeURIComponent(this.settings.button_disabled) |
|---|
| 367 | + ].join(""); |
|---|
| 368 | }; |
|---|
| 369 | |
|---|
| 370 | +// Public: getMovieElement retrieves the DOM reference to the Flash element added by SWFUpload |
|---|
| 371 | +// The element is cached after the first lookup |
|---|
| 372 | SWFUpload.prototype.getMovieElement = function () { |
|---|
| 373 | - if (typeof(this.movieElement) === "undefined" || this.movieElement === null) { |
|---|
| 374 | + if (this.movieElement == undefined) { |
|---|
| 375 | this.movieElement = document.getElementById(this.movieName); |
|---|
| 376 | - |
|---|
| 377 | - // Fix IEs "Flash can't callback when in a form" issue (http://www.extremefx.com.ar/blog/fixing-flash-external-interface-inside-form-on-internet-explorer) |
|---|
| 378 | - // Removed because Revision 6 always adds the flash to the body (inside a containing div) |
|---|
| 379 | - // If you insist on adding the Flash file inside a Form then in IE you have to make you wait until the DOM is ready |
|---|
| 380 | - // and run this code to make the form's ID available from the window object so Flash and JavaScript can communicate. |
|---|
| 381 | - //if (typeof(window[this.movieName]) === "undefined" || window[this.moveName] !== this.movieElement) { |
|---|
| 382 | - // window[this.movieName] = this.movieElement; |
|---|
| 383 | - //} |
|---|
| 384 | } |
|---|
| 385 | |
|---|
| 386 | + if (this.movieElement === null) { |
|---|
| 387 | + throw "Could not find Flash element"; |
|---|
| 388 | + } |
|---|
| 389 | + |
|---|
| 390 | return this.movieElement; |
|---|
| 391 | }; |
|---|
| 392 | |
|---|
| 393 | +// Private: buildParamString takes the name/value pairs in the post_params setting object |
|---|
| 394 | +// and joins them up in to a string formatted "name=value&name=value" |
|---|
| 395 | SWFUpload.prototype.buildParamString = function () { |
|---|
| 396 | - var post_params = this.getSetting("post_params"); |
|---|
| 397 | - var param_string_pairs = []; |
|---|
| 398 | - var i, value, name; |
|---|
| 399 | + var postParams = this.settings.post_params; |
|---|
| 400 | + var paramStringPairs = []; |
|---|
| 401 | |
|---|
| 402 | - // Retrieve the user defined parameters |
|---|
| 403 | - if (typeof(post_params) === "object") { |
|---|
| 404 | - for (name in post_params) { |
|---|
| 405 | - if (post_params.hasOwnProperty(name)) { |
|---|
| 406 | - if (typeof(post_params[name]) === "string") { |
|---|
| 407 | - param_string_pairs.push(encodeURIComponent(name) + "=" + encodeURIComponent(post_params[name])); |
|---|
| 408 | - } |
|---|
| 409 | + if (typeof(postParams) === "object") { |
|---|
| 410 | + for (var name in postParams) { |
|---|
| 411 | + if (postParams.hasOwnProperty(name)) { |
|---|
| 412 | + paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString())); |
|---|
| 413 | } |
|---|
| 414 | } |
|---|
| 415 | } |
|---|
| 416 | |
|---|
| 417 | - return param_string_pairs.join("&"); |
|---|
| 418 | + return paramStringPairs.join("&"); |
|---|
| 419 | }; |
|---|
| 420 | |
|---|
| 421 | -// Saves a setting. If the value given is undefined or null then the default_value is used. |
|---|
| 422 | -SWFUpload.prototype.addSetting = function (name, value, default_value) { |
|---|
| 423 | - if (typeof(value) === "undefined" || value === null) { |
|---|
| 424 | - this.settings[name] = default_value; |
|---|
| 425 | - } else { |
|---|
| 426 | - this.settings[name] = value; |
|---|
| 427 | - } |
|---|
| 428 | +// Public: Used to remove a SWFUpload instance from the page. This method strives to remove |
|---|
| 429 | +// all references to the SWF, and other objects so memory is properly freed. |
|---|
| 430 | +// Returns true if everything was destroyed. Returns a false if a failure occurs leaving SWFUpload in an inconsistant state. |
|---|
| 431 | +SWFUpload.prototype.destroy = function () { |
|---|
| 432 | + try { |
|---|
| 433 | + // Make sure Flash is done before we try to remove it |
|---|
| 434 | + this.stopUpload(); |
|---|
| 435 | + |
|---|
| 436 | + // Remove the SWFUpload DOM nodes |
|---|
| 437 | + var movieElement = null; |
|---|
| 438 | + try { |
|---|
| 439 | + movieElement = this.getMovieElement(); |
|---|
| 440 | + } catch (ex) { |
|---|
| 441 | + } |
|---|
| 442 | + |
|---|
| 443 | + if (movieElement != undefined && movieElement.parentNode != undefined && typeof movieElement.parentNode.removeChild === "function") { |
|---|
| 444 | + var container = movieElement.parentNode; |
|---|
| 445 | + if (container != undefined) { |
|---|
| 446 | + container.removeChild(movieElement); |
|---|
| 447 | + if (container.parentNode != undefined && typeof container.parentNode.removeChild === "function") { |
|---|
| 448 | + container.parentNode.removeChild(container); |
|---|
| 449 | + } |
|---|
| 450 | + } |
|---|
| 451 | + } |
|---|
| 452 | + |
|---|
| 453 | + // Destroy references |
|---|
| 454 | + SWFUpload.instances[this.movieName] = null; |
|---|
| 455 | + delete SWFUpload.instances[this.movieName]; |
|---|
| 456 | |
|---|
| 457 | - return this.settings[name]; |
|---|
| 458 | -}; |
|---|
| 459 | - |
|---|
| 460 | -// Gets a setting. Returns empty string if not found. |
|---|
| 461 | -SWFUpload.prototype.getSetting = function (name) { |
|---|
| 462 | - if (typeof(this.settings[name]) === "undefined") { |
|---|
| 463 | - return ""; |
|---|
| 464 | - } else { |
|---|
| 465 | - return this.settings[name]; |
|---|
| 466 | + delete this.movieElement; |
|---|
| 467 | + delete this.settings; |
|---|
| 468 | + delete this.customSettings; |
|---|
| 469 | + delete this.eventQueue; |
|---|
| 470 | + delete this.movieName; |
|---|
| 471 | + |
|---|
| 472 | + delete window[this.movieName]; |
|---|
| 473 | + |
|---|
| 474 | + return true; |
|---|
| 475 | + } catch (ex1) { |
|---|
| 476 | + return false; |
|---|
| 477 | } |
|---|
| 478 | }; |
|---|
| 479 | |
|---|
| 480 | -// Gets a setting, if the setting is undefined then return the default value |
|---|
| 481 | -// This does not affect or use the interal setting object. |
|---|
| 482 | -SWFUpload.prototype.retrieveSetting = function (value, default_value) { |
|---|
| 483 | - if (typeof(value) === "undefined" || value === null) { |
|---|
| 484 | - return default_value; |
|---|
| 485 | - } else { |
|---|
| 486 | - return value; |
|---|
| 487 | - } |
|---|
| 488 | -}; |
|---|
| 489 | - |
|---|
| 490 | - |
|---|
| 491 | -// It loops through all the settings and displays |
|---|
| 492 | -// them in the debug Console. |
|---|
| 493 | +// Public: displayDebugInfo prints out settings and configuration |
|---|
| 494 | +// information about this SWFUpload instance. |
|---|
| 495 | +// This function (and any references to it) can be deleted when placing |
|---|
| 496 | +// SWFUpload in production. |
|---|
| 497 | SWFUpload.prototype.displayDebugInfo = function () { |
|---|
| 498 | - var key, debug_message = ""; |
|---|
| 499 | + this.debug( |
|---|
| 500 | + [ |
|---|
| 501 | + "---SWFUpload Instance Info---\n", |
|---|
| 502 | + "Version: ", SWFUpload.version, "\n", |
|---|
| 503 | + "Movie Name: ", this.movieName, "\n", |
|---|
| 504 | + "Settings:\n", |
|---|
| 505 | + "\t", "upload_url: ", this.settings.upload_url, "\n", |
|---|
| 506 | + "\t", "flash_url: ", this.settings.flash_url, "\n", |
|---|
| 507 | + "\t", "use_query_string: ", this.settings.use_query_string.toString(), "\n", |
|---|
| 508 | + "\t", "file_post_name: ", this.settings.file_post_name, "\n", |
|---|
| 509 | + "\t", "post_params: ", this.settings.post_params.toString(), "\n", |
|---|
| 510 | + "\t", "file_types: ", this.settings.file_types, "\n", |
|---|
| 511 | + "\t", "file_types_description: ", this.settings.file_types_description, "\n", |
|---|
| 512 | + "\t", "file_size_limit: ", this.settings.file_size_limit, "\n", |
|---|
| 513 | + "\t", "file_upload_limit: ", this.settings.file_upload_limit, "\n", |
|---|
| 514 | + "\t", "file_queue_limit: ", this.settings.file_queue_limit, "\n", |
|---|
| 515 | + "\t", "debug: ", this.settings.debug.toString(), "\n", |
|---|
| 516 | |
|---|
| 517 | - debug_message += "----- SWFUPLOAD SETTINGS ----\nID: " + this.moveName + "\n"; |
|---|
| 518 | + "\t", "prevent_swf_caching: ", this.settings.prevent_swf_caching.toString(), "\n", |
|---|
| 519 | |
|---|
| 520 | - debug_message += this.outputObject(this.settings); |
|---|
| 521 | + "\t", "button_placeholder_id: ", this.settings.button_placeholder_id.toString(), "\n", |
|---|
| 522 | + "\t", "button_image_url: ", this.settings.button_image_url.toString(), "\n", |
|---|
| 523 | + "\t", "button_width: ", this.settings.button_width.toString(), "\n", |
|---|
| 524 | + "\t", "button_height: ", this.settings.button_height.toString(), "\n", |
|---|
| 525 | + "\t", "button_text: ", this.settings.button_text.toString(), "\n", |
|---|
| 526 | + "\t", "button_text_style: ", this.settings.button_text_style.toString(), "\n", |
|---|
| 527 | + "\t", "button_text_top_padding: ", this.settings.button_text_top_padding.toString(), "\n", |
|---|
| 528 | + "\t", "button_text_left_padding: ", this.settings.button_text_left_padding.toString(), "\n", |
|---|
| 529 | + "\t", "button_action: ", this.settings.button_action.toString(), "\n", |
|---|
| 530 | + "\t", "button_disabled: ", this.settings.button_disabled.toString(), "\n", |
|---|
| 531 | |
|---|
| 532 | - debug_message += "----- SWFUPLOAD SETTINGS END ----\n"; |
|---|
| 533 | - debug_message += "\n"; |
|---|
| 534 | + "\t", "custom_settings: ", this.settings.custom_settings.toString(), "\n", |
|---|
| 535 | + "Event Handlers:\n", |
|---|
| 536 | + "\t", "swfupload_loaded_handler assigned: ", (typeof this.settings.swfupload_loaded_handler === "function").toString(), "\n", |
|---|
| 537 | + "\t", "file_dialog_start_handler assigned: ", (typeof this.settings.file_dialog_start_handler === "function").toString(), "\n", |
|---|
| 538 | + "\t", "file_queued_handler assigned: ", (typeof this.settings.file_queued_handler === "function").toString(), "\n", |
|---|
| 539 | + "\t", "file_queue_error_handler assigned: ", (typeof this.settings.file_queue_error_handler === "function").toString(), "\n", |
|---|
| 540 | + "\t", "upload_start_handler assigned: ", (typeof this.settings.upload_start_handler === "function").toString(), "\n", |
|---|
| 541 | + "\t", "upload_progress_handler assigned: ", (typeof this.settings.upload_progress_handler === "function").toString(), "\n", |
|---|
| 542 | + "\t", "upload_error_handler assigned: ", (typeof this.settings.upload_error_handler === "function").toString(), "\n", |
|---|
| 543 | + "\t", "upload_success_handler assigned: ", (typeof this.settings.upload_success_handler === "function").toString(), "\n", |
|---|
| 544 | + "\t", "upload_complete_handler assigned: ", (typeof this.settings.upload_complete_handler === "function").toString(), "\n", |
|---|
| 545 | + "\t", "debug_handler assigned: ", (typeof this.settings.debug_handler === "function").toString(), "\n" |
|---|
| 546 | + ].join("") |
|---|
| 547 | + ); |
|---|
| 548 | +}; |
|---|
| 549 | |
|---|
| 550 | - this.debug(debug_message); |
|---|
| 551 | +/* Note: addSetting and getSetting are no longer used by SWFUpload but are included |
|---|
| 552 | + the maintain v2 API compatibility |
|---|
| 553 | +*/ |
|---|
| 554 | +// Public: (Deprecated) addSetting adds a setting value. If the value given is undefined or null then the default_value is used. |
|---|
| 555 | +SWFUpload.prototype.addSetting = function (name, value, default_value) { |
|---|
| 556 | + if (value == undefined) { |
|---|
| 557 | + return (this.settings[name] = default_value); |
|---|
| 558 | + } else { |
|---|
| 559 | + return (this.settings[name] = value); |
|---|
| 560 | + } |
|---|
| 561 | }; |
|---|
| 562 | -SWFUpload.prototype.outputObject = function (object, prefix) { |
|---|
| 563 | - var output = "", key; |
|---|
| 564 | |
|---|
| 565 | - if (typeof(prefix) !== "string") { |
|---|
| 566 | - prefix = ""; |
|---|
| 567 | +// Public: (Deprecated) getSetting gets a setting. Returns an empty string if the setting was not found. |
|---|
| 568 | +SWFUpload.prototype.getSetting = function (name) { |
|---|
| 569 | + if (this.settings[name] != undefined) { |
|---|
| 570 | + return this.settings[name]; |
|---|
| 571 | } |
|---|
| 572 | - if (typeof(object) !== "object") { |
|---|
| 573 | - return ""; |
|---|
| 574 | - } |
|---|
| 575 | |
|---|
| 576 | - for (key in object) { |
|---|
| 577 | - if (object.hasOwnProperty(key)) { |
|---|
| 578 | - if (typeof(object[key]) === "object") { |
|---|
| 579 | - output += (prefix + key + ": { \n" + this.outputObject(object[key], "\t" + prefix) + prefix + "}" + "\n"); |
|---|
| 580 | - } else { |
|---|
| 581 | - output += (prefix + key + ": " + object[key] + "\n"); |
|---|
| 582 | - } |
|---|
| 583 | + return ""; |
|---|
| 584 | +}; |
|---|
| 585 | + |
|---|
| 586 | + |
|---|
| 587 | + |
|---|
| 588 | +// Private: callFlash handles function calls made to the Flash element. |
|---|
| 589 | +// Calls are made with a setTimeout for some functions to work around |
|---|
| 590 | +// bugs in the ExternalInterface library. |
|---|
| 591 | +SWFUpload.prototype.callFlash = function (functionName, argumentArray) { |
|---|
| 592 | + argumentArray = argumentArray || []; |
|---|
| 593 | + |
|---|
| 594 | + var movieElement = this.getMovieElement(); |
|---|
| 595 | + var returnValue; |
|---|
| 596 | + |
|---|
| 597 | + if (typeof movieElement[functionName] === "function") { |
|---|
| 598 | + // 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. |
|---|
| 599 | + if (argumentArray.length === 0) { |
|---|
| 600 | + returnValue = movieElement[functionName](); |
|---|
| 601 | + } else if (argumentArray.length === 1) { |
|---|
| 602 | + returnValue = movieElement[functionName](argumentArray[0]); |
|---|
| 603 | + } else if (argumentArray.length === 2) { |
|---|
| 604 | + returnValue = movieElement[functionName](argumentArray[0], argumentArray[1]); |
|---|
| 605 | + } else if (argumentArray.length === 3) { |
|---|
| 606 | + returnValue = movieElement[functionName](argumentArray[0], argumentArray[1], argumentArray[2]); |
|---|
| 607 | + } else { |
|---|
| 608 | + throw "Too many arguments"; |
|---|
| 609 | } |
|---|
| 610 | + |
|---|
| 611 | + // Unescape file post param values |
|---|
| 612 | + if (returnValue != undefined && typeof returnValue.post === "object") { |
|---|
| 613 | + returnValue = this.unescapeFilePostParams(returnValue); |
|---|
| 614 | + } |
|---|
| 615 | + |
|---|
| 616 | + return returnValue; |
|---|
| 617 | + } else { |
|---|
| 618 | + throw "Invalid function name: " + functionName; |
|---|
| 619 | } |
|---|
| 620 | - |
|---|
| 621 | - return output; |
|---|
| 622 | }; |
|---|
| 623 | |
|---|
| 624 | + |
|---|
| 625 | /* ***************************** |
|---|
| 626 | -- Flash control methods -- |
|---|
| 627 | Your UI should use these |
|---|
| 628 | to operate SWFUpload |
|---|
| 629 | ***************************** */ |
|---|
| 630 | |
|---|
| 631 | +// Public: selectFile causes a File Selection Dialog window to appear. This |
|---|
| 632 | +// dialog only allows 1 file to be selected. WARNING: this function does not work in Flash Player 10 |
|---|
| 633 | SWFUpload.prototype.selectFile = function () { |
|---|
| 634 | - var movie_element = this.getMovieElement(); |
|---|
| 635 | - if (movie_element !== null && typeof(movie_element.SelectFile) === "function") { |
|---|
| 636 | - try { |
|---|
| 637 | - movie_element.SelectFile(); |
|---|
| 638 | - } |
|---|
| 639 | - catch (ex) { |
|---|
| 640 | - this.debug("Could not call SelectFile: " + ex); |
|---|
| 641 | - } |
|---|
| 642 | - } else { |
|---|
| 643 | - this.debug("Could not find Flash element"); |
|---|
| 644 | - } |
|---|
| 645 | - |
|---|
| 646 | + this.callFlash("SelectFile"); |
|---|
| 647 | }; |
|---|
| 648 | |
|---|
| 649 | +// Public: selectFiles causes a File Selection Dialog window to appear/ This |
|---|
| 650 | +// dialog allows the user to select any number of files |
|---|
| 651 | +// Flash Bug Warning: Flash limits the number of selectable files based on the combined length of the file names. |
|---|
| 652 | +// If the selection name length is too long the dialog will fail in an unpredictable manner. There is no work-around |
|---|
| 653 | +// for this bug. WARNING: this function does not work in Flash Player 10 |
|---|
| 654 | SWFUpload.prototype.selectFiles = function () { |
|---|
| 655 | - var movie_element = this.getMovieElement(); |
|---|
| 656 | - if (movie_element !== null && typeof(movie_element.SelectFiles) === "function") { |
|---|
| 657 | - try { |
|---|
| 658 | - movie_element.SelectFiles(); |
|---|
| 659 | - } |
|---|
| 660 | - catch (ex) { |
|---|
| 661 | - this.debug("Could not call SelectFiles: " + ex); |
|---|
| 662 | - } |
|---|
| 663 | - } else { |
|---|
| 664 | - this.debug("Could not find Flash element"); |
|---|
| 665 | - } |
|---|
| 666 | - |
|---|
| 667 | + this.callFlash("SelectFiles"); |
|---|
| 668 | }; |
|---|
| 669 | |
|---|
| 670 | |
|---|
| 671 | -/* Start the upload. If a file_id is specified that file is uploaded. Otherwise the first |
|---|
| 672 | - * file in the queue is uploaded. If no files are in the queue then nothing happens. |
|---|
| 673 | - * This call uses setTimeout since Flash will be calling back in to JavaScript |
|---|
| 674 | - */ |
|---|
| 675 | -SWFUpload.prototype.startUpload = function (file_id) { |
|---|
| 676 | - var self = this; |
|---|
| 677 | - var movie_element = this.getMovieElement(); |
|---|
| 678 | - if (movie_element !== null && typeof(movie_element.StartUpload) === "function") { |
|---|
| 679 | - setTimeout( |
|---|
| 680 | - function () { |
|---|
| 681 | - try { |
|---|
| 682 | - movie_element.StartUpload(file_id); |
|---|
| 683 | - } |
|---|
| 684 | - catch (ex) { |
|---|
| 685 | - self.debug("Could not call StartUpload: " + ex); |
|---|
| 686 | - } |
|---|
| 687 | - }, 0 |
|---|
| 688 | - ); |
|---|
| 689 | - } else { |
|---|
| 690 | - this.debug("Could not find Flash element"); |
|---|
| 691 | - } |
|---|
| 692 | - |
|---|
| 693 | +// Public: startUpload starts uploading the first file in the queue unless |
|---|
| 694 | +// the optional parameter 'fileID' specifies the ID |
|---|
| 695 | +SWFUpload.prototype.startUpload = function (fileID) { |
|---|
| 696 | + this.callFlash("StartUpload", [fileID]); |
|---|
| 697 | }; |
|---|
| 698 | |
|---|
| 699 | /* Cancels a the file upload. You must specify a file_id */ |
|---|
| 700 | -SWFUpload.prototype.cancelUpload = function (file_id) { |
|---|
| 701 | - var movie_element = this.getMovieElement(); |
|---|
| 702 | - if (movie_element !== null && typeof(movie_element.CancelUpload) === "function") { |
|---|
| 703 | - try { |
|---|
| 704 | - movie_element.CancelUpload(file_id); |
|---|
| 705 | - } |
|---|
| 706 | - catch (ex) { |
|---|
| 707 | - this.debug("Could not call CancelUpload: " + ex); |
|---|
| 708 | - } |
|---|
| 709 | - } else { |
|---|
| 710 | - this.debug("Could not find Flash element"); |
|---|
| 711 | - } |
|---|
| 712 | - |
|---|
| 713 | +// Public: cancelUpload cancels any queued file. The fileID parameter |
|---|
| 714 | +// must be specified. |
|---|
| 715 | +SWFUpload.prototype.cancelUpload = function (fileID) { |
|---|
| 716 | + this.callFlash("CancelUpload", [fileID]); |
|---|
| 717 | }; |
|---|
| 718 | |
|---|
| 719 | -// Stops the current upload. The file is re-queued. If nothing is currently uploading then nothing happens. |
|---|
| 720 | +// Public: stopUpload stops the current upload and requeues the file at the beginning of the queue. |
|---|
| 721 | +// If nothing is currently uploading then nothing happens. |
|---|
| 722 | SWFUpload.prototype.stopUpload = function () { |
|---|
| 723 | - var movie_element = this.getMovieElement(); |
|---|
| 724 | - if (movie_element !== null && typeof(movie_element.StopUpload) === "function") { |
|---|
| 725 | - try { |
|---|
| 726 | - movie_element.StopUpload(); |
|---|
| 727 | - } |
|---|
| 728 | - catch (ex) { |
|---|
| 729 | - this.debug("Could not call StopUpload: " + ex); |
|---|
| 730 | - } |
|---|
| 731 | - } else { |
|---|
| 732 | - this.debug("Could not find Flash element"); |
|---|
| 733 | - } |
|---|
| 734 | - |
|---|
| 735 | + this.callFlash("StopUpload"); |
|---|
| 736 | }; |
|---|
| 737 | |
|---|
| 738 | /* ************************ |
|---|
| 739 | * Settings methods |
|---|
| 740 | - * These methods change the settings inside SWFUpload |
|---|
| 741 | - * They shouldn't need to be called in a setTimeout since they |
|---|
| 742 | - * should not call back from Flash to JavaScript (except perhaps in a Debug call) |
|---|
| 743 | - * and some need to return data so setTimeout won't work. |
|---|
| 744 | - */ |
|---|
| 745 | + * These methods change the SWFUpload settings. |
|---|
| 746 | + * SWFUpload settings should not be changed directly on the settings object |
|---|
| 747 | + * since many of the settings need to be passed to Flash in order to take |
|---|
| 748 | + * effect. |
|---|
| 749 | + * *********************** */ |
|---|
| 750 | |
|---|
| 751 | -/* Gets the file statistics object. It looks like this (where n = number): |
|---|
| 752 | - { |
|---|
| 753 | - files_queued: n, |
|---|
| 754 | - complete_uploads: n, |
|---|
| 755 | - upload_errors: n, |
|---|
| 756 | - uploads_cancelled: n, |
|---|
| 757 | - queue_errors: n |
|---|
| 758 | - } |
|---|
| 759 | -*/ |
|---|
| 760 | +// Public: getStats gets the file statistics object. |
|---|
| 761 | SWFUpload.prototype.getStats = function () { |
|---|
| 762 | - var movie_element = this.getMovieElement(); |
|---|
| 763 | - if (movie_element !== null && typeof(movie_element.GetStats) === "function") { |
|---|
| 764 | - try { |
|---|
| 765 | - return movie_element.GetStats(); |
|---|
| 766 | - } |
|---|
| 767 | - catch (ex) { |
|---|
| 768 | - this.debug("Could not call GetStats"); |
|---|
| 769 | - } |
|---|
| 770 | - } else { |
|---|
| 771 | - this.debug("Could not find Flash element"); |
|---|
| 772 | - } |
|---|
| 773 | + return this.callFlash("GetStats"); |
|---|
| 774 | }; |
|---|
| 775 | -SWFUpload.prototype.setStats = function (stats_object) { |
|---|
| 776 | - var movie_element = this.getMovieElement(); |
|---|
| 777 | - if (movie_element !== null && typeof(movie_element.SetStats) === "function") { |
|---|
| 778 | - try { |
|---|
| 779 | - movie_element.SetStats(stats_object); |
|---|
| 780 | - } |
|---|
| 781 | - catch (ex) { |
|---|
| 782 | - this.debug("Could not call SetStats"); |
|---|
| 783 | - } |
|---|
| 784 | - } else { |
|---|
| 785 | - this.debug("Could not find Flash element"); |
|---|
| 786 | - } |
|---|
| 787 | + |
|---|
| 788 | +// Public: setStats changes the SWFUpload statistics. You shouldn't need to |
|---|
| 789 | +// change the statistics but you can. Changing the statistics does not |
|---|
| 790 | +// affect SWFUpload accept for the successful_uploads count which is used |
|---|
| 791 | +// by the upload_limit setting to determine how many files the user may upload. |
|---|
| 792 | +SWFUpload.prototype.setStats = function (statsObject) { |
|---|
| 793 | + this.callFlash("SetStats", [statsObject]); |
|---|
| 794 | }; |
|---|
| 795 | |
|---|
| 796 | -SWFUpload.prototype.setCredentials = function(name, password) { |
|---|
| 797 | - var movie_element = this.getMovieElement(); |
|---|
| 798 | - if (movie_element !== null && typeof(movie_element.SetCredentials) === "function") { |
|---|
| 799 | - try { |
|---|
| 800 | - return movie_element.SetCredentials(name, password); |
|---|
| 801 | - } |
|---|
| 802 | - catch (ex) { |
|---|
| 803 | - this.debug("Could not call SetCredentials"); |
|---|
| 804 | - } |
|---|
| 805 | +// Public: getFile retrieves a File object by ID or Index. If the file is |
|---|
| 806 | +// not found then 'null' is returned. |
|---|
| 807 | +SWFUpload.prototype.getFile = function (fileID) { |
|---|
| 808 | + if (typeof(fileID) === "number") { |
|---|
| 809 | + return this.callFlash("GetFileByIndex", [fileID]); |
|---|
| 810 | } else { |
|---|
| 811 | - this.debug("Could not find Flash element"); |
|---|
| 812 | + return this.callFlash("GetFile", [fileID]); |
|---|
| 813 | } |
|---|
| 814 | }; |
|---|
| 815 | |
|---|
| 816 | -SWFUpload.prototype.getFile = function (file_id) { |
|---|
| 817 | - var movie_element = this.getMovieElement(); |
|---|
| 818 | - if (typeof(file_id) === "number") { |
|---|
| 819 | - if (movie_element !== null && typeof(movie_element.GetFileByIndex) === "function") { |
|---|
| 820 | - try { |
|---|
| 821 | - return movie_element.GetFileByIndex(file_id); |
|---|
| 822 | - } |
|---|
| 823 | - catch (ex) { |
|---|
| 824 | - this.debug("Could not call GetFileByIndex"); |
|---|
| 825 | - } |
|---|
| 826 | - } else { |
|---|
| 827 | - this.debug("Could not find Flash element"); |
|---|
| 828 | - } |
|---|
| 829 | - } else { |
|---|
| 830 | - if (movie_element !== null && typeof(movie_element.GetFile) === "function") { |
|---|
| 831 | - try { |
|---|
| 832 | - return movie_element.GetFile(file_id); |
|---|
| 833 | - } |
|---|
| 834 | - catch (ex) { |
|---|
| 835 | - this.debug("Could not call GetFile"); |
|---|
| 836 | - } |
|---|
| 837 | - } else { |
|---|
| 838 | - this.debug("Could not find Flash element"); |
|---|
| 839 | - } |
|---|
| 840 | - } |
|---|
| 841 | +// Public: addFileParam sets a name/value pair that will be posted with the |
|---|
| 842 | +// file specified by the Files ID. If the name already exists then the |
|---|
| 843 | +// exiting value will be overwritten. |
|---|
| 844 | +SWFUpload.prototype.addFileParam = function (fileID, name, value) { |
|---|
| 845 | + return this.callFlash("AddFileParam", [fileID, name, value]); |
|---|
| 846 | }; |
|---|
| 847 | |
|---|
| 848 | -SWFUpload.prototype.addFileParam = function (file_id, name, value) { |
|---|
| 849 | - var movie_element = this.getMovieElement(); |
|---|
| 850 | - if (movie_element !== null && typeof(movie_element.AddFileParam) === "function") { |
|---|
| 851 | - try { |
|---|
| 852 | - return movie_element.AddFileParam(file_id, name, value); |
|---|
| 853 | - } |
|---|
| 854 | - catch (ex) { |
|---|
| 855 | - this.debug("Could not call AddFileParam"); |
|---|
| 856 | - } |
|---|
| 857 | - } else { |
|---|
| 858 | - this.debug("Could not find Flash element"); |
|---|
| 859 | - } |
|---|
| 860 | +// Public: removeFileParam removes a previously set (by addFileParam) name/value |
|---|
| 861 | +// pair from the specified file. |
|---|
| 862 | +SWFUpload.prototype.removeFileParam = function (fileID, name) { |
|---|
| 863 | + this.callFlash("RemoveFileParam", [fileID, name]); |
|---|
| 864 | }; |
|---|
| 865 | |
|---|
| 866 | -SWFUpload.prototype.removeFileParam = function (file_id, name) { |
|---|
| 867 | - var movie_element = this.getMovieElement(); |
|---|
| 868 | - if (movie_element !== null && typeof(movie_element.RemoveFileParam) === "function") { |
|---|
| 869 | - try { |
|---|
| 870 | - return movie_element.RemoveFileParam(file_id, name); |
|---|
| 871 | - } |
|---|
| 872 | - catch (ex) { |
|---|
| 873 | - this.debug("Could not call AddFileParam"); |
|---|
| 874 | - } |
|---|
| 875 | - } else { |
|---|
| 876 | - this.debug("Could not find Flash element"); |
|---|
| 877 | - } |
|---|
| 878 | +// Public: setUploadUrl changes the upload_url setting. |
|---|
| 879 | +SWFUpload.prototype.setUploadURL = function (url) { |
|---|
| 880 | + this.settings.upload_url = url.toString(); |
|---|
| 881 | + this.callFlash("SetUploadURL", [url]); |
|---|
| 882 | +}; |
|---|
| 883 | |
|---|
| 884 | +// Public: setPostParams changes the post_params setting |
|---|
| 885 | +SWFUpload.prototype.setPostParams = function (paramsObject) { |
|---|
| 886 | + this.settings.post_params = paramsObject; |
|---|
| 887 | + this.callFlash("SetPostParams", [paramsObject]); |
|---|
| 888 | }; |
|---|
| 889 | |
|---|
| 890 | -SWFUpload.prototype.setUploadURL = function (url) { |
|---|
| 891 | - var movie_element = this.getMovieElement(); |
|---|
| 892 | - if (movie_element !== null && typeof(movie_element.SetUploadURL) === "function") { |
|---|
| 893 | - try { |
|---|
| 894 | - this.addSetting("upload_url", url); |
|---|
| 895 | - movie_element.SetUploadURL(this.getSetting("upload_url")); |
|---|
| 896 | - } |
|---|
| 897 | - catch (ex) { |
|---|
| 898 | - this.debug("Could not call SetUploadURL"); |
|---|
| 899 | - } |
|---|
| 900 | - } else { |
|---|
| 901 | - this.debug("Could not find Flash element in setUploadURL"); |
|---|
| 902 | - } |
|---|
| 903 | +// Public: addPostParam adds post name/value pair. Each name can have only one value. |
|---|
| 904 | +SWFUpload.prototype.addPostParam = function (name, value) { |
|---|
| 905 | + this.settings.post_params[name] = value; |
|---|
| 906 | + this.callFlash("SetPostParams", [this.settings.post_params]); |
|---|
| 907 | }; |
|---|
| 908 | |
|---|
| 909 | -SWFUpload.prototype.setPostParams = function (param_object) { |
|---|
| 910 | - var movie_element = this.getMovieElement(); |
|---|
| 911 | - if (movie_element !== null && typeof(movie_element.SetPostParams) === "function") { |
|---|
| 912 | - try { |
|---|
| 913 | - this.addSetting("post_params", param_object); |
|---|
| 914 | - movie_element.SetPostParams(this.getSetting("post_params")); |
|---|
| 915 | - } |
|---|
| 916 | - catch (ex) { |
|---|
| 917 | - this.debug("Could not call SetPostParams"); |
|---|
| 918 | - } |
|---|
| 919 | - } else { |
|---|
| 920 | - this.debug("Could not find Flash element in SetPostParams"); |
|---|
| 921 | - } |
|---|
| 922 | +// Public: removePostParam deletes post name/value pair. |
|---|
| 923 | +SWFUpload.prototype.removePostParam = function (name) { |
|---|
| 924 | + delete this.settings.post_params[name]; |
|---|
| 925 | + this.callFlash("SetPostParams", [this.settings.post_params]); |
|---|
| 926 | }; |
|---|
| 927 | |
|---|
| 928 | +// Public: setFileTypes changes the file_types setting and the file_types_description setting |
|---|
| 929 | SWFUpload.prototype.setFileTypes = function (types, description) { |
|---|
| 930 | - var movie_element = this.getMovieElement(); |
|---|
| 931 | - if (movie_element !== null && typeof(movie_element.SetFileTypes) === "function") { |
|---|
| 932 | - try { |
|---|
| 933 | - this.addSetting("file_types", types); |
|---|
| 934 | - this.addSetting("file_types_description", description); |
|---|
| 935 | - movie_element.SetFileTypes(this.getSetting("file_types"), this.getSetting("file_types_description")); |
|---|
| 936 | - } |
|---|
| 937 | - catch (ex) { |
|---|
| 938 | - this.debug("Could not call SetFileTypes"); |
|---|
| 939 | - } |
|---|
| 940 | - } else { |
|---|
| 941 | - this.debug("Could not find Flash element in SetFileTypes"); |
|---|
| 942 | - } |
|---|
| 943 | + this.settings.file_types = types; |
|---|
| 944 | + this.settings.file_types_description = description; |
|---|
| 945 | + this.callFlash("SetFileTypes", [types, description]); |
|---|
| 946 | }; |
|---|
| 947 | |
|---|
| 948 | -SWFUpload.prototype.setFileSizeLimit = function (file_size_limit) { |
|---|
| 949 | - var movie_element = this.getMovieElement(); |
|---|
| 950 | - if (movie_element !== null && typeof(movie_element.SetFileSizeLimit) === "function") { |
|---|
| 951 | - try { |
|---|
| 952 | - this.addSetting("file_size_limit", file_size_limit); |
|---|
| 953 | - movie_element.SetFileSizeLimit(this.getSetting("file_size_limit")); |
|---|
| 954 | - } |
|---|
| 955 | - catch (ex) { |
|---|
| 956 | - this.debug("Could not call SetFileSizeLimit"); |
|---|
| 957 | - } |
|---|
| 958 | - } else { |
|---|
| 959 | - this.debug("Could not find Flash element in SetFileSizeLimit"); |
|---|
| 960 | - } |
|---|
| 961 | +// Public: setFileSizeLimit changes the file_size_limit setting |
|---|
| 962 | +SWFUpload.prototype.setFileSizeLimit = function (fileSizeLimit) { |
|---|
| 963 | + this.settings.file_size_limit = fileSizeLimit; |
|---|
| 964 | + this.callFlash("SetFileSizeLimit", [fileSizeLimit]); |
|---|
| 965 | }; |
|---|
| 966 | |
|---|
| 967 | -SWFUpload.prototype.setFileUploadLimit = function (file_upload_limit) { |
|---|
| 968 | - var movie_element = this.getMovieElement(); |
|---|
| 969 | - if (movie_element !== null && typeof(movie_element.SetFileUploadLimit) === "function") { |
|---|
| 970 | - try { |
|---|
| 971 | - this.addSetting("file_upload_limit", file_upload_limit); |
|---|
| 972 | - movie_element.SetFileUploadLimit(this.getSetting("file_upload_limit")); |
|---|
| 973 | - } |
|---|
| 974 | - catch (ex) { |
|---|
| 975 | - this.debug("Could not call SetFileUploadLimit"); |
|---|
| 976 | - } |
|---|
| 977 | - } else { |
|---|
| 978 | - this.debug("Could not find Flash element in SetFileUploadLimit"); |
|---|
| 979 | - } |
|---|
| 980 | +// Public: setFileUploadLimit changes the file_upload_limit setting |
|---|
| 981 | +SWFUpload.prototype.setFileUploadLimit = function (fileUploadLimit) { |
|---|
| 982 | + this.settings.file_upload_limit = fileUploadLimit; |
|---|
| 983 | + this.callFlash("SetFileUploadLimit", [fileUploadLimit]); |
|---|
| 984 | }; |
|---|
| 985 | |
|---|
| 986 | -SWFUpload.prototype.setFileQueueLimit = function (file_queue_limit) { |
|---|
| 987 | - var movie_element = this.getMovieElement(); |
|---|
| 988 | - if (movie_element !== null && typeof(movie_element.SetFileQueueLimit) === "function") { |
|---|
| 989 | - try { |
|---|
| 990 | - this.addSetting("file_queue_limit", file_queue_limit); |
|---|
| 991 | - movie_element.SetFileQueueLimit(this.getSetting("file_queue_limit")); |
|---|
| 992 | - } |
|---|
| 993 | - catch (ex) { |
|---|
| 994 | - this.debug("Could not call SetFileQueueLimit"); |
|---|
| 995 | - } |
|---|
| 996 | - } else { |
|---|
| 997 | - this.debug("Could not find Flash element in SetFileQueueLimit"); |
|---|
| 998 | - } |
|---|
| 999 | +// Public: setFileQueueLimit changes the file_queue_limit setting |
|---|
| 1000 | +SWFUpload.prototype.setFileQueueLimit = function (fileQueueLimit) { |
|---|
| 1001 | + this.settings.file_queue_limit = fileQueueLimit; |
|---|
| 1002 | + this.callFlash("SetFileQueueLimit", [fileQueueLimit]); |
|---|
| 1003 | }; |
|---|
| 1004 | |
|---|
| 1005 | -SWFUpload.prototype.setFilePostName = function (file_post_name) { |
|---|
| 1006 | - var movie_element = this.getMovieElement(); |
|---|
| 1007 | - if (movie_element !== null && typeof(movie_element.SetFilePostName) === "function") { |
|---|
| 1008 | - try { |
|---|
| 1009 | - this.addSetting("file_post_name", file_post_name); |
|---|
| 1010 | - movie_element.SetFilePostName(this.getSetting("file_post_name")); |
|---|
| 1011 | - } |
|---|
| 1012 | - catch (ex) { |
|---|
| 1013 | - this.debug("Could not call SetFilePostName"); |
|---|
| 1014 | - } |
|---|
| 1015 | - } else { |
|---|
| 1016 | - this.debug("Could not find Flash element in SetFilePostName"); |
|---|
| 1017 | - } |
|---|
| 1018 | +// Public: setFilePostName changes the file_post_name setting |
|---|
| 1019 | +SWFUpload.prototype.setFilePostName = function (filePostName) { |
|---|
| 1020 | + this.settings.file_post_name = filePostName; |
|---|
| 1021 | + this.callFlash("SetFilePostName", [filePostName]); |
|---|
| 1022 | }; |
|---|
| 1023 | |
|---|
| 1024 | -SWFUpload.prototype.setDebugEnabled = function (debug_enabled) { |
|---|
| 1025 | - var movie_element = this.getMovieElement(); |
|---|
| 1026 | - if (movie_element !== null && typeof(movie_element.SetDebugEnabled) === "function") { |
|---|
| 1027 | - try { |
|---|
| 1028 | - this.addSetting("debug_enabled", debug_enabled); |
|---|
| 1029 | - movie_element.SetDebugEnabled(this.getSetting("debug_enabled")); |
|---|
| 1030 | - } |
|---|
| 1031 | - catch (ex) { |
|---|
| 1032 | - this.debug("Could not call SetDebugEnabled"); |
|---|
| 1033 | - } |
|---|
| 1034 | - } else { |
|---|
| 1035 | - this.debug("Could not find Flash element in SetDebugEnabled"); |
|---|
| 1036 | - } |
|---|
| 1037 | +// Public: setUseQueryString changes the use_query_string setting |
|---|
| 1038 | +SWFUpload.prototype.setUseQueryString = function (useQueryString) { |
|---|
| 1039 | + this.settings.use_query_string = useQueryString; |
|---|
| 1040 | + this.callFlash("SetUseQueryString", [useQueryString]); |
|---|
| 1041 | }; |
|---|
| 1042 | |
|---|
| 1043 | -/* ******************************* |
|---|
| 1044 | - Internal Event Callers |
|---|
| 1045 | - Don't override these! These event callers ensure that your custom event handlers |
|---|
| 1046 | - are called safely and in order. |
|---|
| 1047 | -******************************* */ |
|---|
| 1048 | - |
|---|
| 1049 | -/* This is the callback method that the Flash movie will call when it has been loaded and is ready to go. |
|---|
| 1050 | - Calling this or showUI() "manually" will bypass the Flash Detection built in to SWFUpload. |
|---|
| 1051 | - Use a ui_function setting if you want to control the UI loading after the flash has loaded. |
|---|
| 1052 | -*/ |
|---|
| 1053 | -SWFUpload.prototype.flashReady = function () { |
|---|
| 1054 | - // Check that the movie element is loaded correctly with its ExternalInterface methods defined |
|---|
| 1055 | - var movie_element = this.getMovieElement(); |
|---|
| 1056 | - if (movie_element === null || typeof(movie_element.StartUpload) !== "function") { |
|---|
| 1057 | - this.debug("ExternalInterface methods failed to initialize."); |
|---|
| 1058 | - return; |
|---|
| 1059 | - } |
|---|
| 1060 | - |
|---|
| 1061 | - var self = this; |
|---|
| 1062 | - if (typeof(self.flashReady_handler) === "function") { |
|---|
| 1063 | - this.eventQueue[this.eventQueue.length] = function() { self.flashReady_handler(); }; |
|---|
| 1064 | - setTimeout(function () { self.executeNextEvent();}, 0); |
|---|
| 1065 | - } else { |
|---|
| 1066 | - this.debug("flashReady_handler event not defined"); |
|---|
| 1067 | - } |
|---|
| 1068 | +// Public: setRequeueOnError changes the requeue_on_error setting |
|---|
| 1069 | +SWFUpload.prototype.setRequeueOnError = function (requeueOnError) { |
|---|
| 1070 | + this.settings.requeue_on_error = requeueOnError; |
|---|
| 1071 | + this.callFlash("SetRequeueOnError", [requeueOnError]); |
|---|
| 1072 | }; |
|---|
| 1073 | |
|---|
| 1074 | -/* |
|---|
| 1075 | - Event Queue. Rather can call events directly from Flash they events are |
|---|
| 1076 | - are placed in a queue and then executed. This ensures that each event is |
|---|
| 1077 | - executed in the order it was called which is not guarenteed when calling |
|---|
| 1078 | - setTimeout. Out of order events was especially problematic in Safari. |
|---|
| 1079 | -*/ |
|---|
| 1080 | -SWFUpload.prototype.executeNextEvent = function () { |
|---|
| 1081 | - var f = this.eventQueue.shift(); |
|---|
| 1082 | - if (typeof(f) === "function") { |
|---|
| 1083 | - f(); |
|---|
| 1084 | - } |
|---|
| 1085 | -} |
|---|
| 1086 | - |
|---|
| 1087 | -/* This is a chance to do something before the browse window opens */ |
|---|
| 1088 | -SWFUpload.prototype.fileDialogStart = function () { |
|---|
| 1089 | - var self = this; |
|---|
| 1090 | - if (typeof(self.fileDialogStart_handler) === "function") { |
|---|
| 1091 | - this.eventQueue[this.eventQueue.length] = function() { self.fileDialogStart_handler(); }; |
|---|
| 1092 | - setTimeout(function () { self.executeNextEvent();}, 0); |
|---|
| 1093 | - } else { |
|---|
| 1094 | - this.debug("fileDialogStart event not defined"); |
|---|
| 1095 | - } |
|---|
| 1096 | +// Public: setDebugEnabled changes the debug_enabled setting |
|---|
| 1097 | +SWFUpload.prototype.setDebugEnabled = function (debugEnabled) { |
|---|
| 1098 | + this.settings.debug_enabled = debugEnabled; |
|---|
| 1099 | + this.callFlash("SetDebugEnabled", [debugEnabled]); |
|---|
| 1100 | }; |
|---|
| 1101 | |
|---|
| 1102 | - |
|---|
| 1103 | -/* Called when a file is successfully added to the queue. */ |
|---|
| 1104 | -SWFUpload.prototype.fileQueued = function (file) { |
|---|
| 1105 | - var self = this; |
|---|
| 1106 | - if (typeof(self.fileQueued_handler) === "function") { |
|---|
| 1107 | - this.eventQueue[this.eventQueue.length] = function() { self.fileQueued_handler(file); }; |
|---|
| 1108 | - setTimeout(function () { self.executeNextEvent();}, 0); |
|---|
| 1109 | - } else { |
|---|
| 1110 | - this.debug("fileQueued event not defined"); |
|---|
| 1111 | +// Public: setButtonImageURL loads a button image sprite |
|---|
| 1112 | +SWFUpload.prototype.setButtonImageURL = function (buttonImageURL) { |
|---|
| 1113 | + if (buttonImageURL == undefined) { |
|---|
| 1114 | + buttonImageURL = ""; |
|---|
| 1115 | } |
|---|
| 1116 | + |
|---|
| 1117 | + this.settings.button_image_url = buttonImageURL; |
|---|
| 1118 | + this.callFlash("SetButtonImageURL", [buttonImageURL]); |
|---|
| 1119 | }; |
|---|
| 1120 | |
|---|
| 1121 | - |
|---|
| 1122 | -/* Handle errors that occur when an attempt to queue a file fails. */ |
|---|
| 1123 | -SWFUpload.prototype.fileQueueError = function (file, error_code, message) { |
|---|
| 1124 | - var self = this; |
|---|
| 1125 | - if (typeof(self.fileQueueError_handler) === "function") { |
|---|
| 1126 | - this.eventQueue[this.eventQueue.length] = function() { self.fileQueueError_handler(file, error_code, message); }; |
|---|
| 1127 | - setTimeout(function () { self.executeNextEvent();}, 0); |
|---|
| 1128 | - } else { |
|---|
| 1129 | - this.debug("fileQueueError event not defined"); |
|---|
| 1130 | +// Public: setButtonDimensions resizes the Flash Movie and button |
|---|
| 1131 | +SWFUpload.prototype.setButtonDimensions = function (width, height) { |
|---|
| 1132 | + this.settings.button_width = width; |
|---|
| 1133 | + this.settings.button_height = height; |
|---|
| 1134 | + |
|---|
| 1135 | + var movie = this.getMovieElement(); |
|---|
| 1136 | + if (movie != undefined) { |
|---|
| 1137 | + movie.style.width = width + "px"; |
|---|
| 1138 | + movie.style.height = height + "px"; |
|---|
| 1139 | } |
|---|
| 1140 | + |
|---|
| 1141 | + this.callFlash("SetButtonDimensions", [width, height]); |
|---|
| 1142 | }; |
|---|
| 1143 | +// Public: setButtonText Changes the text overlaid on the button |
|---|
| 1144 | +SWFUpload.prototype.setButtonText = function (html) { |
|---|
| 1145 | + this.settings.button_text = html; |
|---|
| 1146 | + this.callFlash("SetButtonText", [html]); |
|---|
| 1147 | +}; |
|---|
| 1148 | +// Public: setButtonTextPadding changes the top and left padding of the text overlay |
|---|
| 1149 | +SWFUpload.prototype.setButtonTextPadding = function (left, top) { |
|---|
| 1150 | + this.settings.button_text_top_padding = top; |
|---|
| 1151 | + this.settings.button_text_left_padding = left; |
|---|
| 1152 | + this.callFlash("SetButtonTextPadding", [left, top]); |
|---|
| 1153 | +}; |
|---|
| 1154 | |
|---|
| 1155 | -/* Called after the file dialog has closed and the selected files have been queued. |
|---|
| 1156 | - You could call startUpload here if you want the queued files to begin uploading immediately. */ |
|---|
| 1157 | -SWFUpload.prototype.fileDialogComplete = function (num_files_selected) { |
|---|
| 1158 | - var self = this; |
|---|
| 1159 | - if (typeof(self.fileDialogComplete_handler) === "function") { |
|---|
| 1160 | - this.eventQueue[this.eventQueue.length] = function() { self.fileDialogComplete_handler(num_files_selected); }; |
|---|
| 1161 | - setTimeout(function () { self.executeNextEvent();}, 0); |
|---|
| 1162 | - } else { |
|---|
| 1163 | - this.debug("fileDialogComplete event not defined"); |
|---|
| 1164 | - } |
|---|
| 1165 | +// Public: setButtonTextStyle changes the CSS used to style the HTML/Text overlaid on the button |
|---|
| 1166 | +SWFUpload.prototype.setButtonTextStyle = function (css) { |
|---|
| 1167 | + this.settings.button_text_style = css; |
|---|
| 1168 | + this.callFlash("SetButtonTextStyle", [css]); |
|---|
| 1169 | }; |
|---|
| 1170 | +// Public: setButtonDisabled disables/enables the button |
|---|
| 1171 | +SWFUpload.prototype.setButtonDisabled = function (isDisabled) { |
|---|
| 1172 | + this.settings.button_disabled = isDisabled; |
|---|
| 1173 | + this.callFlash("SetButtonDisabled", [isDisabled]); |
|---|
| 1174 | +}; |
|---|
| 1175 | +// Public: setButtonAction sets the action that occurs when the button is clicked |
|---|
| 1176 | +SWFUpload.prototype.setButtonAction = function (buttonAction) { |
|---|
| 1177 | + this.settings.button_action = buttonAction; |
|---|
| 1178 | + this.callFlash("SetButtonAction", [buttonAction]); |
|---|
| 1179 | +}; |
|---|
| 1180 | |
|---|
| 1181 | -/* Gets called when a file upload is about to be started. Return true to continue the upload. Return false to stop the upload. |
|---|
| 1182 | - If you return false then uploadError and uploadComplete are called (like normal). |
|---|
| 1183 | +/* ******************************* |
|---|
| 1184 | + Flash Event Interfaces |
|---|
| 1185 | + These functions are used by Flash to trigger the various |
|---|
| 1186 | + events. |
|---|
| 1187 | |
|---|
| 1188 | - This is a good place to do any file validation you need. |
|---|
| 1189 | - */ |
|---|
| 1190 | -SWFUpload.prototype.uploadStart = function (file) { |
|---|
| 1191 | + All these functions a Private. |
|---|
| 1192 | + |
|---|
| 1193 | + Because the ExternalInterface library is buggy the event calls |
|---|
| 1194 | + are added to a queue and the queue then executed by a setTimeout. |
|---|
| 1195 | + This ensures that events are executed in a determinate order and that |
|---|
| 1196 | + the ExternalInterface bugs are avoided. |
|---|
| 1197 | +******************************* */ |
|---|
| 1198 | + |
|---|
| 1199 | +SWFUpload.prototype.queueEvent = function (handlerName, argumentArray) { |
|---|
| 1200 | + // Warning: Don't call this.debug inside here or you'll create an infinite loop |
|---|
| 1201 | + |
|---|
| 1202 | + if (argumentArray == undefined) { |
|---|
| 1203 | + argumentArray = []; |
|---|
| 1204 | + } else if (!(argumentArray instanceof Array)) { |
|---|
| 1205 | + argumentArray = [argumentArray]; |
|---|
| 1206 | + } |
|---|
| 1207 | + |
|---|
| 1208 | var self = this; |
|---|
| 1209 | - if (typeof(self.fileDialogComplete_handler) === "function") { |
|---|
| 1210 | - this.eventQueue[this.eventQueue.length] = function() { self.returnUploadStart(self.uploadStart_handler(file)); }; |
|---|
| 1211 | - setTimeout(function () { self.executeNextEvent();}, 0); |
|---|
| 1212 | - } else { |
|---|
| 1213 | - this.debug("uploadStart event not defined"); |
|---|
| 1214 | + if (typeof this.settings[handlerName] === "function") { |
|---|
| 1215 | + // Queue the event |
|---|
| 1216 | + this.eventQueue.push(function () { |
|---|
| 1217 | + this.settings[handlerName].apply(this, argumentArray); |
|---|
| 1218 | + }); |
|---|
| 1219 | + |
|---|
| 1220 | + // Execute the next queued event |
|---|
| 1221 | + setTimeout(function () { |
|---|
| 1222 | + self.executeNextEvent(); |
|---|
| 1223 | + }, 0); |
|---|
| 1224 | + |
|---|
| 1225 | + } else if (this.settings[handlerName] !== null) { |
|---|
| 1226 | + throw "Event handler " + handlerName + " is unknown or is not a function"; |
|---|
| 1227 | } |
|---|
| 1228 | }; |
|---|
| 1229 | |
|---|
| 1230 | -/* Note: Internal use only. This function returns the result of uploadStart to |
|---|
| 1231 | - flash. Since returning values in the normal way can result in Flash/JS circular |
|---|
| 1232 | - call issues we split up the call in a Timeout. This is transparent from the API |
|---|
| 1233 | - point of view. |
|---|
| 1234 | -*/ |
|---|
| 1235 | -SWFUpload.prototype.returnUploadStart = function (return_value) { |
|---|
| 1236 | - var movie_element = this.getMovieElement(); |
|---|
| 1237 | - if (movie_element !== null && typeof(movie_element.ReturnUploadStart) === "function") { |
|---|
| 1238 | - try { |
|---|
| 1239 | - movie_element.ReturnUploadStart(return_value); |
|---|
| 1240 | - } |
|---|
| 1241 | - catch (ex) { |
|---|
| 1242 | - this.debug("Could not call ReturnUploadStart"); |
|---|
| 1243 | - } |
|---|
| 1244 | - } else { |
|---|
| 1245 | - this.debug("Could not find Flash element in returnUploadStart"); |
|---|
| 1246 | +// Private: Causes the next event in the queue to be executed. Since events are queued using a setTimeout |
|---|
| 1247 | +// we must queue them in order to garentee that they are executed in order. |
|---|
| 1248 | +SWFUpload.prototype.executeNextEvent = function () { |
|---|
| 1249 | + // Warning: Don't call this.debug inside here or you'll create an infinite loop |
|---|
| 1250 | + |
|---|
| 1251 | + var f = this.eventQueue ? this.eventQueue.shift() : null; |
|---|
| 1252 | + if (typeof(f) === "function") { |
|---|
| 1253 | + f.apply(this); |
|---|
| 1254 | } |
|---|
| 1255 | }; |
|---|
| 1256 | |
|---|
| 1257 | +// Private: unescapeFileParams is part of a workaround for a flash bug where objects passed through ExternalInterface cannot have |
|---|
| 1258 | +// properties that contain characters that are not valid for JavaScript identifiers. To work around this |
|---|
| 1259 | +// the Flash Component escapes the parameter names and we must unescape again before passing them along. |
|---|
| 1260 | +SWFUpload.prototype.unescapeFilePostParams = function (file) { |
|---|
| 1261 | + var reg = /[$]([0-9a-f]{4})/i; |
|---|
| 1262 | + var unescapedPost = {}; |
|---|
| 1263 | + var uk; |
|---|
| 1264 | |
|---|
| 1265 | + if (file != undefined) { |
|---|
| 1266 | + for (var k in file.post) { |
|---|
| 1267 | + if (file.post.hasOwnProperty(k)) { |
|---|
| 1268 | + uk = k; |
|---|
| 1269 | + var match; |
|---|
| 1270 | + while ((match = reg.exec(uk)) !== null) { |
|---|
| 1271 | + uk = uk.replace(match[0], String.fromCharCode(parseInt("0x" + match[1], 16))); |
|---|
| 1272 | + } |
|---|
| 1273 | + unescapedPost[uk] = file.post[k]; |
|---|
| 1274 | + } |
|---|
| 1275 | + } |
|---|
| 1276 | |
|---|
| 1277 | -/* Called during upload as the file progresses. Use this event to update your UI. */ |
|---|
| 1278 | -SWFUpload.prototype.uploadProgress = function (file, bytes_complete, bytes_total) { |
|---|
| 1279 | - var self = this; |
|---|
| 1280 | - if (typeof(self.uploadProgress_handler) === "function") { |
|---|
| 1281 | - this.eventQueue[this.eventQueue.length] = function() { self.uploadProgress_handler(file, bytes_complete, bytes_total); }; |
|---|
| 1282 | - setTimeout(function () { self.executeNextEvent();}, 0); |
|---|
| 1283 | - } else { |
|---|
| 1284 | - this.debug("uploadProgress event not defined"); |
|---|
| 1285 | + file.post = unescapedPost; |
|---|
| 1286 | } |
|---|
| 1287 | -}; |
|---|
| 1288 | |
|---|
| 1289 | -/* Called when an error occurs during an upload. Use error_code and the SWFUpload.UPLOAD_ERROR constants to determine |
|---|
| 1290 | - which error occurred. The uploadComplete event is called after an error code indicating that the next file is |
|---|
| 1291 | - ready for upload. For files cancelled out of order the uploadComplete event will not be called. */ |
|---|
| 1292 | -SWFUpload.prototype.uploadError = function (file, error_code, message) { |
|---|
| 1293 | - var self = this; |
|---|
| 1294 | - if (typeof(this.uploadError_handler) === "function") { |
|---|
| 1295 | - this.eventQueue[this.eventQueue.length] = function() { self.uploadError_handler(file, error_code, message); }; |
|---|
| 1296 | - setTimeout(function () { self.executeNextEvent();}, 0); |
|---|
| 1297 | - } else { |
|---|
| 1298 | - this.debug("uploadError event not defined"); |
|---|
| 1299 | - } |
|---|
| 1300 | + return file; |
|---|
| 1301 | }; |
|---|
| 1302 | |
|---|
| 1303 | -/* This gets called when a file finishes uploading and the server-side upload script has completed and returned a 200 |
|---|
| 1304 | -status code. Any text returned by the server is available in server_data. |
|---|
| 1305 | -**NOTE: The upload script MUST return some text or the uploadSuccess and uploadComplete events will not fire and the |
|---|
| 1306 | -upload will become 'stuck'. */ |
|---|
| 1307 | -SWFUpload.prototype.uploadSuccess = function (file, server_data) { |
|---|
| 1308 | - var self = this; |
|---|
| 1309 | - if (typeof(self.uploadSuccess_handler) === "function") { |
|---|
| 1310 | - this.eventQueue[this.eventQueue.length] = function() { self.uploadSuccess_handler(file, server_data); }; |
|---|
| 1311 | - setTimeout(function () { self.executeNextEvent();}, 0); |
|---|
| 1312 | - } else { |
|---|
| 1313 | - this.debug("uploadSuccess event not defined"); |
|---|
| 1314 | +SWFUpload.prototype.flashReady = function () { |
|---|
| 1315 | + // Check that the movie element is loaded correctly with its ExternalInterface methods defined |
|---|
| 1316 | + var movieElement = this.getMovieElement(); |
|---|
| 1317 | + if (typeof movieElement.StartUpload !== "function") { |
|---|
| 1318 | + throw "ExternalInterface methods failed to initialize."; |
|---|
| 1319 | } |
|---|
| 1320 | -}; |
|---|
| 1321 | |
|---|
| 1322 | -/* uploadComplete is called when the file is uploaded or an error occurred and SWFUpload is ready to make the next upload. |
|---|
| 1323 | - If you want the next upload to start to automatically you can call startUpload() from this event. */ |
|---|
| 1324 | -SWFUpload.prototype.uploadComplete = function (file) { |
|---|
| 1325 | - var self = this; |
|---|
| 1326 | - if (typeof(self.uploadComplete_handler) === "function") { |
|---|
| 1327 | - this.eventQueue[this.eventQueue.length] = function() { self.uploadComplete_handler(file); }; |
|---|
| 1328 | - setTimeout(function () { self.executeNextEvent();}, 0); |
|---|
| 1329 | - } else { |
|---|
| 1330 | - this.debug("uploadComplete event not defined"); |
|---|
| 1331 | + // Fix IE Flash/Form bug |
|---|
| 1332 | + if (window[this.movieName] == undefined) { |
|---|
| 1333 | + window[this.movieName] = movieElement; |
|---|
| 1334 | } |
|---|
| 1335 | -}; |
|---|
| 1336 | - |
|---|
| 1337 | -/* Called by SWFUpload JavaScript and Flash functions when debug is enabled. By default it writes messages to the |
|---|
| 1338 | - internal debug console. You can override this event and have messages written where you want. */ |
|---|
| 1339 | -SWFUpload.prototype.debug = function (message) { |
|---|
| 1340 | - var self = this; |
|---|
| 1341 | - if (typeof(self.debug_handler) === "function") { |
|---|
| 1342 | - this.eventQueue[this.eventQueue.length] = function() { self.debug_handler(message); }; |
|---|
| 1343 | - setTimeout(function () { self.executeNextEvent();}, 0); |
|---|
| 1344 | - } else { |
|---|
| 1345 | - this.eventQueue[this.eventQueue.length] = function() { self.debugMessage(message); }; |
|---|
| 1346 | - setTimeout(function () { self.executeNextEvent();}, 0); |
|---|
| 1347 | - } |
|---|
| 1348 | -}; |
|---|
| 1349 | - |
|---|
| 1350 | - |
|---|
| 1351 | -/* ********************************** |
|---|
| 1352 | - Default Event Handlers. |
|---|
| 1353 | - These event handlers are used by default if an overriding handler is |
|---|
| 1354 | - not defined in the SWFUpload settings object. |
|---|
| 1355 | |
|---|
| 1356 | - JS Note: even though these are defined on the SWFUpload object (rather than the prototype) they |
|---|
| 1357 | - are attached (read: copied) to a SWFUpload instance and 'this' is given the proper context. |
|---|
| 1358 | - ********************************** */ |
|---|
| 1359 | - |
|---|
| 1360 | -/* This is a special event handler that has no override in the settings. Flash calls this when it has |
|---|
| 1361 | - been loaded by the browser and is ready for interaction. You should not override it. If you need |
|---|
| 1362 | - to do something with SWFUpload has loaded then use the swfupload_loaded_handler setting. |
|---|
| 1363 | -*/ |
|---|
| 1364 | -SWFUpload.flashReady = function () { |
|---|
| 1365 | - try { |
|---|
| 1366 | - this.debug("Flash called back and is ready."); |
|---|
| 1367 | - |
|---|
| 1368 | - if (typeof(this.swfUploadLoaded_handler) === "function") { |
|---|
| 1369 | - this.swfUploadLoaded_handler(); |
|---|
| 1370 | - } |
|---|
| 1371 | - } catch (ex) { |
|---|
| 1372 | - this.debug(ex); |
|---|
| 1373 | - } |
|---|
| 1374 | + this.queueEvent("swfupload_loaded_handler"); |
|---|
| 1375 | }; |
|---|
| 1376 | |
|---|
| 1377 | -/* This is a chance to something immediately after SWFUpload has loaded. |
|---|
| 1378 | - Like, hide the default/degraded upload form and display the SWFUpload form. */ |
|---|
| 1379 | -SWFUpload.swfUploadLoaded = function () { |
|---|
| 1380 | -}; |
|---|
| 1381 | |
|---|
| 1382 | /* This is a chance to do something before the browse window opens */ |
|---|
| 1383 | -SWFUpload.fileDialogStart = function () { |
|---|
| 1384 | +SWFUpload.prototype.fileDialogStart = function () { |
|---|
| 1385 | + this.queueEvent("file_dialog_start_handler"); |
|---|
| 1386 | }; |
|---|
| 1387 | |
|---|
| 1388 | |
|---|
| 1389 | /* Called when a file is successfully added to the queue. */ |
|---|
| 1390 | -SWFUpload.fileQueued = function (file) { |
|---|
| 1391 | +SWFUpload.prototype.fileQueued = function (file) { |
|---|
| 1392 | + file = this.unescapeFilePostParams(file); |
|---|
| 1393 | + this.queueEvent("file_queued_handler", file); |
|---|
| 1394 | }; |
|---|
| 1395 | |
|---|
| 1396 | |
|---|
| 1397 | /* Handle errors that occur when an attempt to queue a file fails. */ |
|---|
| 1398 | -SWFUpload.fileQueueError = function (file, error_code, message) { |
|---|
| 1399 | - try { |
|---|
| 1400 | - switch (error_code) { |
|---|
| 1401 | - case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT: |
|---|
| 1402 | - this.debug("Error Code: File too big, File name: " + file.name + ", File size: " + file.size + ", Message: " + message); |
|---|
| 1403 | - break; |
|---|
| 1404 | - case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE: |
|---|
| 1405 | - this.debug("Error Code: Zero Byte File, File name: " + file.name + ", File size: " + file.size + ", Message: " + message); |
|---|
| 1406 | - break; |
|---|
| 1407 | - case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED: |
|---|
| 1408 | - this.debug("Error Code: Upload limit reached, File name: " + file.name + ", File size: " + file.size + ", Message: " + message); |
|---|
| 1409 | - break; |
|---|
| 1410 | - case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE: |
|---|
| 1411 | - this.debug("Error Code: File extension is not allowed, Message: " + message); |
|---|
| 1412 | - break; |
|---|
| 1413 | - default: |
|---|
| 1414 | - this.debug("Error Code: Unhandled error occured. Errorcode: " + error_code); |
|---|
| 1415 | - } |
|---|
| 1416 | - } catch (ex) { |
|---|
| 1417 | - this.debug(ex); |
|---|
| 1418 | - } |
|---|
| 1419 | +SWFUpload.prototype.fileQueueError = function (file, errorCode, message) { |
|---|
| 1420 | + file = this.unescapeFilePostParams(file); |
|---|
| 1421 | + this.queueEvent("file_queue_error_handler", [file, errorCode, message]); |
|---|
| 1422 | }; |
|---|
| 1423 | |
|---|
| 1424 | /* Called after the file dialog has closed and the selected files have been queued. |
|---|
| 1425 | You could call startUpload here if you want the queued files to begin uploading immediately. */ |
|---|
| 1426 | -SWFUpload.fileDialogComplete = function (num_files_selected) { |
|---|
| 1427 | +SWFUpload.prototype.fileDialogComplete = function (numFilesSelected, numFilesQueued) { |
|---|
| 1428 | + this.queueEvent("file_dialog_complete_handler", [numFilesSelected, numFilesQueued]); |
|---|
| 1429 | }; |
|---|
| 1430 | |
|---|
| 1431 | -/* Gets called when a file upload is about to be started. Return true to continue the upload. Return false to stop the upload. |
|---|
| 1432 | - If you return false then the uploadError callback is called and then uploadComplete (like normal). |
|---|
| 1433 | +SWFUpload.prototype.uploadStart = function (file) { |
|---|
| 1434 | + file = this.unescapeFilePostParams(file); |
|---|
| 1435 | + this.queueEvent("return_upload_start_handler", file); |
|---|
| 1436 | +}; |
|---|
| 1437 | + |
|---|
| 1438 | +SWFUpload.prototype.returnUploadStart = function (file) { |
|---|
| 1439 | + var returnValue; |
|---|
| 1440 | + if (typeof this.settings.upload_start_handler === "function") { |
|---|
| 1441 | + file = this.unescapeFilePostParams(file); |
|---|
| 1442 | + returnValue = this.settings.upload_start_handler.call(this, file); |
|---|
| 1443 | + } else if (this.settings.upload_start_handler != undefined) { |
|---|
| 1444 | + throw "upload_start_handler must be a function"; |
|---|
| 1445 | + } |
|---|
| 1446 | + |
|---|
| 1447 | + // Convert undefined to true so if nothing is returned from the upload_start_handler it is |
|---|
| 1448 | + // interpretted as 'true'. |
|---|
| 1449 | + if (returnValue === undefined) { |
|---|
| 1450 | + returnValue = true; |
|---|
| 1451 | + } |
|---|
| 1452 | |
|---|
| 1453 | - This is a good place to do any file validation you need. |
|---|
| 1454 | + returnValue = !!returnValue; |
|---|
| 1455 | |
|---|
| 1456 | - This is the only function that cannot be called on a setTimeout because it must return a value to Flash. |
|---|
| 1457 | - You SHOULD NOT make any calls in to Flash (e.i, changing settings, getting stats, etc). Flash Player bugs prevent |
|---|
| 1458 | - calls in to Flash from working reliably. |
|---|
| 1459 | -*/ |
|---|
| 1460 | -SWFUpload.uploadStart = function (file) { |
|---|
| 1461 | - return true; |
|---|
| 1462 | + this.callFlash("ReturnUploadStart", [returnValue]); |
|---|
| 1463 | }; |
|---|
| 1464 | |
|---|
| 1465 | -// Called during upload as the file progresses |
|---|
| 1466 | -SWFUpload.uploadProgress = function (file, bytes_complete, bytes_total) { |
|---|
| 1467 | - this.debug("File Progress: " + file.id + ", Bytes: " + bytes_complete + ". Total: " + bytes_total); |
|---|
| 1468 | + |
|---|
| 1469 | + |
|---|
| 1470 | +SWFUpload.prototype.uploadProgress = function (file, bytesComplete, bytesTotal) { |
|---|
| 1471 | + file = this.unescapeFilePostParams(file); |
|---|
| 1472 | + this.queueEvent("upload_progress_handler", [file, bytesComplete, bytesTotal]); |
|---|
| 1473 | }; |
|---|
| 1474 | |
|---|
| 1475 | -/* This gets called when a file finishes uploading and the upload script has completed and returned a 200 status code. Any text returned by the |
|---|
| 1476 | -server is available in server_data. The upload script must return some text or uploadSuccess will not fire (neither will uploadComplete). */ |
|---|
| 1477 | -SWFUpload.uploadSuccess = function (file, server_data) { |
|---|
| 1478 | - this.debug("Upload Success: " + file.id + ", Server: " + server_data); |
|---|
| 1479 | +SWFUpload.prototype.uploadError = function (file, errorCode, message) { |
|---|
| 1480 | + file = this.unescapeFilePostParams(file); |
|---|
| 1481 | + this.queueEvent("upload_error_handler", [file, errorCode, message]); |
|---|
| 1482 | }; |
|---|
| 1483 | |
|---|
| 1484 | -/* This is called last. The file is uploaded or an error occurred and SWFUpload is ready to make the next upload. |
|---|
| 1485 | - If you want to automatically start the next file just call startUpload from here. |
|---|
| 1486 | -*/ |
|---|
| 1487 | -SWFUpload.uploadComplete = function (file) { |
|---|
| 1488 | - this.debug("Upload Complete: " + file.id); |
|---|
| 1489 | +SWFUpload.prototype.uploadSuccess = function (file, serverData) { |
|---|
| 1490 | + file = this.unescapeFilePostParams(file); |
|---|
| 1491 | + this.queueEvent("upload_success_handler", [file, serverData]); |
|---|
| 1492 | }; |
|---|
| 1493 | |
|---|
| 1494 | -// Called by SWFUpload JavaScript and Flash functions when debug is enabled. |
|---|
| 1495 | -// Override this method in your settings to call your own debug message handler |
|---|
| 1496 | -SWFUpload.debug = function (message) { |
|---|
| 1497 | - if (this.getSetting("debug_enabled")) { |
|---|
| 1498 | - this.debugMessage(message); |
|---|
| 1499 | - } |
|---|
| 1500 | +SWFUpload.prototype.uploadComplete = function (file) { |
|---|
| 1501 | + file = this.unescapeFilePostParams(file); |
|---|
| 1502 | + this.queueEvent("upload_complete_handler", file); |
|---|
| 1503 | }; |
|---|
| 1504 | |
|---|
| 1505 | -/* Called when an upload occurs during upload. For HTTP errors 'message' will contain the HTTP STATUS CODE */ |
|---|
| 1506 | -SWFUpload.uploadError = function (file, errcode, msg) { |
|---|
| 1507 | - try { |
|---|
| 1508 | - switch (errcode) { |
|---|
| 1509 | - case SWFUpload.UPLOAD_ERROR.SPECIFIED_FILE_ID_NOT_FOUND: |
|---|
| 1510 | - this.debug("Error Code: File ID specified for upload was not found, Message: " + msg); |
|---|
| 1511 | - break; |
|---|
| 1512 | - case SWFUpload.UPLOAD_ERROR.HTTP_ERROR: |
|---|
| 1513 | - this.debug("Error Code: HTTP Error, File name: " + file.name + ", Message: " + msg); |
|---|
| 1514 | - break; |
|---|
| 1515 | - case SWFUpload.UPLOAD_ERROR.MISSING_UPLOAD_URL: |
|---|
| 1516 | - this.debug("Error Code: No backend file, File name: " + file.name + ", Message: " + msg); |
|---|
| 1517 | - break; |
|---|
| 1518 | - case SWFUpload.UPLOAD_ERROR.IO_ERROR: |
|---|
| 1519 | - this.debug("Error Code: IO Error, File name: " + file.name + ", Message: " + msg); |
|---|
| 1520 | - break; |
|---|
| 1521 | - case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR: |
|---|
| 1522 | - this.debug("Error Code: Security Error, File name: " + file.name + ", Message: " + msg); |
|---|
| 1523 | - break; |
|---|
| 1524 | - case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED: |
|---|
| 1525 | - this.debug("Error Code: Upload limit reached, File name: " + file.name + ", File size: " + file.size + ", Message: " + msg); |
|---|
| 1526 | - break; |
|---|
| 1527 | - case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED: |
|---|
| 1528 | - this.debug("Error Code: Upload Initialization exception, File name: " + file.name + ", File size: " + file.size + ", Message: " + msg); |
|---|
| 1529 | - break; |
|---|
| 1530 | - case SWFUpload.UPLOAD_ERROR.FILE_VALIDATION_FAILED: |
|---|
| 1531 | - this.debug("Error Code: uploadStart callback returned false, File name: " + file.name + ", File size: " + file.size + ", Message: " + msg); |
|---|
| 1532 | - break; |
|---|
| 1533 | - case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED: |
|---|
| 1534 | - this.debug("Error Code: The file upload was cancelled, File name: " + file.name + ", File size: " + file.size + ", Message: " + msg); |
|---|
| 1535 | - break; |
|---|
| 1536 | - case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED: |
|---|
| 1537 | - this.debug("Error Code: The file upload was stopped, File name: " + file.name + ", File size: " + file.size + ", Message: " + msg); |
|---|
| 1538 | - break; |
|---|
| 1539 | - default: |
|---|
| 1540 | - this.debug("Error Code: Unhandled error occured. Errorcode: " + errcode); |
|---|
| 1541 | - } |
|---|
| 1542 | - } catch (ex) { |
|---|
| 1543 | - this.debug(ex); |
|---|
| 1544 | - } |
|---|
| 1545 | +/* Called by SWFUpload JavaScript and Flash functions when debug is enabled. By default it writes messages to the |
|---|
| 1546 | + internal debug console. You can override this event and have messages written where you want. */ |
|---|
| 1547 | +SWFUpload.prototype.debug = function (message) { |
|---|
| 1548 | + this.queueEvent("debug_handler", message); |
|---|
| 1549 | }; |
|---|
| 1550 | |
|---|
| 1551 | |
|---|
| 1552 | - |
|---|
| 1553 | /* ********************************** |
|---|
| 1554 | Debug Console |
|---|
| 1555 | The debug console is a self contained, in page location |
|---|
| 1556 | @@ -998,24 +828,32 @@ |
|---|
| 1557 | |
|---|
| 1558 | The console is automatically scrolled as messages appear. |
|---|
| 1559 | |
|---|
| 1560 | - You can override this console (to use FireBug's console for instance) by setting the debug event method to your own function |
|---|
| 1561 | - that handles the debug message |
|---|
| 1562 | - ********************************** */ |
|---|
| 1563 | + If you are using your own debug handler or when you deploy to production and |
|---|
| 1564 | + have debug disabled you can remove these functions to reduce the file size |
|---|
| 1565 | + and complexity. |
|---|
| 1566 | +********************************** */ |
|---|
| 1567 | + |
|---|
| 1568 | +// Private: debugMessage is the default debug_handler. If you want to print debug messages |
|---|
| 1569 | +// call the debug() function. When overriding the function your own function should |
|---|
| 1570 | +// check to see if the debug setting is true before outputting debug information. |
|---|
| 1571 | SWFUpload.prototype.debugMessage = function (message) { |
|---|
| 1572 | - var exception_message, exception_values; |
|---|
| 1573 | + if (this.settings.debug) { |
|---|
| 1574 | + var exceptionMessage, exceptionValues = []; |
|---|
| 1575 | |
|---|
| 1576 | - if (typeof(message) === "object" && typeof(message.name) === "string" && typeof(message.message) === "string") { |
|---|
| 1577 | - exception_message = ""; |
|---|
| 1578 | - exception_values = []; |
|---|
| 1579 | - for (var key in message) { |
|---|
| 1580 | - exception_values.push(key + ": " + message[key]); |
|---|
| 1581 | + // Check for an exception object and print it nicely |
|---|
| 1582 | + if (typeof message === "object" && typeof message.name === "string" && typeof message.message === "string") { |
|---|
| 1583 | + for (var key in message) { |
|---|
| 1584 | + if (message.hasOwnProperty(key)) { |
|---|
| 1585 | + exceptionValues.push(key + ": " + message[key]); |
|---|
| 1586 | + } |
|---|
| 1587 | + } |
|---|
| 1588 | + exceptionMessage = exceptionValues.join("\n") || ""; |
|---|
| 1589 | + exceptionValues = exceptionMessage.split("\n"); |
|---|
| 1590 | + exceptionMessage = "EXCEPTION: " + exceptionValues.join("\nEXCEPTION: "); |
|---|
| 1591 | + SWFUpload.Console.writeLine(exceptionMessage); |
|---|
| 1592 | + } else { |
|---|
| 1593 | + SWFUpload.Console.writeLine(message); |
|---|
| 1594 | } |
|---|
| 1595 | - exception_message = exception_values.join("\n"); |
|---|
| 1596 | - exception_values = exception_message.split("\n"); |
|---|
| 1597 | - exception_message = "EXCEPTION: " + exception_values.join("\nEXCEPTION: "); |
|---|
| 1598 | - SWFUpload.Console.writeLine(exception_message); |
|---|
| 1599 | - } else { |
|---|
| 1600 | - SWFUpload.Console.writeLine(message); |
|---|
| 1601 | } |
|---|
| 1602 | }; |
|---|
| 1603 | |
|---|
| 1604 | Index: wp-includes/js/swfupload/plugins/swfupload.queue.js |
|---|
| 1605 | =================================================================== |
|---|
| 1606 | --- wp-includes/js/swfupload/plugins/swfupload.queue.js (revision 9385) |
|---|
| 1607 | +++ wp-includes/js/swfupload/plugins/swfupload.queue.js (working copy) |
|---|
| 1608 | @@ -2,9 +2,12 @@ |
|---|
| 1609 | Queue Plug-in |
|---|
| 1610 | |
|---|
| 1611 | Features: |
|---|
| 1612 | - cancelQueue method for cancelling the entire queue. |
|---|
| 1613 | - All queued files are uploaded when startUpload() is called. |
|---|
| 1614 | - If false is returned from uploadComplete then the queue upload is stopped. If false is not returned (strict comparison) then the queue upload is continued. |
|---|
| 1615 | + *Adds a cancelQueue() method for cancelling the entire queue. |
|---|
| 1616 | + *All queued files are uploaded when startUpload() is called. |
|---|
| 1617 | + *If false is returned from uploadComplete then the queue upload is stopped. |
|---|
| 1618 | + If false is not returned (strict comparison) then the queue upload is continued. |
|---|
| 1619 | + *Adds a QueueComplete event that is fired when all the queued files have finished uploading. |
|---|
| 1620 | + Set the event handler with the queue_complete_handler setting. |
|---|
| 1621 | |
|---|
| 1622 | */ |
|---|
| 1623 | |
|---|
| 1624 | @@ -12,47 +15,63 @@ |
|---|
| 1625 | if (typeof(SWFUpload) === "function") { |
|---|
| 1626 | SWFUpload.queue = {}; |
|---|
| 1627 | |
|---|
| 1628 | - SWFUpload.prototype.initSettings = function (old_initSettings) { |
|---|
| 1629 | - return function (init_settings) { |
|---|
| 1630 | - if (typeof(old_initSettings) === "function") { |
|---|
| 1631 | - old_initSettings.call(this, init_settings); |
|---|
| 1632 | + SWFUpload.prototype.initSettings = (function (oldInitSettings) { |
|---|
| 1633 | + return function () { |
|---|
| 1634 | + if (typeof(oldInitSettings) === "function") { |
|---|
| 1635 | + oldInitSettings.call(this); |
|---|
| 1636 | } |
|---|
| 1637 | |
|---|
| 1638 | this.customSettings.queue_cancelled_flag = false; |
|---|
| 1639 | + this.customSettings.queue_upload_count = 0; |
|---|
| 1640 | |
|---|
| 1641 | - this.addSetting("user_upload_complete_handler", init_settings.upload_complete_handler, SWFUpload.uploadComplete); |
|---|
| 1642 | - this.uploadComplete_handler = SWFUpload.queue.uploadComplete; |
|---|
| 1643 | + this.settings.user_upload_complete_handler = this.settings.upload_complete_handler; |
|---|
| 1644 | + this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler; |
|---|
| 1645 | + |
|---|
| 1646 | + this.settings.queue_complete_handler = this.settings.queue_complete_handler || null; |
|---|
| 1647 | }; |
|---|
| 1648 | - }(SWFUpload.prototype.initSettings); |
|---|
| 1649 | + })(SWFUpload.prototype.initSettings); |
|---|
| 1650 | |
|---|
| 1651 | - SWFUpload.prototype.cancelQueue = function () { |
|---|
| 1652 | - var stats = this.getStats(); |
|---|
| 1653 | + SWFUpload.prototype.startUpload = function (fileID) { |
|---|
| 1654 | this.customSettings.queue_cancelled_flag = false; |
|---|
| 1655 | + this.callFlash("StartUpload", false, [fileID]); |
|---|
| 1656 | + }; |
|---|
| 1657 | |
|---|
| 1658 | - if (stats.in_progress > 0) { |
|---|
| 1659 | - this.customSettings.queue_cancelled_flag = true; |
|---|
| 1660 | - } |
|---|
| 1661 | + SWFUpload.prototype.cancelQueue = function () { |
|---|
| 1662 | + this.customSettings.queue_cancelled_flag = true; |
|---|
| 1663 | + this.stopUpload(); |
|---|
| 1664 | |
|---|
| 1665 | - while(stats.files_queued > 0) { |
|---|
| 1666 | + var stats = this.getStats(); |
|---|
| 1667 | + while (stats.files_queued > 0) { |
|---|
| 1668 | this.cancelUpload(); |
|---|
| 1669 | stats = this.getStats(); |
|---|
| 1670 | } |
|---|
| 1671 | }; |
|---|
| 1672 | |
|---|
| 1673 | - SWFUpload.queue.uploadComplete = function (file) { |
|---|
| 1674 | - var user_upload_complete_handler = this.getSetting("user_upload_complete_handler"); |
|---|
| 1675 | - var continue_upload = true; |
|---|
| 1676 | + SWFUpload.queue.uploadCompleteHandler = function (file) { |
|---|
| 1677 | + var user_upload_complete_handler = this.settings.user_upload_complete_handler; |
|---|
| 1678 | + var continueUpload; |
|---|
| 1679 | + |
|---|
| 1680 | + if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) { |
|---|
| 1681 | + this.customSettings.queue_upload_count++; |
|---|
| 1682 | + } |
|---|
| 1683 | + |
|---|
| 1684 | if (typeof(user_upload_complete_handler) === "function") { |
|---|
| 1685 | - continue_upload = (user_upload_complete_handler.call(this, file) === false) ? false : true; |
|---|
| 1686 | + continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true; |
|---|
| 1687 | + } else { |
|---|
| 1688 | + continueUpload = true; |
|---|
| 1689 | } |
|---|
| 1690 | |
|---|
| 1691 | - if (continue_upload) { |
|---|
| 1692 | + if (continueUpload) { |
|---|
| 1693 | var stats = this.getStats(); |
|---|
| 1694 | if (stats.files_queued > 0 && this.customSettings.queue_cancelled_flag === false) { |
|---|
| 1695 | this.startUpload(); |
|---|
| 1696 | + } else if (this.customSettings.queue_cancelled_flag === false) { |
|---|
| 1697 | + this.queueEvent("queue_complete_handler", [this.customSettings.queue_upload_count]); |
|---|
| 1698 | + this.customSettings.queue_upload_count = 0; |
|---|
| 1699 | } else { |
|---|
| 1700 | this.customSettings.queue_cancelled_flag = false; |
|---|
| 1701 | + this.customSettings.queue_upload_count = 0; |
|---|
| 1702 | } |
|---|
| 1703 | } |
|---|
| 1704 | }; |
|---|
| 1705 | Index: wp-includes/js/swfupload/plugins/swfupload.swfobject.js |
|---|
| 1706 | =================================================================== |
|---|
| 1707 | --- wp-includes/js/swfupload/plugins/swfupload.swfobject.js (revision 0) |
|---|
| 1708 | +++ wp-includes/js/swfupload/plugins/swfupload.swfobject.js (revision 0) |
|---|
| 1709 | @@ -0,0 +1,108 @@ |
|---|
| 1710 | +/* |
|---|
| 1711 | + SWFUpload.SWFObject Plugin |
|---|
| 1712 | + |
|---|
| 1713 | + Summary: |
|---|
| 1714 | + This plugin uses SWFObject to embed SWFUpload dynamically in the page. SWFObject provides accurate Flash Player detection and DOM Ready loading. |
|---|
| 1715 | + This plugin replaces the Graceful Degradation plugin. |
|---|
| 1716 | + |
|---|
| 1717 | + Features: |
|---|
| 1718 | + * swfupload_load_failed_hander event |
|---|
| 1719 | + * swfupload_pre_load_handler event |
|---|
| 1720 | + * minimum_flash_version setting (default: "9.0.28") |
|---|
| 1721 | + * SWFUpload.onload event for early loading |
|---|
| 1722 | + |
|---|
| 1723 | + Usage: |
|---|
| 1724 | + Provide handlers and settings as needed. When using the SWFUpload.SWFObject plugin you should initialize SWFUploading |
|---|
| 1725 | + in SWFUpload.onload rather than in window.onload. When initialized this way SWFUpload can load earlier preventing the UI flicker |
|---|
| 1726 | + that was seen using the Graceful Degradation plugin. |
|---|
| 1727 | + |
|---|
| 1728 | + <script type="text/javascript"> |
|---|
| 1729 | + var swfu; |
|---|
| 1730 | + SWFUpload.onload = function () { |
|---|
| 1731 | + swfu = new SWFUpload({ |
|---|
| 1732 | + minimum_flash_version: "9.0.28", |
|---|
| 1733 | + swfupload_pre_load_handler: swfuploadPreLoad, |
|---|
| 1734 | + swfupload_load_failed_handler: swfuploadLoadFailed |
|---|
| 1735 | + }); |
|---|
| 1736 | + }; |
|---|
| 1737 | + </script> |
|---|
| 1738 | + |
|---|
| 1739 | + Notes: |
|---|
| 1740 | + You must provide set minimum_flash_version setting to "8" if you are using SWFUpload for Flash Player 8. |
|---|
| 1741 | + The swfuploadLoadFailed event is only fired if the minimum version of Flash Player is not met. Other issues such as missing SWF files, browser bugs |
|---|
| 1742 | + or corrupt Flash Player installations will not trigger this event. |
|---|
| 1743 | + The swfuploadPreLoad event is fired as soon as the minimum version of Flash Player is found. It does not wait for SWFUpload to load and can |
|---|
| 1744 | + be used to prepare the SWFUploadUI and hide alternate content. |
|---|
| 1745 | + swfobject's onDomReady event is cross-browser safe but will default to the window.onload event when DOMReady is not supported by the browser. |
|---|
| 1746 | + Early DOM Loading is supported in major modern browsers but cannot be guaranteed for every browser ever made. |
|---|
| 1747 | +*/ |
|---|
| 1748 | + |
|---|
| 1749 | + |
|---|
| 1750 | +/* SWFObject v2.0 rc4 <http://code.google.com/p/swfobject/> |
|---|
| 1751 | + Copyright (c) 2007 Geoff Stearns, Michael Williams, and Bobby van der Sluis |
|---|
| 1752 | + This software is released under the MIT License <http://www.opensource.org/licenses/mit-license.php> |
|---|
| 1753 | +*/ |
|---|
| 1754 | +var swfobject=function(){var X="undefined",P="object",a="visibility:visible",e="visibility:hidden",B="Shockwave Flash",h="ShockwaveFlash.ShockwaveFlash",V="application/x-shockwave-flash",K="SWFObjectExprInst",G=window,g=document,N=navigator,f=[],H=[],Q=null,L=null,S=false,C=false;var Y=function(){var l=typeof g.getElementById!=X&&typeof g.getElementsByTagName!=X&&typeof g.createElement!=X&&typeof g.appendChild!=X&&typeof g.replaceChild!=X&&typeof g.removeChild!=X&&typeof g.cloneNode!=X,t=[0,0,0],n=null;if(typeof N.plugins!=X&&typeof N.plugins[B]==P){n=N.plugins[B].description;if(n){n=n.replace(/^.*\s+(\S+\s+\S+$)/,"$1");t[0]=parseInt(n.replace(/^(.*)\..*$/,"$1"),10);t[1]=parseInt(n.replace(/^.*\.(.*)\s.*$/,"$1"),10);t[2]=/r/.test(n)?parseInt(n.replace(/^.*r(.*)$/,"$1"),10):0}}else{if(typeof G.ActiveXObject!=X){var o=null,s=false;try{o=new ActiveXObject(h+".7")}catch(k){try{o=new ActiveXObject(h+".6");t=[6,0,21];o.AllowScriptAccess="always"}catch(k){if(t[0]==6){s=true}}if(!s){try{o=new ActiveXObject(h)}catch(k){}}}if(!s&&o){try{n=o.GetVariable("$version");if(n){n=n.split(" ")[1].split(",");t=[parseInt(n[0],10),parseInt(n[1],10),parseInt(n[2],10)]}}catch(k){}}}}var v=N.userAgent.toLowerCase(),j=N.platform.toLowerCase(),r=/webkit/.test(v)?parseFloat(v.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):false,i=false,q=j?/win/.test(j):/win/.test(v),m=j?/mac/.test(j):/mac/.test(v);/*@cc_on i=true;@if(@_win32)q=true;@elif(@_mac)m=true;@end@*/return{w3cdom:l,pv:t,webkit:r,ie:i,win:q,mac:m}}();var d=function(){if(!Y.w3cdom){return }J(I);if(Y.ie&&Y.win){try{g.write("<script id=__ie_ondomload defer=true src=//:><\/script>");var i=b("__ie_ondomload");if(i){i.onreadystatechange=function(){if(this.readyState=="complete"){this.parentNode.removeChild(this);U()}}}}catch(j){}}if(Y.webkit&&typeof g.readyState!=X){Q=setInterval(function(){if(/loaded|complete/.test(g.readyState)){U()}},10)}if(typeof g.addEventListener!=X){g.addEventListener("DOMContentLoaded",U,null)}M(U)}();function U(){if(S){return }if(Y.ie&&Y.win){var m=W("span");try{var l=g.getElementsByTagName("body")[0].appendChild(m);l.parentNode.removeChild(l)}catch(n){return }}S=true;if(Q){clearInterval(Q);Q=null}var j=f.length;for(var k=0;k<j;k++){f[k]()}}function J(i){if(S){i()}else{f[f.length]=i}}function M(j){if(typeof G.addEventListener!=X){G.addEventListener("load",j,false)}else{if(typeof g.addEventListener!=X){g.addEventListener("load",j,false)}else{if(typeof G.attachEvent!=X){G.attachEvent("onload",j)}else{if(typeof G.onload=="function"){var i=G.onload;G.onload=function(){i();j()}}else{G.onload=j}}}}}function I(){var l=H.length;for(var j=0;j<l;j++){var m=H[j].id;if(Y.pv[0]>0){var k=b(m);if(k){H[j].width=k.getAttribute("width")?k.getAttribute("width"):"0";H[j].height=k.getAttribute("height")?k.getAttribute("height"):"0";if(O(H[j].swfVersion)){if(Y.webkit&&Y.webkit<312){T(k)}}else{if(H[j].expressInstall&&!C&&O("6.0.65")&&(Y.win||Y.mac)){D(H[j])}else{c(k)}}}}A("#"+m,a)}}function T(m){var k=m.getElementsByTagName(P)[0];if(k){var p=W("embed"),r=k.attributes;if(r){var o=r.length;for(var n=0;n<o;n++){if(r[n].nodeName.toLowerCase()=="data"){p.setAttribute("src",r[n].nodeValue)}else{p.setAttribute(r[n].nodeName,r[n].nodeValue)}}}var q=k.childNodes;if(q){var s=q.length;for(var l=0;l<s;l++){if(q[l].nodeType==1&&q[l].nodeName.toLowerCase()=="param"){p.setAttribute(q[l].getAttribute("name"),q[l].getAttribute("value"))}}}m.parentNode.replaceChild(p,m)}}function F(i){if(Y.ie&&Y.win&&O("8.0.0")){G.attachEvent("onunload",function(){var k=b(i);for(var j in k){if(typeof k[j]=="function"){k[j]=function(){}}}k.parentNode.removeChild(k)})}}function D(j){C=true;var o=b(j.id);if(o){if(j.altContentId){var l=b(j.altContentId);if(l){L=l}}else{L=Z(o)}if(!(/%$/.test(j.width))&&parseInt(j.width,10)<310){j.width="310"}if(!(/%$/.test(j.height))&&parseInt(j.height,10)<137){j.height="137"}g.title=g.title.slice(0,47)+" - Flash Player Installation";var n=Y.ie&&Y.win?"ActiveX":"PlugIn",k=g.title,m="MMredirectURL="+G.location+"&MMplayerType="+n+"&MMdoctitle="+k,p=j.id;if(Y.ie&&Y.win&&o.readyState!=4){var i=W("div");p+="SWFObjectNew";i.setAttribute("id",p);o.parentNode.insertBefore(i,o);o.style.display="none";G.attachEvent("onload",function(){o.parentNode.removeChild(o)})}R({data:j.expressInstall,id:K,width:j.width,height:j.height},{flashvars:m},p)}}function c(j){if(Y.ie&&Y.win&&j.readyState!=4){var i=W("div");j.parentNode.insertBefore(i,j);i.parentNode.replaceChild(Z(j),i);j.style.display="none";G.attachEvent("onload",function(){j.parentNode.removeChild(j)})}else{j.parentNode.replaceChild(Z(j),j)}}function Z(n){var m=W("div");if(Y.win&&Y.ie){m.innerHTML=n.innerHTML}else{var k=n.getElementsByTagName(P)[0];if(k){var o=k.childNodes;if(o){var j=o.length;for(var l=0;l<j;l++){if(!(o[l].nodeType==1&&o[l].nodeName.toLowerCase()=="param")&&!(o[l].nodeType==8)){m.appendChild(o[l].cloneNode(true))}}}}}return m}function R(AE,AC,q){var p,t=b(q);if(typeof AE.id==X){AE.id=q}if(Y.ie&&Y.win){var AD="";for(var z in AE){if(AE[z]!=Object.prototype[z]){if(z=="data"){AC.movie=AE[z]}else{if(z.toLowerCase()=="styleclass"){AD+=' class="'+AE[z]+'"'}else{if(z!="classid"){AD+=" "+z+'="'+AE[z]+'"'}}}}}var AB="";for(var y in AC){if(AC[y]!=Object.prototype[y]){AB+='<param name="'+y+'" value="'+AC[y]+'" />'}}t.outerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+AD+">"+AB+"</object>";F(AE.id);p=b(AE.id)}else{if(Y.webkit&&Y.webkit<312){var AA=W("embed");AA.setAttribute("type",V);for(var x in AE){if(AE[x]!=Object.prototype[x]){if(x=="data"){AA.setAttribute("src",AE[x])}else{if(x.toLowerCase()=="styleclass"){AA.setAttribute("class",AE[x])}else{if(x!="classid"){AA.setAttribute(x,AE[x])}}}}}for(var w in AC){if(AC[w]!=Object.prototype[w]){if(w!="movie"){AA.setAttribute(w,AC[w])}}}t.parentNode.replaceChild(AA,t);p=AA}else{var s=W(P);s.setAttribute("type",V);for(var v in AE){if(AE[v]!=Object.prototype[v]){if(v.toLowerCase()=="styleclass"){s.setAttribute("class",AE[v])}else{if(v!="classid"){s.setAttribute(v,AE[v])}}}}for(var u in AC){if(AC[u]!=Object.prototype[u]&&u!="movie"){E(s,u,AC[u])}}t.parentNode.replaceChild(s,t);p=s}}return p}function E(k,i,j){var l=W("param");l.setAttribute("name",i);l.setAttribute("value",j);k.appendChild(l)}function b(i){return g.getElementById(i)}function W(i){return g.createElement(i)}function O(k){var j=Y.pv,i=k.split(".");i[0]=parseInt(i[0],10);i[1]=parseInt(i[1],10);i[2]=parseInt(i[2],10);return(j[0]>i[0]||(j[0]==i[0]&&j[1]>i[1])||(j[0]==i[0]&&j[1]==i[1]&&j[2]>=i[2]))?true:false}function A(m,j){if(Y.ie&&Y.mac){return }var l=g.getElementsByTagName("head")[0],k=W("style");k.setAttribute("type","text/css");k.setAttribute("media","screen");if(!(Y.ie&&Y.win)&&typeof g.createTextNode!=X){k.appendChild(g.createTextNode(m+" {"+j+"}"))}l.appendChild(k);if(Y.ie&&Y.win&&typeof g.styleSheets!=X&&g.styleSheets.length>0){var i=g.styleSheets[g.styleSheets.length-1];if(typeof i.addRule==P){i.addRule(m,j)}}}return{registerObject:function(l,i,k){if(!Y.w3cdom||!l||!i){return }var j={};j.id=l;j.swfVersion=i;j.expressInstall=k?k:false;H[H.length]=j;A("#"+l,e)},getObjectById:function(l){var i=null;if(Y.w3cdom&&S){var j=b(l);if(j){var k=j.getElementsByTagName(P)[0];if(!k||(k&&typeof j.SetVariable!=X)){i=j}else{if(typeof k.SetVariable!=X){i=k}}}}return i},embedSWF:function(n,u,r,t,j,m,k,p,s){if(!Y.w3cdom||!n||!u||!r||!t||!j){return }r+="";t+="";if(O(j)){A("#"+u,e);var q=(typeof s==P)?s:{};q.data=n;q.width=r;q.height=t;var o=(typeof p==P)?p:{};if(typeof k==P){for(var l in k){if(k[l]!=Object.prototype[l]){if(typeof o.flashvars!=X){o.flashvars+="&"+l+"="+k[l]}else{o.flashvars=l+"="+k[l]}}}}J(function(){R(q,o,u);A("#"+u,a)})}else{if(m&&!C&&O("6.0.65")&&(Y.win||Y.mac)){A("#"+u,e);J(function(){var i={};i.id=i.altContentId=u;i.width=r;i.height=t;i.expressInstall=m;D(i);A("#"+u,a)})}}},getFlashPlayerVersion:function(){return{major:Y.pv[0],minor:Y.pv[1],release:Y.pv[2]}},hasFlashPlayerVersion:O,createSWF:function(k,j,i){if(Y.w3cdom&&S){return R(k,j,i)}else{return undefined}},createCSS:function(j,i){if(Y.w3cdom){A(j,i)}},addDomLoadEvent:J,addLoadEvent:M,getQueryParamValue:function(m){var l=g.location.search||g.location.hash;if(m==null){return l}if(l){var k=l.substring(1).split("&");for(var j=0;j<k.length;j++){if(k[j].substring(0,k[j].indexOf("="))==m){return k[j].substring((k[j].indexOf("=")+1))}}}return""},expressInstallCallback:function(){if(C&&L){var i=b(K);if(i){i.parentNode.replaceChild(L,i);L=null;C=false}}}}}(); |
|---|
| 1755 | + |
|---|
| 1756 | + |
|---|
| 1757 | +var SWFUpload; |
|---|
| 1758 | +if (typeof(SWFUpload) === "function") { |
|---|
| 1759 | + SWFUpload.onload = function () {}; |
|---|
| 1760 | + |
|---|
| 1761 | + swfobject.addDomLoadEvent(function () { |
|---|
| 1762 | + if (typeof(SWFUpload.onload) === "function") { |
|---|
| 1763 | + SWFUpload.onload.call(window); |
|---|
| 1764 | + } |
|---|
| 1765 | + }); |
|---|
| 1766 | + |
|---|
| 1767 | + SWFUpload.prototype.initSettings = (function (oldInitSettings) { |
|---|
| 1768 | + return function () { |
|---|
| 1769 | + if (typeof(oldInitSettings) === "function") { |
|---|
| 1770 | + oldInitSettings.call(this); |
|---|
| 1771 | + } |
|---|
| 1772 | + |
|---|
| 1773 | + this.ensureDefault = function (settingName, defaultValue) { |
|---|
| 1774 | + this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName]; |
|---|
| 1775 | + }; |
|---|
| 1776 | + |
|---|
| 1777 | + this.ensureDefault("minimum_flash_version", "9.0.28"); |
|---|
| 1778 | + this.ensureDefault("swfupload_load_failed_handler", null); |
|---|
| 1779 | + |
|---|
| 1780 | + delete this.ensureDefault; |
|---|
| 1781 | + |
|---|
| 1782 | + }; |
|---|
| 1783 | + })(SWFUpload.prototype.initSettings); |
|---|
| 1784 | + |
|---|
| 1785 | + |
|---|
| 1786 | + SWFUpload.prototype.loadFlash = function (oldLoadFlash) { |
|---|
| 1787 | + return function () { |
|---|
| 1788 | + var hasFlash = swfobject.hasFlashPlayerVersion(this.settings.minimum_flash_version); |
|---|
| 1789 | + |
|---|
| 1790 | + if (hasFlash) { |
|---|
| 1791 | + this.queueEvent("swfupload_pre_load_handler"); |
|---|
| 1792 | + if (typeof(oldLoadFlash) === "function") { |
|---|
| 1793 | + oldLoadFlash.call(this); |
|---|
| 1794 | + } |
|---|
| 1795 | + } else { |
|---|
| 1796 | + this.queueEvent("swfupload_load_failed_handler"); |
|---|
| 1797 | + } |
|---|
| 1798 | + }; |
|---|
| 1799 | + |
|---|
| 1800 | + }(SWFUpload.prototype.loadFlash); |
|---|
| 1801 | + |
|---|
| 1802 | + SWFUpload.prototype.displayDebugInfo = function (oldDisplayDebugInfo) { |
|---|
| 1803 | + return function () { |
|---|
| 1804 | + if (typeof(oldDisplayDebugInfo) === "function") { |
|---|
| 1805 | + oldDisplayDebugInfo.call(this); |
|---|
| 1806 | + } |
|---|
| 1807 | + |
|---|
| 1808 | + this.debug( |
|---|
| 1809 | + [ |
|---|
| 1810 | + "SWFUpload.SWFObject Plugin settings:", "\n", |
|---|
| 1811 | + "\t", "minimum_flash_version: ", this.settings.minimum_flash_version, "\n", |
|---|
| 1812 | + "\t", "swfupload_load_failed_handler assigned: ", (typeof(this.settings.swfupload_load_failed_handler) === "function").toString(), "\n", |
|---|
| 1813 | + ].join("") |
|---|
| 1814 | + ); |
|---|
| 1815 | + }; |
|---|
| 1816 | + }(SWFUpload.prototype.displayDebugInfo); |
|---|
| 1817 | +} |
|---|
| 1818 | Index: wp-includes/js/swfupload/plugins/swfupload.cookies.js |
|---|
| 1819 | =================================================================== |
|---|
| 1820 | --- wp-includes/js/swfupload/plugins/swfupload.cookies.js (revision 9385) |
|---|
| 1821 | +++ wp-includes/js/swfupload/plugins/swfupload.cookies.js (working copy) |
|---|
| 1822 | @@ -8,42 +8,45 @@ |
|---|
| 1823 | |
|---|
| 1824 | var SWFUpload; |
|---|
| 1825 | if (typeof(SWFUpload) === "function") { |
|---|
| 1826 | - SWFUpload.prototype.initSettings = function (old_initSettings) { |
|---|
| 1827 | - return function (init_settings) { |
|---|
| 1828 | - if (typeof(old_initSettings) === "function") { |
|---|
| 1829 | - old_initSettings.call(this, init_settings); |
|---|
| 1830 | + SWFUpload.prototype.initSettings = function (oldInitSettings) { |
|---|
| 1831 | + return function () { |
|---|
| 1832 | + if (typeof(oldInitSettings) === "function") { |
|---|
| 1833 | + oldInitSettings.call(this); |
|---|
| 1834 | } |
|---|
| 1835 | |
|---|
| 1836 | this.refreshCookies(false); // The false parameter must be sent since SWFUpload has not initialzed at this point |
|---|
| 1837 | }; |
|---|
| 1838 | }(SWFUpload.prototype.initSettings); |
|---|
| 1839 | |
|---|
| 1840 | - // refreshes the post_params and updates SWFUpload. The send_to_flash parameters is optional and defaults to True |
|---|
| 1841 | - SWFUpload.prototype.refreshCookies = function (send_to_flash) { |
|---|
| 1842 | - if (send_to_flash !== false) send_to_flash = true; |
|---|
| 1843 | + // refreshes the post_params and updates SWFUpload. The sendToFlash parameters is optional and defaults to True |
|---|
| 1844 | + SWFUpload.prototype.refreshCookies = function (sendToFlash) { |
|---|
| 1845 | + if (sendToFlash === undefined) { |
|---|
| 1846 | + sendToFlash = true; |
|---|
| 1847 | + } |
|---|
| 1848 | + sendToFlash = !!sendToFlash; |
|---|
| 1849 | |
|---|
| 1850 | // Get the post_params object |
|---|
| 1851 | - var post_params = this.getSetting("post_params"); |
|---|
| 1852 | + var postParams = this.settings.post_params; |
|---|
| 1853 | |
|---|
| 1854 | // Get the cookies |
|---|
| 1855 | - var i, cookie_array = document.cookie.split(';'), ca_length = cookie_array.length, c, eq_index, name, value; |
|---|
| 1856 | - for(i = 0; i < ca_length; i++) { |
|---|
| 1857 | - c = cookie_array[i]; |
|---|
| 1858 | + var i, cookieArray = document.cookie.split(';'), caLength = cookieArray.length, c, eqIndex, name, value; |
|---|
| 1859 | + for (i = 0; i < caLength; i++) { |
|---|
| 1860 | + c = cookieArray[i]; |
|---|
| 1861 | |
|---|
| 1862 | // Left Trim spaces |
|---|
| 1863 | - while (c.charAt(0) == " ") { |
|---|
| 1864 | + while (c.charAt(0) === " ") { |
|---|
| 1865 | c = c.substring(1, c.length); |
|---|
| 1866 | } |
|---|
| 1867 | - eq_index = c.indexOf("="); |
|---|
| 1868 | - if (eq_index > 0) { |
|---|
| 1869 | - name = c.substring(0, eq_index); |
|---|
| 1870 | - value = c.substring(eq_index+1); |
|---|
| 1871 | - post_params[name] = value; |
|---|
| 1872 | + eqIndex = c.indexOf("="); |
|---|
| 1873 | + if (eqIndex > 0) { |
|---|
| 1874 | + name = c.substring(0, eqIndex); |
|---|
| 1875 | + value = c.substring(eqIndex + 1); |
|---|
| 1876 | + postParams[name] = value; |
|---|
| 1877 | } |
|---|
| 1878 | } |
|---|
| 1879 | |
|---|
| 1880 | - if (send_to_flash) { |
|---|
| 1881 | - this.setPostParams(post_params); |
|---|
| 1882 | + if (sendToFlash) { |
|---|
| 1883 | + this.setPostParams(postParams); |
|---|
| 1884 | } |
|---|
| 1885 | }; |
|---|
| 1886 | |
|---|
| 1887 | Index: wp-includes/js/swfupload/swfupload.swf |
|---|
| 1888 | =================================================================== |
|---|
| 1889 | Cannot display: file marked as a binary type. |
|---|
| 1890 | svn:mime-type = application/octet-stream |
|---|
| 1891 | |
|---|
| 1892 | Property changes on: wp-includes/js/swfupload/swfupload.swf |
|---|
| 1893 | ___________________________________________________________________ |
|---|
| 1894 | Added: svn:mime-type |
|---|
| 1895 | + application/octet-stream |
|---|
| 1896 | |
|---|
| 1897 | Index: wp-includes/js/swfupload/handlers.js |
|---|
| 1898 | =================================================================== |
|---|
| 1899 | --- wp-includes/js/swfupload/handlers.js (revision 9385) |
|---|
| 1900 | +++ wp-includes/js/swfupload/handlers.js (working copy) |
|---|
| 1901 | @@ -205,6 +205,14 @@ |
|---|
| 1902 | } |
|---|
| 1903 | } |
|---|
| 1904 | |
|---|
| 1905 | +function swfuploadPreLoad() { |
|---|
| 1906 | + return true; |
|---|
| 1907 | +} |
|---|
| 1908 | + |
|---|
| 1909 | +function swfuploadLoadFailed() { |
|---|
| 1910 | + return true; |
|---|
| 1911 | +} |
|---|
| 1912 | + |
|---|
| 1913 | function uploadError(fileObj, error_code, message) { |
|---|
| 1914 | // first the file specific error |
|---|
| 1915 | if ( error_code == SWFUpload.UPLOAD_ERROR.MISSING_UPLOAD_URL ) { |
|---|
| 1916 | Index: wp-includes/images/upload.png |
|---|
| 1917 | =================================================================== |
|---|
| 1918 | Cannot display: file marked as a binary type. |
|---|
| 1919 | svn:mime-type = application/octet-stream |
|---|
| 1920 | |
|---|
| 1921 | Property changes on: wp-includes/images/upload.png |
|---|
| 1922 | ___________________________________________________________________ |
|---|
| 1923 | Added: svn:mime-type |
|---|
| 1924 | + application/octet-stream |
|---|
| 1925 | |
|---|
| 1926 | Index: wp-includes/script-loader.php |
|---|
| 1927 | =================================================================== |
|---|
| 1928 | --- wp-includes/script-loader.php (revision 9385) |
|---|
| 1929 | +++ wp-includes/script-loader.php (working copy) |
|---|
| 1930 | @@ -104,6 +104,7 @@ |
|---|
| 1931 | $scripts->add( 'thickbox', '/wp-includes/js/thickbox/thickbox.js', array('jquery'), '3.1-20080430'); |
|---|
| 1932 | $scripts->add( 'swfupload', '/wp-includes/js/swfupload/swfupload.js', false, '2.0.2-20080430'); |
|---|
| 1933 | $scripts->add( 'swfupload-degrade', '/wp-includes/js/swfupload/plugins/swfupload.graceful_degradation.js', array('swfupload'), '2.0.2'); |
|---|
| 1934 | + $scripts->add( 'swfupload-swfobject', '/wp-includes/js/swfupload/plugins/swfupload.swfobject.js', array('swfupload'), '2.0.2'); |
|---|
| 1935 | $scripts->localize( 'swfupload-degrade', 'uploadDegradeOptions', array( |
|---|
| 1936 | 'is_lighttpd_before_150' => is_lighttpd_before_150(), |
|---|
| 1937 | ) ); |
|---|
| 1938 | Index: wp-admin/includes/media.php |
|---|
| 1939 | =================================================================== |
|---|
| 1940 | --- wp-admin/includes/media.php (revision 9385) |
|---|
| 1941 | +++ wp-admin/includes/media.php (working copy) |
|---|
| 1942 | @@ -1220,8 +1220,14 @@ |
|---|
| 1943 | <!-- |
|---|
| 1944 | jQuery(function($){ |
|---|
| 1945 | swfu = new SWFUpload({ |
|---|
| 1946 | + button_text: '<span class="button"><?php _e('Upload'); ?></span>', |
|---|
| 1947 | + button_text_style: '.button { text-align: center; font-weight: bold; font-family:"Lucida Grande","Lucida Sans Unicode",Tahoma,Verdana,sans-serif; }', |
|---|
| 1948 | + button_height: "24", |
|---|
| 1949 | + button_width: "132", |
|---|
| 1950 | + button_image_url: '<?php echo includes_url('images/upload.png'); ?>', |
|---|
| 1951 | + button_placeholder_id: "async-upload-wrap", |
|---|
| 1952 | upload_url : "<?php echo attribute_escape( $flash_action_url ); ?>", |
|---|
| 1953 | - flash_url : "<?php echo includes_url('js/swfupload/swfupload_f9.swf'); ?>", |
|---|
| 1954 | + flash_url : "<?php echo includes_url('js/swfupload/swfupload.swf'); ?>", |
|---|
| 1955 | file_post_name: "async-upload", |
|---|
| 1956 | file_types: "<?php echo apply_filters('upload_file_glob', '*.*'); ?>", |
|---|
| 1957 | post_params : { |
|---|
| 1958 | @@ -1244,6 +1250,8 @@ |
|---|
| 1959 | upload_complete_handler : uploadComplete, |
|---|
| 1960 | file_queue_error_handler : fileQueueError, |
|---|
| 1961 | file_dialog_complete_handler : fileDialogComplete, |
|---|
| 1962 | + swfupload_pre_load_handler: swfuploadPreLoad, |
|---|
| 1963 | + swfupload_load_failed_handler: swfuploadLoadFailed, |
|---|
| 1964 | |
|---|
| 1965 | debug: false |
|---|
| 1966 | }); |
|---|
| 1967 | @@ -1263,7 +1271,7 @@ |
|---|
| 1968 | |
|---|
| 1969 | <div id="html-upload-ui"> |
|---|
| 1970 | <?php do_action('pre-html-upload-ui'); ?> |
|---|
| 1971 | - <p> |
|---|
| 1972 | + <p id="async-upload-wrap"> |
|---|
| 1973 | <input type="file" name="async-upload" id="async-upload" /> <input type="submit" class="button" name="html-upload" value="<?php echo attribute_escape(__('Upload')); ?>" /> <a href="#" onclick="return top.tb_remove();"><?php _e('Cancel'); ?></a> |
|---|
| 1974 | </p> |
|---|
| 1975 | |
|---|
| 1976 | Index: wp-admin/media-upload.php |
|---|
| 1977 | =================================================================== |
|---|
| 1978 | --- wp-admin/media-upload.php (revision 9385) |
|---|
| 1979 | +++ wp-admin/media-upload.php (working copy) |
|---|
| 1980 | @@ -16,7 +16,7 @@ |
|---|
| 1981 | wp_die(__('You do not have permission to upload files.')); |
|---|
| 1982 | |
|---|
| 1983 | wp_enqueue_script('swfupload'); |
|---|
| 1984 | -wp_enqueue_script('swfupload-degrade'); |
|---|
| 1985 | +wp_enqueue_script('swfupload-swfobject'); |
|---|
| 1986 | wp_enqueue_script('swfupload-queue'); |
|---|
| 1987 | wp_enqueue_script('swfupload-handlers'); |
|---|
| 1988 | |
|---|