WordPress.org

Make WordPress Core

Ticket #16668: swfupload.diff

File swfupload.diff, 12.9 KB (added by niallkennedy, 9 years ago)

SWFUpload 2.2.1

  • wp-includes/js/swfupload/swfupload.js

     
    2323        };
    2424}
    2525
    26 SWFUpload.prototype.initSWFUpload = function (settings) {
     26SWFUpload.prototype.initSWFUpload = function (userSettings) {
    2727        try {
    2828                this.customSettings = {};       // A container where developers can place their own settings associated with this instance.
    29                 this.settings = settings;
     29                this.settings = {};
    3030                this.eventQueue = [];
    3131                this.movieName = "SWFUpload_" + SWFUpload.movieCount++;
    3232                this.movieElement = null;
     
    3636                SWFUpload.instances[this.movieName] = this;
    3737
    3838                // Load the settings.  Load the Flash movie.
    39                 this.initSettings();
     39                this.initSettings(userSettings);
    4040                this.loadFlash();
    4141                this.displayDebugInfo();
    4242        } catch (ex) {
     
    5050/* *************** */
    5151SWFUpload.instances = {};
    5252SWFUpload.movieCount = 0;
    53 SWFUpload.version = "2.2.0 2009-03-25";
     53SWFUpload.version = "2.2.1 2009-03-30";
    5454SWFUpload.QUEUE_ERROR = {
    5555        QUEUE_LIMIT_EXCEEDED                    : -100,
    5656        FILE_EXCEEDS_SIZE_LIMIT                 : -110,
     
    7979SWFUpload.BUTTON_ACTION = {
    8080        SELECT_FILE  : -100,
    8181        SELECT_FILES : -110,
    82         START_UPLOAD : -120
     82        START_UPLOAD : -120,
     83        JAVASCRIPT   : -130
    8384};
    8485SWFUpload.CURSOR = {
    8586        ARROW : -1,
     
    9394
    9495// Private: takes a URL, determines if it is relative and converts to an absolute URL
    9596// 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(/^\//)) {
     97SWFUpload.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) {
    98113                return url;
    99114        }
    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        
    112115};
    113116
    114117
     
    118121
    119122// Private: initSettings ensures that all the
    120123// settings are set, getting a default value if one was not assigned.
    121 SWFUpload.prototype.initSettings = function () {
     124SWFUpload.prototype.initSettings = function (userSettings) {
    122125        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                }
    124142        };
    125143       
    126144        // Upload backend settings
     
    177195        this.ensureDefault("upload_success_handler", null);
    178196        this.ensureDefault("upload_complete_handler", null);
    179197       
     198        this.ensureDefault("button_action_handler", null);
     199       
    180200        this.ensureDefault("debug_handler", this.debugMessage);
    181201
    182202        this.ensureDefault("custom_settings", {});
     
    190210        }
    191211       
    192212        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 it
    194213                this.settings.upload_url = SWFUpload.completeURL(this.settings.upload_url);
    195214                this.settings.button_image_url = SWFUpload.completeURL(this.settings.button_image_url);
    196215        }
     
    214233                throw "Could not find the placeholder element: " + this.settings.button_placeholder_id;
    215234        }
    216235
     236        var wrapperType = (targetElement.currentStyle && targetElement.currentStyle["display"] || window.getComputedStyle && document.defaultView.getComputedStyle(targetElement, null).getPropertyValue("display")) !== "block" ? "span" : "div";
     237       
    217238        // Append the container and load the flash
    218         tempParent = document.createElement("div");
     239        tempParent = document.createElement(wrapperType);
    219240        tempParent.innerHTML = this.getFlashHTML();     // Using innerHTML is non-standard but the only sensible way to dynamically add Flash in IE (and maybe other browsers)
    220241        targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement);
    221242
     
    314335                // Make sure Flash is done before we try to remove it
    315336                this.cancelUpload(null, false);
    316337               
     338                // Stop the external interface check from running
     339                this.callFlash("StopExternalInterfaceCheck");
     340               
     341                var movieElement = this.cleanUp();
    317342
    318343                // 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) {
    332345                        // Remove the Movie Element from the page
    333346                        try {
    334347                                movieElement.parentNode.removeChild(movieElement);
    335348                        } catch (ex) {}
    336349                }
    337                
     350
    338351                // Remove IE form fix reference
    339352                window[this.movieName] = null;
    340353
     
    506519        this.callFlash("StopUpload");
    507520};
    508521
     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).
     526SWFUpload.prototype.requeueUpload = function (indexOrFileID) {
     527        return this.callFlash("RequeueUpload", [indexOrFileID]);
     528};
     529
     530
    509531/* ************************
    510532 * Settings methods
    511533 *   These methods change the SWFUpload settings.
     
    792814                return;
    793815        }
    794816
    795         this.cleanUp(movieElement);
     817        this.cleanUp();
    796818       
    797819        this.queueEvent("swfupload_loaded_handler");
    798820};
    799821
    800822// Private: removes Flash added fuctions to the DOM node to prevent memory leaks in IE.
    801823// This function is called by Flash each time the ExternalInterface functions are created.
    802 SWFUpload.prototype.cleanUp = function (movieElement) {
     824SWFUpload.prototype.cleanUp = function () {
     825        var movieElement = this.getMovieElement();
     826       
    803827        // Pro-actively unhook all the Flash functions
    804828        try {
    805                 if (this.movieElement && typeof(movieElement.CallFunction) === "unknown") { // We only want to do this in IE
     829                if (movieElement && typeof(movieElement.CallFunction) === "unknown") { // We only want to do this in IE
    806830                        this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)");
    807831                        for (var key in movieElement) {
    808832                                try {
     
    817841       
    818842        }
    819843
    820         // Fix Flashes own cleanup code so if the SWFMovie was removed from the page
     844        // Fix Flashes own cleanup code so if the SWF Movie was removed from the page
    821845        // it doesn't display errors.
    822846        window["__flash__removeCallback"] = function (instance, name) {
    823847                try {
     
    828852               
    829853                }
    830854        };
     855       
     856        return movieElement;
     857};
    831858
     859/* When the button_action is set to JavaScript this event gets fired and executes the button_action_handler */
     860SWFUpload.prototype.buttonAction = function () {
     861        this.queueEvent("button_action_handler");
    832862};
    833863
    834 
    835864/* This is a chance to do something before the browse window opens */
    836865SWFUpload.prototype.fileDialogStart = function () {
    837866        this.queueEvent("file_dialog_start_handler");
  • wp-includes/js/swfupload/plugins/swfupload.queue.js

     
    1616        SWFUpload.queue = {};
    1717       
    1818        SWFUpload.prototype.initSettings = (function (oldInitSettings) {
    19                 return function () {
     19                return function (userSettings) {
    2020                        if (typeof(oldInitSettings) === "function") {
    21                                 oldInitSettings.call(this);
     21                                oldInitSettings.call(this, userSettings);
    2222                        }
    2323                       
    2424                        this.queueSettings = {};
     
    3131                        this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
    3232                        this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler;
    3333                       
    34                         this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
     34                        this.settings.queue_complete_handler = userSettings.queue_complete_handler || null;
    3535                };
    3636        })(SWFUpload.prototype.initSettings);
    3737
  • wp-includes/js/swfupload/plugins/swfupload.swfobject.js

     
    5151        });
    5252       
    5353        SWFUpload.prototype.initSettings = (function (oldInitSettings) {
    54                 return function () {
     54                return function (userSettings) {
    5555                        if (typeof(oldInitSettings) === "function") {
    56                                 oldInitSettings.call(this);
     56                                oldInitSettings.call(this, userSettings);
    5757                        }
    5858
    5959                        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];
    6161                        };
    6262
    6363                        this.ensureDefault("minimum_flash_version", "9.0.28");
  • wp-includes/js/swfupload/plugins/swfupload.cookies.js

     
    99var SWFUpload;
    1010if (typeof(SWFUpload) === "function") {
    1111        SWFUpload.prototype.initSettings = function (oldInitSettings) {
    12                 return function () {
     12                return function (userSettings) {
    1313                        if (typeof(oldInitSettings) === "function") {
    14                                 oldInitSettings.call(this);
     14                                oldInitSettings.call(this, userSettings);
    1515                        }
    1616                       
    1717                        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

     
    33       
    44        Features:
    55                *Adds several properties to the 'file' object indicated upload speed, time left, upload time, etc.
    6                         - currentSpeed -- String indicating the upload speed, bytes per second
    7                         - averageSpeed -- Overall average upload speed, bytes per second
    8                         - movingAverageSpeed -- Speed over averaged over the last several measurements, bytes per second
     6                        - 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
    99                        - timeRemaining -- Estimated remaining upload time in seconds
    1010                        - timeElapsed -- Number of seconds passed for this upload
    1111                        - percentUploaded -- Percentage of the file uploaded (0 to 100)
     
    2929        SWFUpload.speed = {};
    3030       
    3131        SWFUpload.prototype.initSettings = (function (oldInitSettings) {
    32                 return function () {
     32                return function (userSettings) {
    3333                        if (typeof(oldInitSettings) === "function") {
    34                                 oldInitSettings.call(this);
     34                                oldInitSettings.call(this, userSettings);
    3535                        }
    3636                       
    3737                        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];
    3939                        };
    4040
    4141                        // List used to keep the speed stats for the files we are tracking
     
    339339                return mSum / mCount;
    340340        };
    341341       
    342 }
    343  No newline at end of file
     342}