Ticket #16668: swfupload.diff
File swfupload.diff, 12.9 KB (added by , 14 years ago) |
---|
-
wp-includes/js/swfupload/swfupload.js
23 23 }; 24 24 } 25 25 26 SWFUpload.prototype.initSWFUpload = function ( settings) {26 SWFUpload.prototype.initSWFUpload = function (userSettings) { 27 27 try { 28 28 this.customSettings = {}; // A container where developers can place their own settings associated with this instance. 29 this.settings = settings;29 this.settings = {}; 30 30 this.eventQueue = []; 31 31 this.movieName = "SWFUpload_" + SWFUpload.movieCount++; 32 32 this.movieElement = null; … … 36 36 SWFUpload.instances[this.movieName] = this; 37 37 38 38 // Load the settings. Load the Flash movie. 39 this.initSettings( );39 this.initSettings(userSettings); 40 40 this.loadFlash(); 41 41 this.displayDebugInfo(); 42 42 } catch (ex) { … … 50 50 /* *************** */ 51 51 SWFUpload.instances = {}; 52 52 SWFUpload.movieCount = 0; 53 SWFUpload.version = "2.2. 0 2009-03-25";53 SWFUpload.version = "2.2.1 2009-03-30"; 54 54 SWFUpload.QUEUE_ERROR = { 55 55 QUEUE_LIMIT_EXCEEDED : -100, 56 56 FILE_EXCEEDS_SIZE_LIMIT : -110, … … 79 79 SWFUpload.BUTTON_ACTION = { 80 80 SELECT_FILE : -100, 81 81 SELECT_FILES : -110, 82 START_UPLOAD : -120 82 START_UPLOAD : -120, 83 JAVASCRIPT : -130 83 84 }; 84 85 SWFUpload.CURSOR = { 85 86 ARROW : -1, … … 93 94 94 95 // Private: takes a URL, determines if it is relative and converts to an absolute URL 95 96 // using the current site. Only processes the URL if it can, otherwise returns the URL untouched 96 SWFUpload.completeURL = function(url) { 97 if (typeof(url) !== "string" || url.match(/^https?:\/\//i) || url.match(/^\//)) { 97 SWFUpload.completeURL = function (url) { 98 try { 99 var path = ""; 100 if (typeof(url) !== "string" || url.match(/^https?:\/\//i) || url.match(/^\//) || url === "") { 101 return url; 102 } 103 104 var indexSlash = window.location.pathname.lastIndexOf("/"); 105 if (indexSlash <= 0) { 106 path = "/"; 107 } else { 108 path = window.location.pathname.substr(0, indexSlash) + "/"; 109 } 110 111 return path + url; 112 } catch (ex) { 98 113 return url; 99 114 } 100 101 var currentURL = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : "");102 103 var indexSlash = window.location.pathname.lastIndexOf("/");104 if (indexSlash <= 0) {105 path = "/";106 } else {107 path = window.location.pathname.substr(0, indexSlash) + "/";108 }109 110 return /*currentURL +*/ path + url;111 112 115 }; 113 116 114 117 … … 118 121 119 122 // Private: initSettings ensures that all the 120 123 // settings are set, getting a default value if one was not assigned. 121 SWFUpload.prototype.initSettings = function ( ) {124 SWFUpload.prototype.initSettings = function (userSettings) { 122 125 this.ensureDefault = function (settingName, defaultValue) { 123 this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName]; 126 var setting = userSettings[settingName]; 127 if (setting != undefined) { 128 if (typeof(setting) === "object" && !(setting instanceof Array)) { 129 var clone = {}; 130 for (var key in setting) { 131 if (setting.hasOwnProperty(key)) { 132 clone[key] = setting[key]; 133 } 134 } 135 this.settings[settingName] = clone; 136 } else { 137 this.settings[settingName] = setting; 138 } 139 } else { 140 this.settings[settingName] = defaultValue; 141 } 124 142 }; 125 143 126 144 // Upload backend settings … … 177 195 this.ensureDefault("upload_success_handler", null); 178 196 this.ensureDefault("upload_complete_handler", null); 179 197 198 this.ensureDefault("button_action_handler", null); 199 180 200 this.ensureDefault("debug_handler", this.debugMessage); 181 201 182 202 this.ensureDefault("custom_settings", {}); … … 190 210 } 191 211 192 212 if (!this.settings.preserve_relative_urls) { 193 //this.settings.flash_url = SWFUpload.completeURL(this.settings.flash_url); // Don't need to do this one since flash doesn't look at it194 213 this.settings.upload_url = SWFUpload.completeURL(this.settings.upload_url); 195 214 this.settings.button_image_url = SWFUpload.completeURL(this.settings.button_image_url); 196 215 } … … 214 233 throw "Could not find the placeholder element: " + this.settings.button_placeholder_id; 215 234 } 216 235 236 var wrapperType = (targetElement.currentStyle && targetElement.currentStyle["display"] || window.getComputedStyle && document.defaultView.getComputedStyle(targetElement, null).getPropertyValue("display")) !== "block" ? "span" : "div"; 237 217 238 // Append the container and load the flash 218 tempParent = document.createElement( "div");239 tempParent = document.createElement(wrapperType); 219 240 tempParent.innerHTML = this.getFlashHTML(); // Using innerHTML is non-standard but the only sensible way to dynamically add Flash in IE (and maybe other browsers) 220 241 targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement); 221 242 … … 314 335 // Make sure Flash is done before we try to remove it 315 336 this.cancelUpload(null, false); 316 337 338 // Stop the external interface check from running 339 this.callFlash("StopExternalInterfaceCheck"); 340 341 var movieElement = this.cleanUp(); 317 342 318 343 // Remove the SWFUpload DOM nodes 319 var movieElement = null; 320 movieElement = this.getMovieElement(); 321 322 if (movieElement && typeof(movieElement.CallFunction) === "unknown") { // We only want to do this in IE 323 // Loop through all the movie's properties and remove all function references (DOM/JS IE 6/7 memory leak workaround) 324 for (var i in movieElement) { 325 try { 326 if (typeof(movieElement[i]) === "function") { 327 movieElement[i] = null; 328 } 329 } catch (ex1) {} 330 } 331 344 if (movieElement) { 332 345 // Remove the Movie Element from the page 333 346 try { 334 347 movieElement.parentNode.removeChild(movieElement); 335 348 } catch (ex) {} 336 349 } 337 350 338 351 // Remove IE form fix reference 339 352 window[this.movieName] = null; 340 353 … … 506 519 this.callFlash("StopUpload"); 507 520 }; 508 521 522 523 // Public: requeueUpload requeues any file. If the file is requeued or already queued true is returned. 524 // If the file is not found or is currently uploading false is returned. Requeuing a file bypasses the 525 // file size, queue size, upload limit and other queue checks. Certain files can't be requeued (e.g, invalid or zero bytes files). 526 SWFUpload.prototype.requeueUpload = function (indexOrFileID) { 527 return this.callFlash("RequeueUpload", [indexOrFileID]); 528 }; 529 530 509 531 /* ************************ 510 532 * Settings methods 511 533 * These methods change the SWFUpload settings. … … 792 814 return; 793 815 } 794 816 795 this.cleanUp( movieElement);817 this.cleanUp(); 796 818 797 819 this.queueEvent("swfupload_loaded_handler"); 798 820 }; 799 821 800 822 // Private: removes Flash added fuctions to the DOM node to prevent memory leaks in IE. 801 823 // This function is called by Flash each time the ExternalInterface functions are created. 802 SWFUpload.prototype.cleanUp = function (movieElement) { 824 SWFUpload.prototype.cleanUp = function () { 825 var movieElement = this.getMovieElement(); 826 803 827 // Pro-actively unhook all the Flash functions 804 828 try { 805 if ( this.movieElement && typeof(movieElement.CallFunction) === "unknown") { // We only want to do this in IE829 if (movieElement && typeof(movieElement.CallFunction) === "unknown") { // We only want to do this in IE 806 830 this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)"); 807 831 for (var key in movieElement) { 808 832 try { … … 817 841 818 842 } 819 843 820 // Fix Flashes own cleanup code so if the SWF Movie was removed from the page844 // Fix Flashes own cleanup code so if the SWF Movie was removed from the page 821 845 // it doesn't display errors. 822 846 window["__flash__removeCallback"] = function (instance, name) { 823 847 try { … … 828 852 829 853 } 830 854 }; 855 856 return movieElement; 857 }; 831 858 859 /* When the button_action is set to JavaScript this event gets fired and executes the button_action_handler */ 860 SWFUpload.prototype.buttonAction = function () { 861 this.queueEvent("button_action_handler"); 832 862 }; 833 863 834 835 864 /* This is a chance to do something before the browse window opens */ 836 865 SWFUpload.prototype.fileDialogStart = function () { 837 866 this.queueEvent("file_dialog_start_handler"); -
wp-includes/js/swfupload/plugins/swfupload.queue.js
16 16 SWFUpload.queue = {}; 17 17 18 18 SWFUpload.prototype.initSettings = (function (oldInitSettings) { 19 return function ( ) {19 return function (userSettings) { 20 20 if (typeof(oldInitSettings) === "function") { 21 oldInitSettings.call(this );21 oldInitSettings.call(this, userSettings); 22 22 } 23 23 24 24 this.queueSettings = {}; … … 31 31 this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler; 32 32 this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler; 33 33 34 this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;34 this.settings.queue_complete_handler = userSettings.queue_complete_handler || null; 35 35 }; 36 36 })(SWFUpload.prototype.initSettings); 37 37 -
wp-includes/js/swfupload/plugins/swfupload.swfobject.js
51 51 }); 52 52 53 53 SWFUpload.prototype.initSettings = (function (oldInitSettings) { 54 return function ( ) {54 return function (userSettings) { 55 55 if (typeof(oldInitSettings) === "function") { 56 oldInitSettings.call(this );56 oldInitSettings.call(this, userSettings); 57 57 } 58 58 59 59 this.ensureDefault = function (settingName, defaultValue) { 60 this.settings[settingName] = ( this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];60 this.settings[settingName] = (userSettings[settingName] == undefined) ? defaultValue : userSettings[settingName]; 61 61 }; 62 62 63 63 this.ensureDefault("minimum_flash_version", "9.0.28"); -
wp-includes/js/swfupload/plugins/swfupload.cookies.js
9 9 var SWFUpload; 10 10 if (typeof(SWFUpload) === "function") { 11 11 SWFUpload.prototype.initSettings = function (oldInitSettings) { 12 return function ( ) {12 return function (userSettings) { 13 13 if (typeof(oldInitSettings) === "function") { 14 oldInitSettings.call(this );14 oldInitSettings.call(this, userSettings); 15 15 } 16 16 17 17 this.refreshCookies(false); // The false parameter must be sent since SWFUpload has not initialzed at this point -
wp-includes/js/swfupload/plugins/swfupload.speed.js
3 3 4 4 Features: 5 5 *Adds several properties to the 'file' object indicated upload speed, time left, upload time, etc. 6 - currentSpeed -- String indicating the upload speed, b ytes per second7 - averageSpeed -- Overall average upload speed, b ytes per second8 - movingAverageSpeed -- Speed over averaged over the last several measurements, b ytes per second6 - currentSpeed -- String indicating the upload speed, bits per second 7 - averageSpeed -- Overall average upload speed, bits per second 8 - movingAverageSpeed -- Speed over averaged over the last several measurements, bits per second 9 9 - timeRemaining -- Estimated remaining upload time in seconds 10 10 - timeElapsed -- Number of seconds passed for this upload 11 11 - percentUploaded -- Percentage of the file uploaded (0 to 100) … … 29 29 SWFUpload.speed = {}; 30 30 31 31 SWFUpload.prototype.initSettings = (function (oldInitSettings) { 32 return function ( ) {32 return function (userSettings) { 33 33 if (typeof(oldInitSettings) === "function") { 34 oldInitSettings.call(this );34 oldInitSettings.call(this, userSettings); 35 35 } 36 36 37 37 this.ensureDefault = function (settingName, defaultValue) { 38 this.settings[settingName] = ( this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];38 this.settings[settingName] = (userSettings[settingName] == undefined) ? defaultValue : userSettings[settingName]; 39 39 }; 40 40 41 41 // List used to keep the speed stats for the files we are tracking … … 339 339 return mSum / mCount; 340 340 }; 341 341 342 } 343 No newline at end of file 342 }