WordPress.org

Make WordPress Core

Changeset 8057


Ignore:
Timestamp:
06/06/2008 07:34:30 AM (12 years ago)
Author:
ryan
Message:

Revert [8056], didn't quite work

Location:
trunk/wp-includes/js/swfupload
Files:
1 deleted
5 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/js/swfupload/plugins/swfupload.cookies.js

    r8056 r8057  
    99var SWFUpload;
    1010if (typeof(SWFUpload) === "function") {
    11     SWFUpload.prototype.initSettings = function (oldInitSettings) {
    12         return function () {
    13             if (typeof(oldInitSettings) === "function") {
    14                 oldInitSettings.call(this);
     11    SWFUpload.prototype.initSettings = function (old_initSettings) {
     12        return function (init_settings) {
     13            if (typeof(old_initSettings) === "function") {
     14                old_initSettings.call(this, init_settings);
    1515            }
    1616           
     
    1919    }(SWFUpload.prototype.initSettings);
    2020   
    21     // refreshes the post_params and updates SWFUpload.  The sendToFlash parameters is optional and defaults to True
    22     SWFUpload.prototype.refreshCookies = function (sendToFlash) {
    23         if (sendToFlash === undefined) {
    24             sendToFlash = true;
    25         }
    26         sendToFlash = !!sendToFlash;
     21    // refreshes the post_params and updates SWFUpload.  The send_to_flash parameters is optional and defaults to True
     22    SWFUpload.prototype.refreshCookies = function (send_to_flash) {
     23        if (send_to_flash !== false) send_to_flash = true;
    2724       
    2825        // Get the post_params object
    29         var postParams = this.settings.post_params;
     26        var post_params = this.getSetting("post_params");
    3027       
    3128        // Get the cookies
    32         var i, cookieArray = document.cookie.split(';'), caLength = cookieArray.length, c, eqIndex, name, value;
    33         for (i = 0; i < caLength; i++) {
    34             c = cookieArray[i];
     29        var i, cookie_array = document.cookie.split(';'), ca_length = cookie_array.length, c, eq_index, name, value;
     30        for(i = 0; i < ca_length; i++) {
     31            c = cookie_array[i];
    3532           
    3633            // Left Trim spaces
    37             while (c.charAt(0) === " ") {
     34            while (c.charAt(0) == " ") {
    3835                c = c.substring(1, c.length);
    3936            }
    40             eqIndex = c.indexOf("=");
    41             if (eqIndex > 0) {
    42                 name = c.substring(0, eqIndex);
    43                 value = c.substring(eqIndex + 1);
    44                 postParams[name] = value;
     37            eq_index = c.indexOf("=");
     38            if (eq_index > 0) {
     39                name = c.substring(0, eq_index);
     40                value = c.substring(eq_index+1);
     41                post_params[name] = value;
    4542            }
    4643        }
    4744       
    48         if (sendToFlash) {
    49             this.setPostParams(postParams);
     45        if (send_to_flash) {
     46            this.setPostParams(post_params);
    5047        }
    5148    };
  • trunk/wp-includes/js/swfupload/plugins/swfupload.graceful_degradation.js

    r8056 r8057  
    2020if (typeof(SWFUpload) === "function") {
    2121    SWFUpload.gracefulDegradation = {};
    22     SWFUpload.prototype.initSettings = (function (oldInitSettings) {
    23         return function () {
    24             if (typeof(oldInitSettings) === "function") {
    25                 oldInitSettings.call(this);
     22    SWFUpload.prototype.initSettings = function (old_initSettings) {
     23        return function (init_settings) {
     24            if (typeof(old_initSettings) === "function") {
     25                old_initSettings.call(this, init_settings);
    2626            }
    2727           
    28             this.ensureDefault = function (settingName, defaultValue) {
    29                 this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
    30             };
     28            this.addSetting("swfupload_element_id",             init_settings.swfupload_element_id,             "swfupload_container");
     29            this.addSetting("degraded_element_id",              init_settings.degraded_element_id,              "degraded_container");
     30            this.addSetting("user_swfUploadLoaded_handler",     init_settings.swfupload_loaded_handler,         SWFUpload.swfUploadLoaded);
     31
     32            this.swfUploadLoaded_handler = SWFUpload.gracefulDegradation.swfUploadLoaded;
     33        };
     34    }(SWFUpload.prototype.initSettings);
     35
     36    SWFUpload.gracefulDegradation.swfUploadLoaded = function () {
     37        var swfupload_container_id, swfupload_container, degraded_container_id, degraded_container, user_swfUploadLoaded_handler;
     38        try {
     39            if (uploadDegradeOptions.is_lighttpd_before_150) throw "Lighttpd versions earlier than 1.5.0 aren't supported!";
     40            swfupload_element_id = this.getSetting("swfupload_element_id");
     41            degraded_element_id = this.getSetting("degraded_element_id");
    3142           
    32             this.ensureDefault("swfupload_element_id", "swfupload_container");
    33             this.ensureDefault("degraded_element_id", "degraded_container");
    34             this.settings.user_swfupload_loaded_handler = this.settings.swfupload_loaded_handler;
     43            // Show the UI container
     44            swfupload_container = document.getElementById(swfupload_element_id);
     45            if (swfupload_container !== null) {
     46                swfupload_container.style.display = "block";
    3547
    36             this.settings.swfupload_loaded_handler = SWFUpload.gracefulDegradation.swfUploadLoadedHandler;
    37            
    38             delete this.ensureDefault;
    39         };
    40     })(SWFUpload.prototype.initSettings);
    41 
    42     SWFUpload.gracefulDegradation.swfUploadLoadedHandler = function () {
    43         var swfuploadContainerID, swfuploadContainer, degradedContainerID, degradedContainer;
    44 
    45         swfuploadContainerID = this.settings.swfupload_element_id;
    46         degradedContainerID = this.settings.degraded_element_id;
    47        
    48         // Show the UI container
    49         swfuploadContainer = document.getElementById(swfuploadContainerID);
    50         if (swfuploadContainer != undefined) {
    51             swfuploadContainer.style.display = "block";
    52 
    53             // Now take care of hiding the degraded UI
    54             degradedContainer = document.getElementById(degradedContainerID);
    55             if (degradedContainer != undefined) {
    56                 degradedContainer.style.display = "none";
     48                // Now take care of hiding the degraded UI
     49                degraded_container = document.getElementById(degraded_element_id);
     50                if (degraded_container !== null) {
     51                    degraded_container.style.display = "none";
     52                }
    5753            }
     54        } catch (ex) {
     55            this.debug(ex);
    5856        }
    5957       
    60         if (typeof(this.settings.user_swfupload_loaded_handler) === "function") {
    61             this.settings.user_swfupload_loaded_handler.apply(this);
     58        user_swfUploadLoaded_handler = this.getSetting("user_swfUploadLoaded_handler");
     59        if (typeof(user_swfUploadLoaded_handler) === "function") {
     60            user_swfUploadLoaded_handler.apply(this);
    6261        }
    6362    };
  • trunk/wp-includes/js/swfupload/plugins/swfupload.queue.js

    r8056 r8057  
    33   
    44    Features:
    5         *Adds a cancelQueue() method for cancelling the entire queue.
    6         *All queued files are uploaded when startUpload() is called.
    7         *If false is returned from uploadComplete then the queue upload is stopped.
    8          If false is not returned (strict comparison) then the queue upload is continued.
    9         *Adds a QueueComplete event that is fired when all the queued files have finished uploading.
    10          Set the event handler with the queue_complete_handler setting.
     5        cancelQueue method for cancelling the entire queue.
     6        All queued files are uploaded when startUpload() is called.
     7        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.
    118       
    129    */
     
    1613    SWFUpload.queue = {};
    1714   
    18     SWFUpload.prototype.initSettings = (function (oldInitSettings) {
    19         return function () {
    20             if (typeof(oldInitSettings) === "function") {
    21                 oldInitSettings.call(this);
     15    SWFUpload.prototype.initSettings = function (old_initSettings) {
     16        return function (init_settings) {
     17            if (typeof(old_initSettings) === "function") {
     18                old_initSettings.call(this, init_settings);
    2219            }
    2320           
    2421            this.customSettings.queue_cancelled_flag = false;
    25             this.customSettings.queue_upload_count = 0;
    2622           
    27             this.settings.user_upload_complete_handler = this.settings.upload_complete_handler;
    28             this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
    29            
    30             this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
     23            this.addSetting("user_upload_complete_handler", init_settings.upload_complete_handler, SWFUpload.uploadComplete);
     24            this.uploadComplete_handler = SWFUpload.queue.uploadComplete;
    3125        };
    32     })(SWFUpload.prototype.initSettings);
    33 
    34     SWFUpload.prototype.startUpload = function (fileID) {
    35         this.customSettings.queue_cancelled_flag = false;
    36         this.callFlash("StartUpload", false, [fileID]);
    37     };
     26    }(SWFUpload.prototype.initSettings);
    3827
    3928    SWFUpload.prototype.cancelQueue = function () {
    40         this.customSettings.queue_cancelled_flag = true;
    41         this.stopUpload();
     29        var stats = this.getStats();
     30        this.customSettings.queue_cancelled_flag = false;
     31
     32        if (stats.in_progress > 0) {
     33            this.customSettings.queue_cancelled_flag = true;
     34        }
    4235       
    43         var stats = this.getStats();
    44         while (stats.files_queued > 0) {
     36        while(stats.files_queued > 0) {
    4537            this.cancelUpload();
    4638            stats = this.getStats();
     
    4840    };
    4941   
    50     SWFUpload.queue.uploadCompleteHandler = function (file) {
    51         var user_upload_complete_handler = this.settings.user_upload_complete_handler;
    52         var continueUpload;
    53        
    54         if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
    55             this.customSettings.queue_upload_count++;
    56         }
    57 
     42    SWFUpload.queue.uploadComplete = function (file) {
     43        var user_upload_complete_handler = this.getSetting("user_upload_complete_handler");
     44        var continue_upload = true;
    5845        if (typeof(user_upload_complete_handler) === "function") {
    59             continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
    60         } else {
    61             continueUpload = true;
     46            continue_upload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
    6247        }
    6348       
    64         if (continueUpload) {
     49        if (continue_upload) {
    6550            var stats = this.getStats();
    6651            if (stats.files_queued > 0 && this.customSettings.queue_cancelled_flag === false) {
    6752                this.startUpload();
    68             } else if (this.customSettings.queue_cancelled_flag === false) {
    69                 this.queueEvent("queue_complete_handler", [this.customSettings.queue_upload_count]);
    70                 this.customSettings.queue_upload_count = 0;
    7153            } else {
    7254                this.customSettings.queue_cancelled_flag = false;
    73                 this.customSettings.queue_upload_count = 0;
    7455            }
    7556        }
  • trunk/wp-includes/js/swfupload/swfupload.js

    r8056 r8057  
    11/**
    2  * SWFUpload v2.1.0 by Jacob Roberts, Feb 2008, http://www.swfupload.org, http://swfupload.googlecode.com, http://www.swfupload.org
     2 * SWFUpload v2.0 by Jacob Roberts, Nov 2007, http://www.swfupload.org, http://linebyline.blogspot.com
    33 * -------- -------- -------- -------- -------- -------- -------- --------
    4  * SWFUpload is (c) 2006 Lars Huring, Olov Nilzén and Mammon Media and is released under the MIT License:
     4 * SWFUpload is (c) 2006 Lars Huring and Mammon Media and is released under the MIT License:
    55 * http://www.opensource.org/licenses/mit-license.php
    66 *
    77 * See Changelog.txt for version history
    88 *
     9 * Development Notes:
     10 *  * This version of SWFUpload requires Flash Player 9.0.28 and should autodetect the correct flash version.
     11 *  * In Linux Flash Player 9 setting the post file variable name does not work. It is always set to "Filedata".
     12 *  * There is a lot of repeated code that could be refactored to single functions.  Feel free.
     13 *  * It's dangerous to do "circular calls" between Flash and JavaScript. I've taken steps to try to work around issues
     14 *     by having the event calls pipe through setTimeout.  However you should still avoid calling in to Flash from
     15 *     within the event handler methods.  Especially the "startUpload" event since it cannot use the setTimeout hack.
    916 */
    1017
     
    1421/* *********** */
    1522
    16 var SWFUpload = function (settings) {
    17     this.initSWFUpload(settings);
    18 };
    19 
    20 SWFUpload.prototype.initSWFUpload = function (settings) {
     23var SWFUpload = function (init_settings) {
     24    this.initSWFUpload(init_settings);
     25};
     26
     27SWFUpload.prototype.initSWFUpload = function (init_settings) {
     28    // Remove background flicker in IE (read this: http://misterpixel.blogspot.com/2006/09/forensic-analysis-of-ie6.html)
     29    // This doesn't have anything to do with SWFUpload but can help your UI behave better in IE.
     30    try {
     31        document.execCommand('BackgroundImageCache', false, true);
     32    } catch (ex1) {
     33    }
     34
     35
    2136    try {
    2237        this.customSettings = {};   // A container where developers can place their own settings associated with this instance.
    23         this.settings = settings;
     38        this.settings = {};
    2439        this.eventQueue = [];
    2540        this.movieName = "SWFUpload_" + SWFUpload.movieCount++;
     
    3045
    3146        // Load the settings.  Load the Flash movie.
    32         this.initSettings();
     47        this.initSettings(init_settings);
    3348        this.loadFlash();
     49
    3450        this.displayDebugInfo();
    35     } catch (ex) {
    36         delete SWFUpload.instances[this.movieName];
    37         throw ex;
    38     }
    39 };
     51
     52    } catch (ex2) {
     53        this.debug(ex2);
     54    }
     55}
    4056
    4157/* *************** */
    42 /* Static Members */
     58/* Static thingies */
    4359/* *************** */
    4460SWFUpload.instances = {};
    4561SWFUpload.movieCount = 0;
    46 SWFUpload.version = "2.1.0";
    4762SWFUpload.QUEUE_ERROR = {
    4863    QUEUE_LIMIT_EXCEEDED            : -100,
     
    7287
    7388
    74 /* ******************** */
    75 /* Instance Members  */
    76 /* ******************** */
    77 
    78 // Private: initSettings ensures that all the
    79 // settings are set, getting a default value if one was not assigned.
    80 SWFUpload.prototype.initSettings = function () {
    81     this.ensureDefault = function (settingName, defaultValue) {
    82         this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
    83     };
     89/* ***************** */
     90/* Instance Thingies */
     91/* ***************** */
     92// init is a private method that ensures that all the object settings are set, getting a default value if one was not assigned.
     93
     94SWFUpload.prototype.initSettings = function (init_settings) {
     95    // Upload backend settings
     96    this.addSetting("upload_url",               init_settings.upload_url,               "");
     97    this.addSetting("file_post_name",           init_settings.file_post_name,           "Filedata");
     98    this.addSetting("post_params",              init_settings.post_params,              {});
     99
     100    // File Settings
     101    this.addSetting("file_types",               init_settings.file_types,               "*.*");
     102    this.addSetting("file_types_description",   init_settings.file_types_description,   "All Files");
     103    this.addSetting("file_size_limit",          init_settings.file_size_limit,          "1024");
     104    this.addSetting("file_upload_limit",        init_settings.file_upload_limit,        "0");
     105    this.addSetting("file_queue_limit",         init_settings.file_queue_limit,         "0");
     106
     107    // Flash Settings
     108    this.addSetting("flash_url",                init_settings.flash_url,                "swfupload.swf");
     109    this.addSetting("flash_width",              init_settings.flash_width,              "1px");
     110    this.addSetting("flash_height",             init_settings.flash_height,             "1px");
     111    this.addSetting("flash_color",              init_settings.flash_color,              "#FFFFFF");
     112
     113    // Debug Settings
     114    this.addSetting("debug_enabled", init_settings.debug,  false);
     115
     116    // Event Handlers
     117    this.flashReady_handler         = SWFUpload.flashReady; // This is a non-overrideable event handler
     118    this.swfUploadLoaded_handler    = this.retrieveSetting(init_settings.swfupload_loaded_handler,      SWFUpload.swfUploadLoaded);
    84119   
    85     // Upload backend settings
    86     this.ensureDefault("upload_url", "");
    87     this.ensureDefault("file_post_name", "Filedata");
    88     this.ensureDefault("post_params", {});
    89     this.ensureDefault("use_query_string", false);
    90     this.ensureDefault("requeue_on_error", false);
     120    this.fileDialogStart_handler    = this.retrieveSetting(init_settings.file_dialog_start_handler,     SWFUpload.fileDialogStart);
     121    this.fileQueued_handler         = this.retrieveSetting(init_settings.file_queued_handler,           SWFUpload.fileQueued);
     122    this.fileQueueError_handler     = this.retrieveSetting(init_settings.file_queue_error_handler,      SWFUpload.fileQueueError);
     123    this.fileDialogComplete_handler = this.retrieveSetting(init_settings.file_dialog_complete_handler,  SWFUpload.fileDialogComplete);
    91124   
    92     // File Settings
    93     this.ensureDefault("file_types", "*.*");
    94     this.ensureDefault("file_types_description", "All Files");
    95     this.ensureDefault("file_size_limit", 0);   // Default zero means "unlimited"
    96     this.ensureDefault("file_upload_limit", 0);
    97     this.ensureDefault("file_queue_limit", 0);
    98 
    99     // Flash Settings
    100     this.ensureDefault("flash_url", "swfupload_f9.swf");
    101     this.ensureDefault("flash_color", "#FFFFFF");
    102 
    103     // Debug Settings
    104     this.ensureDefault("debug", false);
    105     this.settings.debug_enabled = this.settings.debug;  // Here to maintain v2 API
    106    
    107     // Event Handlers
    108     this.settings.return_upload_start_handler = this.returnUploadStart;
    109     this.ensureDefault("swfupload_loaded_handler", null);
    110     this.ensureDefault("file_dialog_start_handler", null);
    111     this.ensureDefault("file_queued_handler", null);
    112     this.ensureDefault("file_queue_error_handler", null);
    113     this.ensureDefault("file_dialog_complete_handler", null);
    114    
    115     this.ensureDefault("upload_start_handler", null);
    116     this.ensureDefault("upload_progress_handler", null);
    117     this.ensureDefault("upload_error_handler", null);
    118     this.ensureDefault("upload_success_handler", null);
    119     this.ensureDefault("upload_complete_handler", null);
    120    
    121     this.ensureDefault("debug_handler", this.debugMessage);
    122 
    123     this.ensureDefault("custom_settings", {});
     125    this.uploadStart_handler        = this.retrieveSetting(init_settings.upload_start_handler,          SWFUpload.uploadStart);
     126    this.uploadProgress_handler     = this.retrieveSetting(init_settings.upload_progress_handler,       SWFUpload.uploadProgress);
     127    this.uploadError_handler        = this.retrieveSetting(init_settings.upload_error_handler,          SWFUpload.uploadError);
     128    this.uploadSuccess_handler      = this.retrieveSetting(init_settings.upload_success_handler,        SWFUpload.uploadSuccess);
     129    this.uploadComplete_handler     = this.retrieveSetting(init_settings.upload_complete_handler,       SWFUpload.uploadComplete);
     130
     131    this.debug_handler              = this.retrieveSetting(init_settings.debug_handler,                 SWFUpload.debug);
    124132
    125133    // Other settings
    126     this.customSettings = this.settings.custom_settings;
    127    
    128     delete this.ensureDefault;
    129 };
    130 
    131 // Private: loadFlash generates the HTML tag for the Flash
    132 // It then adds the flash to the body
     134    this.customSettings = this.retrieveSetting(init_settings.custom_settings, {});
     135};
     136
     137// loadFlash is a private method that generates the HTML tag for the Flash
     138// It then adds the flash to the "target" or to the body and stores a
     139// reference to the flash element in "movieElement".
    133140SWFUpload.prototype.loadFlash = function () {
    134     var targetElement, container;
     141    var html, target_element, container;
    135142
    136143    // Make sure an element with the ID we are going to use doesn't already exist
    137144    if (document.getElementById(this.movieName) !== null) {
    138         throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
     145        return false;
    139146    }
    140147
    141148    // Get the body tag where we will be adding the flash movie
    142     targetElement = document.getElementsByTagName("body")[0];
    143 
    144     if (targetElement == undefined) {
    145         throw "Could not find the 'body' element.";
     149    try {
     150        target_element = document.getElementsByTagName("body")[0];
     151        if (typeof(target_element) === "undefined" || target_element === null) {
     152            this.debug('Could not find the BODY element. SWFUpload failed to load.');
     153            return false;
     154        }
     155    } catch (ex) {
     156        return false;
    146157    }
    147158
    148159    // Append the container and load the flash
    149160    container = document.createElement("div");
    150     container.style.width = "1px";
    151     container.style.height = "1px";
    152 
    153     targetElement.appendChild(container);
     161    container.style.width = this.getSetting("flash_width");
     162    container.style.height = this.getSetting("flash_height");
     163
     164    target_element.appendChild(container);
    154165    container.innerHTML = this.getFlashHTML();  // Using innerHTML is non-standard but the only sensible way to dynamically add Flash in IE (and maybe other browsers)
    155166};
    156167
    157 // Private: getFlashHTML generates the object tag needed to embed the flash in to the document
     168// Generates the embed/object tags needed to embed the flash in to the document
    158169SWFUpload.prototype.getFlashHTML = function () {
    159     // Flash Satay object syntax: http://www.alistapart.com/articles/flashsatay
    160     return ['<object id="', this.movieName, '" type="application/x-shockwave-flash" data="', this.settings.flash_url, '" width="1" height="1" style="-moz-user-focus: ignore;">',
    161                 '<param name="movie" value="', this.settings.flash_url, '" />',
    162                 '<param name="bgcolor" value="', this.settings.flash_color, '" />',
    163                 '<param name="quality" value="high" />',
    164                 '<param name="menu" value="false" />',
    165                 '<param name="allowScriptAccess" value="always" />',
    166                 '<param name="flashvars" value="' + this.getFlashVars() + '" />',
    167                 '</object>'].join("");
    168 };
    169 
    170 // Private: getFlashVars builds the parameter string that will be passed
    171 // to flash in the flashvars param.
     170    var html = "";
     171
     172    // Create Mozilla Embed HTML
     173    if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) {
     174        // Build the basic embed html
     175        html = '<embed type="application/x-shockwave-flash" src="' + this.getSetting("flash_url") + '" width="' + this.getSetting("flash_width") + '" height="' + this.getSetting("flash_height") + '"';
     176        html += ' id="' + this.movieName + '" name="' + this.movieName + '" ';
     177        html += 'bgcolor="' + this.getSetting("flash_color") + '" quality="high" menu="false" flashvars="';
     178
     179        html += this.getFlashVars();
     180
     181        html += '" />';
     182
     183        // Create IE Object HTML
     184    } else {
     185
     186        // Build the basic Object tag
     187        html = '<object id="' + this.movieName + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + this.getSetting("flash_width") + '" height="' + this.getSetting("flash_height") + '">';
     188        html += '<param name="movie" value="' + this.getSetting("flash_url") + '">';
     189
     190        html += '<param name="bgcolor" value="' + this.getSetting("flash_color") + '" />';
     191        html += '<param name="quality" value="high" />';
     192        html += '<param name="menu" value="false" />';
     193
     194        html += '<param name="flashvars" value="' + this.getFlashVars() + '" />';
     195        html += '</object>';
     196    }
     197
     198    return html;
     199};
     200
     201// This private method builds the parameter string that will be passed
     202// to flash.
    172203SWFUpload.prototype.getFlashVars = function () {
    173204    // Build a string from the post param object
    174     var paramString = this.buildParamString();
     205    var param_string = this.buildParamString();
    175206
    176207    // Build the parameter string
    177     return ["movieName=", encodeURIComponent(this.movieName),
    178             "&amp;uploadURL=", encodeURIComponent(this.settings.upload_url),
    179             "&amp;useQueryString=", encodeURIComponent(this.settings.use_query_string),
    180             "&amp;requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),
    181             "&amp;params=", encodeURIComponent(paramString),
    182             "&amp;filePostName=", encodeURIComponent(this.settings.file_post_name),
    183             "&amp;fileTypes=", encodeURIComponent(this.settings.file_types),
    184             "&amp;fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),
    185             "&amp;fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),
    186             "&amp;fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),
    187             "&amp;fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),
    188             "&amp;debugEnabled=", encodeURIComponent(this.settings.debug_enabled)].join("");
    189 };
    190 
    191 // Public: getMovieElement retrieves the DOM reference to the Flash element added by SWFUpload
    192 // The element is cached after the first lookup
     208    var html = "";
     209    html += "movieName=" + encodeURIComponent(this.movieName);
     210    html += "&uploadURL=" + encodeURIComponent(this.getSetting("upload_url"));
     211    html += "&params=" + encodeURIComponent(param_string);
     212    html += "&filePostName=" + encodeURIComponent(this.getSetting("file_post_name"));
     213    html += "&fileTypes=" + encodeURIComponent(this.getSetting("file_types"));
     214    html += "&fileTypesDescription=" + encodeURIComponent(this.getSetting("file_types_description"));
     215    html += "&fileSizeLimit=" + encodeURIComponent(this.getSetting("file_size_limit"));
     216    html += "&fileUploadLimit=" + encodeURIComponent(this.getSetting("file_upload_limit"));
     217    html += "&fileQueueLimit=" + encodeURIComponent(this.getSetting("file_queue_limit"));
     218    html += "&debugEnabled=" + encodeURIComponent(this.getSetting("debug_enabled"));
     219
     220    return html;
     221};
     222
    193223SWFUpload.prototype.getMovieElement = function () {
    194     if (this.movieElement == undefined) {
     224    if (typeof(this.movieElement) === "undefined" || this.movieElement === null) {
    195225        this.movieElement = document.getElementById(this.movieName);
    196     }
    197 
    198     if (this.movieElement === null) {
    199         throw "Could not find Flash element";
    200     }
    201    
     226
     227        // 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)
     228        // Removed because Revision 6 always adds the flash to the body (inside a containing div)
     229        // 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
     230        // and run this code to make the form's ID available from the window object so Flash and JavaScript can communicate.
     231        //if (typeof(window[this.movieName]) === "undefined" || window[this.moveName] !== this.movieElement) {
     232        //  window[this.movieName] = this.movieElement;
     233        //}
     234    }
     235
    202236    return this.movieElement;
    203237};
    204238
    205 // Private: buildParamString takes the name/value pairs in the post_params setting object
    206 // and joins them up in to a string formatted "name=value&amp;name=value"
    207239SWFUpload.prototype.buildParamString = function () {
    208     var postParams = this.settings.post_params;
    209     var paramStringPairs = [];
    210 
    211     if (typeof(postParams) === "object") {
    212         for (var name in postParams) {
    213             if (postParams.hasOwnProperty(name)) {
    214                 paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString()));
    215             }
    216         }
    217     }
    218 
    219     return paramStringPairs.join("&amp;");
    220 };
    221 
    222 // Public: Used to remove a SWFUpload instance from the page. This method strives to remove
    223 // all references to the SWF, and other objects so memory is properly freed.
    224 // Returns true if everything was destroyed. Returns a false if a failure occurs leaving SWFUpload in an inconsistant state.
    225 SWFUpload.prototype.destroy = function () {
    226     try {
    227         // Make sure Flash is done before we try to remove it
    228         this.stopUpload();
    229        
    230         // Remove the SWFUpload DOM nodes
    231         var movieElement = null;
    232         try {
    233             movieElement = this.getMovieElement();
    234         } catch (ex) {
    235         }
    236        
    237         if (movieElement != undefined && movieElement.parentNode != undefined && typeof(movieElement.parentNode.removeChild) === "function") {
    238             var container = movieElement.parentNode;
    239             if (container != undefined) {
    240                 container.removeChild(movieElement);
    241                 if (container.parentNode != undefined && typeof(container.parentNode.removeChild) === "function") {
    242                     container.parentNode.removeChild(container);
     240    var post_params = this.getSetting("post_params");
     241    var param_string_pairs = [];
     242    var i, value, name;
     243
     244    // Retrieve the user defined parameters
     245    if (typeof(post_params) === "object") {
     246        for (name in post_params) {
     247            if (post_params.hasOwnProperty(name)) {
     248                if (typeof(post_params[name]) === "string") {
     249                    param_string_pairs.push(encodeURIComponent(name) + "=" + encodeURIComponent(post_params[name]));
    243250                }
    244251            }
    245252        }
    246        
    247         // Destroy references
    248         SWFUpload.instances[this.movieName] = null;
    249         delete SWFUpload.instances[this.movieName];
    250 
    251         delete this.movieElement;
    252         delete this.settings;
    253         delete this.customSettings;
    254         delete this.eventQueue;
    255         delete this.movieName;
    256        
    257         return true;
    258     } catch (ex1) {
    259         return false;
    260     }
    261 };
    262 
    263 // Public: displayDebugInfo prints out settings and configuration
    264 // information about this SWFUpload instance.
    265 // This function (and any references to it) can be deleted when placing
    266 // SWFUpload in production.
     253    }
     254
     255    return param_string_pairs.join("&");
     256};
     257
     258// Saves a setting.  If the value given is undefined or null then the default_value is used.
     259SWFUpload.prototype.addSetting = function (name, value, default_value) {
     260    if (typeof(value) === "undefined" || value === null) {
     261        this.settings[name] = default_value;
     262    } else {
     263        this.settings[name] = value;
     264    }
     265
     266    return this.settings[name];
     267};
     268
     269// Gets a setting.  Returns empty string if not found.
     270SWFUpload.prototype.getSetting = function (name) {
     271    if (typeof(this.settings[name]) === "undefined") {
     272        return "";
     273    } else {
     274        return this.settings[name];
     275    }
     276};
     277
     278// Gets a setting, if the setting is undefined then return the default value
     279// This does not affect or use the interal setting object.
     280SWFUpload.prototype.retrieveSetting = function (value, default_value) {
     281    if (typeof(value) === "undefined" || value === null) {
     282        return default_value;
     283    } else {
     284        return value;
     285    }
     286};
     287
     288
     289// It loops through all the settings and displays
     290// them in the debug Console.
    267291SWFUpload.prototype.displayDebugInfo = function () {
    268     this.debug(
    269         [
    270             "---SWFUpload Instance Info---\n",
    271             "Version: ", SWFUpload.version, "\n",
    272             "Movie Name: ", this.movieName, "\n",
    273             "Settings:\n",
    274             "\t", "upload_url:             ", this.settings.upload_url, "\n",
    275             "\t", "use_query_string:       ", this.settings.use_query_string.toString(), "\n",
    276             "\t", "file_post_name:         ", this.settings.file_post_name, "\n",
    277             "\t", "post_params:            ", this.settings.post_params.toString(), "\n",
    278             "\t", "file_types:             ", this.settings.file_types, "\n",
    279             "\t", "file_types_description: ", this.settings.file_types_description, "\n",
    280             "\t", "file_size_limit:        ", this.settings.file_size_limit, "\n",
    281             "\t", "file_upload_limit:      ", this.settings.file_upload_limit, "\n",
    282             "\t", "file_queue_limit:       ", this.settings.file_queue_limit, "\n",
    283             "\t", "flash_url:              ", this.settings.flash_url, "\n",
    284             "\t", "flash_color:            ", this.settings.flash_color, "\n",
    285             "\t", "debug:                  ", this.settings.debug.toString(), "\n",
    286             "\t", "custom_settings:        ", this.settings.custom_settings.toString(), "\n",
    287             "Event Handlers:\n",
    288             "\t", "swfupload_loaded_handler assigned:  ", (typeof(this.settings.swfupload_loaded_handler) === "function").toString(), "\n",
    289             "\t", "file_dialog_start_handler assigned: ", (typeof(this.settings.file_dialog_start_handler) === "function").toString(), "\n",
    290             "\t", "file_queued_handler assigned:       ", (typeof(this.settings.file_queued_handler) === "function").toString(), "\n",
    291             "\t", "file_queue_error_handler assigned:  ", (typeof(this.settings.file_queue_error_handler) === "function").toString(), "\n",
    292             "\t", "upload_start_handler assigned:      ", (typeof(this.settings.upload_start_handler) === "function").toString(), "\n",
    293             "\t", "upload_progress_handler assigned:   ", (typeof(this.settings.upload_progress_handler) === "function").toString(), "\n",
    294             "\t", "upload_error_handler assigned:      ", (typeof(this.settings.upload_error_handler) === "function").toString(), "\n",
    295             "\t", "upload_success_handler assigned:    ", (typeof(this.settings.upload_success_handler) === "function").toString(), "\n",
    296             "\t", "upload_complete_handler assigned:   ", (typeof(this.settings.upload_complete_handler) === "function").toString(), "\n",
    297             "\t", "debug_handler assigned:             ", (typeof(this.settings.debug_handler) === "function").toString(), "\n"
    298         ].join("")
    299     );
    300 };
    301 
    302 /* Note: addSetting and getSetting are no longer used by SWFUpload but are included
    303     the maintain v2 API compatibility
    304 */
    305 // Public: (Deprecated) addSetting adds a setting value. If the value given is undefined or null then the default_value is used.
    306 SWFUpload.prototype.addSetting = function (name, value, default_value) {
    307     if (value == undefined) {
    308         return (this.settings[name] = default_value);
    309     } else {
    310         return (this.settings[name] = value);
    311     }
    312 };
    313 
    314 // Public: (Deprecated) getSetting gets a setting. Returns an empty string if the setting was not found.
    315 SWFUpload.prototype.getSetting = function (name) {
    316     if (this.settings[name] != undefined) {
    317         return this.settings[name];
    318     }
    319 
    320     return "";
    321 };
    322 
    323 
    324 
    325 // Private: callFlash handles function calls made to the Flash element.
    326 // Calls are made with a setTimeout for some functions to work around
    327 // bugs in the ExternalInterface library.
    328 SWFUpload.prototype.callFlash = function (functionName, argumentArray) {
    329     argumentArray = argumentArray || [];
    330    
    331     var self = this;
    332     var callFunction = function () {
    333         var movieElement = self.getMovieElement();
    334         var returnValue;
    335         if (typeof(movieElement[functionName]) === "function") {
    336             // 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.
    337             if (argumentArray.length === 0) {
    338                 returnValue = movieElement[functionName]();
    339             } else if (argumentArray.length === 1) {
    340                 returnValue = movieElement[functionName](argumentArray[0]);
    341             } else if (argumentArray.length === 2) {
    342                 returnValue = movieElement[functionName](argumentArray[0], argumentArray[1]);
    343             } else if (argumentArray.length === 3) {
    344                 returnValue = movieElement[functionName](argumentArray[0], argumentArray[1], argumentArray[2]);
     292    var key, debug_message = "";
     293
     294    debug_message += "----- SWFUPLOAD SETTINGS     ----\nID: " + this.moveName + "\n";
     295
     296    debug_message += this.outputObject(this.settings);
     297
     298    debug_message += "----- SWFUPLOAD SETTINGS END ----\n";
     299    debug_message += "\n";
     300
     301    this.debug(debug_message);
     302};
     303SWFUpload.prototype.outputObject = function (object, prefix) {
     304    var output = "", key;
     305
     306    if (typeof(prefix) !== "string") {
     307        prefix = "";
     308    }
     309    if (typeof(object) !== "object") {
     310        return "";
     311    }
     312
     313    for (key in object) {
     314        if (object.hasOwnProperty(key)) {
     315            if (typeof(object[key]) === "object") {
     316                output += (prefix + key + ": { \n" + this.outputObject(object[key], "\t" + prefix) + prefix + "}" + "\n");
    345317            } else {
    346                 throw "Too many arguments";
     318                output += (prefix + key + ": " + object[key] + "\n");
    347319            }
    348            
    349             // Unescape file post param values
    350             if (returnValue != undefined && typeof(returnValue.post) === "object") {
    351                 returnValue = self.unescapeFilePostParams(returnValue);
    352             }
    353            
    354             return returnValue;
    355         } else {
    356             throw "Invalid function name";
    357         }
    358     };
    359    
    360     return callFunction();
    361 };
    362 
     320        }
     321    }
     322
     323    return output;
     324};
    363325
    364326/* *****************************
     
    368330   ***************************** */
    369331
    370 // Public: selectFile causes a File Selection Dialog window to appear.  This
    371 // dialog only allows 1 file to be selected.
    372332SWFUpload.prototype.selectFile = function () {
    373     this.callFlash("SelectFile");
    374 };
    375 
    376 // Public: selectFiles causes a File Selection Dialog window to appear/ This
    377 // dialog allows the user to select any number of files
    378 // Flash Bug Warning: Flash limits the number of selectable files based on the combined length of the file names.
    379 // If the selection name length is too long the dialog will fail in an unpredictable manner.  There is no work-around
    380 // for this bug.
     333    var movie_element = this.getMovieElement();
     334    if (movie_element !== null && typeof(movie_element.SelectFile) === "function") {
     335        try {
     336            movie_element.SelectFile();
     337        }
     338        catch (ex) {
     339            this.debug("Could not call SelectFile: " + ex);
     340        }
     341    } else {
     342        this.debug("Could not find Flash element");
     343    }
     344
     345};
     346
    381347SWFUpload.prototype.selectFiles = function () {
    382     this.callFlash("SelectFiles");
    383 };
    384 
    385 
    386 // Public: startUpload starts uploading the first file in the queue unless
    387 // the optional parameter 'fileID' specifies the ID
    388 SWFUpload.prototype.startUpload = function (fileID) {
    389     this.callFlash("StartUpload", [fileID]);
     348    var movie_element = this.getMovieElement();
     349    if (movie_element !== null && typeof(movie_element.SelectFiles) === "function") {
     350        try {
     351            movie_element.SelectFiles();
     352        }
     353        catch (ex) {
     354            this.debug("Could not call SelectFiles: " + ex);
     355        }
     356    } else {
     357        this.debug("Could not find Flash element");
     358    }
     359
     360};
     361
     362
     363/* Start the upload.  If a file_id is specified that file is uploaded. Otherwise the first
     364 * file in the queue is uploaded.  If no files are in the queue then nothing happens.
     365 * This call uses setTimeout since Flash will be calling back in to JavaScript
     366 */
     367SWFUpload.prototype.startUpload = function (file_id) {
     368    var self = this;
     369    var movie_element = this.getMovieElement();
     370    if (movie_element !== null && typeof(movie_element.StartUpload) === "function") {
     371        setTimeout(
     372            function () {
     373                try {
     374                    movie_element.StartUpload(file_id);
     375                }
     376                catch (ex) {
     377                    self.debug("Could not call StartUpload: " + ex);
     378                }
     379            }, 0
     380        );
     381    } else {
     382        this.debug("Could not find Flash element");
     383    }
     384
    390385};
    391386
    392387/* Cancels a the file upload.  You must specify a file_id */
    393 // Public: cancelUpload cancels any queued file.  The fileID parameter
    394 // must be specified.
    395 SWFUpload.prototype.cancelUpload = function (fileID) {
    396     this.callFlash("CancelUpload", [fileID]);
    397 };
    398 
    399 // Public: stopUpload stops the current upload and requeues the file at the beginning of the queue.
    400 // If nothing is currently uploading then nothing happens.
     388SWFUpload.prototype.cancelUpload = function (file_id) {
     389    var movie_element = this.getMovieElement();
     390    if (movie_element !== null && typeof(movie_element.CancelUpload) === "function") {
     391        try {
     392            movie_element.CancelUpload(file_id);
     393        }
     394        catch (ex) {
     395            this.debug("Could not call CancelUpload: " + ex);
     396        }
     397    } else {
     398        this.debug("Could not find Flash element");
     399    }
     400
     401};
     402
     403// Stops the current upload.  The file is re-queued.  If nothing is currently uploading then nothing happens.
    401404SWFUpload.prototype.stopUpload = function () {
    402     this.callFlash("StopUpload");
     405    var movie_element = this.getMovieElement();
     406    if (movie_element !== null && typeof(movie_element.StopUpload) === "function") {
     407        try {
     408            movie_element.StopUpload();
     409        }
     410        catch (ex) {
     411            this.debug("Could not call StopUpload: " + ex);
     412        }
     413    } else {
     414        this.debug("Could not find Flash element");
     415    }
     416
    403417};
    404418
    405419/* ************************
    406420 * Settings methods
    407  *   These methods change the SWFUpload settings.
    408  *   SWFUpload settings should not be changed directly on the settings object
    409  *   since many of the settings need to be passed to Flash in order to take
    410  *   effect.
    411  * *********************** */
    412 
    413 // Public: getStats gets the file statistics object.
     421 *   These methods change the settings inside SWFUpload
     422 *   They shouldn't need to be called in a setTimeout since they
     423 *   should not call back from Flash to JavaScript (except perhaps in a Debug call)
     424 *   and some need to return data so setTimeout won't work.
     425 */
     426
     427/* Gets the file statistics object.  It looks like this (where n = number):
     428    {
     429        files_queued: n,
     430        complete_uploads: n,
     431        upload_errors: n,
     432        uploads_cancelled: n,
     433        queue_errors: n
     434    }
     435*/
    414436SWFUpload.prototype.getStats = function () {
    415     return this.callFlash("GetStats");
    416 };
    417 
    418 // Public: setStats changes the SWFUpload statistics.  You shouldn't need to
    419 // change the statistics but you can.  Changing the statistics does not
    420 // affect SWFUpload accept for the successful_uploads count which is used
    421 // by the upload_limit setting to determine how many files the user may upload.
    422 SWFUpload.prototype.setStats = function (statsObject) {
    423     this.callFlash("SetStats", [statsObject]);
    424 };
    425 
    426 // Public: getFile retrieves a File object by ID or Index.  If the file is
    427 // not found then 'null' is returned.
    428 SWFUpload.prototype.getFile = function (fileID) {
    429     if (typeof(fileID) === "number") {
    430         return this.callFlash("GetFileByIndex", [fileID]);
    431     } else {
    432         return this.callFlash("GetFile", [fileID]);
    433     }
    434 };
    435 
    436 // Public: addFileParam sets a name/value pair that will be posted with the
    437 // file specified by the Files ID.  If the name already exists then the
    438 // exiting value will be overwritten.
    439 SWFUpload.prototype.addFileParam = function (fileID, name, value) {
    440     return this.callFlash("AddFileParam", [fileID, name, value]);
    441 };
    442 
    443 // Public: removeFileParam removes a previously set (by addFileParam) name/value
    444 // pair from the specified file.
    445 SWFUpload.prototype.removeFileParam = function (fileID, name) {
    446     this.callFlash("RemoveFileParam", [fileID, name]);
    447 };
    448 
    449 // Public: setUploadUrl changes the upload_url setting.
     437    var movie_element = this.getMovieElement();
     438    if (movie_element !== null && typeof(movie_element.GetStats) === "function") {
     439        try {
     440            return movie_element.GetStats();
     441        }
     442        catch (ex) {
     443            this.debug("Could not call GetStats");
     444        }
     445    } else {
     446        this.debug("Could not find Flash element");
     447    }
     448};
     449SWFUpload.prototype.setStats = function (stats_object) {
     450    var movie_element = this.getMovieElement();
     451    if (movie_element !== null && typeof(movie_element.SetStats) === "function") {
     452        try {
     453            movie_element.SetStats(stats_object);
     454        }
     455        catch (ex) {
     456            this.debug("Could not call SetStats");
     457        }
     458    } else {
     459        this.debug("Could not find Flash element");
     460    }
     461};
     462
     463SWFUpload.prototype.setCredentials = function(name, password) {
     464    var movie_element = this.getMovieElement();
     465    if (movie_element !== null && typeof(movie_element.SetCredentials) === "function") {
     466        try {
     467            return movie_element.SetCredentials(name, password);
     468        }
     469        catch (ex) {
     470            this.debug("Could not call SetCredentials");
     471        }
     472    } else {
     473        this.debug("Could not find Flash element");
     474    }
     475};
     476
     477SWFUpload.prototype.getFile = function (file_id) {
     478    var movie_element = this.getMovieElement();
     479            if (typeof(file_id) === "number") {
     480                if (movie_element !== null && typeof(movie_element.GetFileByIndex) === "function") {
     481                    try {
     482                        return movie_element.GetFileByIndex(file_id);
     483                    }
     484                    catch (ex) {
     485                        this.debug("Could not call GetFileByIndex");
     486                    }
     487                } else {
     488                    this.debug("Could not find Flash element");
     489                }
     490            } else {
     491                if (movie_element !== null && typeof(movie_element.GetFile) === "function") {
     492                    try {
     493                        return movie_element.GetFile(file_id);
     494                    }
     495                    catch (ex) {
     496                        this.debug("Could not call GetFile");
     497                    }
     498                } else {
     499                    this.debug("Could not find Flash element");
     500                }
     501            }
     502};
     503
     504SWFUpload.prototype.addFileParam = function (file_id, name, value) {
     505    var movie_element = this.getMovieElement();
     506    if (movie_element !== null && typeof(movie_element.AddFileParam) === "function") {
     507        try {
     508            return movie_element.AddFileParam(file_id, name, value);
     509        }
     510        catch (ex) {
     511            this.debug("Could not call AddFileParam");
     512        }
     513    } else {
     514        this.debug("Could not find Flash element");
     515    }
     516};
     517
     518SWFUpload.prototype.removeFileParam = function (file_id, name) {
     519    var movie_element = this.getMovieElement();
     520    if (movie_element !== null && typeof(movie_element.RemoveFileParam) === "function") {
     521        try {
     522            return movie_element.RemoveFileParam(file_id, name);
     523        }
     524        catch (ex) {
     525            this.debug("Could not call AddFileParam");
     526        }
     527    } else {
     528        this.debug("Could not find Flash element");
     529    }
     530
     531};
     532
    450533SWFUpload.prototype.setUploadURL = function (url) {
    451     this.settings.upload_url = url.toString();
    452     this.callFlash("SetUploadURL", [url]);
    453 };
    454 
    455 // Public: setPostParams changes the post_params setting
    456 SWFUpload.prototype.setPostParams = function (paramsObject) {
    457     this.settings.post_params = paramsObject;
    458     this.callFlash("SetPostParams", [paramsObject]);
    459 };
    460 
    461 // Public: addPostParam adds post name/value pair.  Each name can have only one value.
    462 SWFUpload.prototype.addPostParam = function (name, value) {
    463     this.settings.post_params[name] = value;
    464     this.callFlash("SetPostParams", [this.settings.post_params]);
    465 };
    466 
    467 // Public: removePostParam deletes post name/value pair.
    468 SWFUpload.prototype.removePostParam = function (name) {
    469     delete this.settings.post_params[name];
    470     this.callFlash("SetPostParams", [this.settings.post_params]);
    471 };
    472 
    473 // Public: setFileTypes changes the file_types setting and the file_types_description setting
     534    var movie_element = this.getMovieElement();
     535    if (movie_element !== null && typeof(movie_element.SetUploadURL) === "function") {
     536        try {
     537            this.addSetting("upload_url", url);
     538            movie_element.SetUploadURL(this.getSetting("upload_url"));
     539        }
     540        catch (ex) {
     541            this.debug("Could not call SetUploadURL");
     542        }
     543    } else {
     544        this.debug("Could not find Flash element in setUploadURL");
     545    }
     546};
     547
     548SWFUpload.prototype.setPostParams = function (param_object) {
     549    var movie_element = this.getMovieElement();
     550    if (movie_element !== null && typeof(movie_element.SetPostParams) === "function") {
     551        try {
     552            this.addSetting("post_params", param_object);
     553            movie_element.SetPostParams(this.getSetting("post_params"));
     554        }
     555        catch (ex) {
     556            this.debug("Could not call SetPostParams");
     557        }
     558    } else {
     559        this.debug("Could not find Flash element in SetPostParams");
     560    }
     561};
     562
    474563SWFUpload.prototype.setFileTypes = function (types, description) {
    475     this.settings.file_types = types;
    476     this.settings.file_types_description = description;
    477     this.callFlash("SetFileTypes", [types, description]);
    478 };
    479 
    480 // Public: setFileSizeLimit changes the file_size_limit setting
    481 SWFUpload.prototype.setFileSizeLimit = function (fileSizeLimit) {
    482     this.settings.file_size_limit = fileSizeLimit;
    483     this.callFlash("SetFileSizeLimit", [fileSizeLimit]);
    484 };
    485 
    486 // Public: setFileUploadLimit changes the file_upload_limit setting
    487 SWFUpload.prototype.setFileUploadLimit = function (fileUploadLimit) {
    488     this.settings.file_upload_limit = fileUploadLimit;
    489     this.callFlash("SetFileUploadLimit", [fileUploadLimit]);
    490 };
    491 
    492 // Public: setFileQueueLimit changes the file_queue_limit setting
    493 SWFUpload.prototype.setFileQueueLimit = function (fileQueueLimit) {
    494     this.settings.file_queue_limit = fileQueueLimit;
    495     this.callFlash("SetFileQueueLimit", [fileQueueLimit]);
    496 };
    497 
    498 // Public: setFilePostName changes the file_post_name setting
    499 SWFUpload.prototype.setFilePostName = function (filePostName) {
    500     this.settings.file_post_name = filePostName;
    501     this.callFlash("SetFilePostName", [filePostName]);
    502 };
    503 
    504 // Public: setUseQueryString changes the use_query_string setting
    505 SWFUpload.prototype.setUseQueryString = function (useQueryString) {
    506     this.settings.use_query_string = useQueryString;
    507     this.callFlash("SetUseQueryString", [useQueryString]);
    508 };
    509 
    510 // Public: setRequeueOnError changes the requeue_on_error setting
    511 SWFUpload.prototype.setRequeueOnError = function (requeueOnError) {
    512     this.settings.requeue_on_error = requeueOnError;
    513     this.callFlash("SetRequeueOnError", [requeueOnError]);
    514 };
    515 
    516 // Public: setDebugEnabled changes the debug_enabled setting
    517 SWFUpload.prototype.setDebugEnabled = function (debugEnabled) {
    518     this.settings.debug_enabled = debugEnabled;
    519     this.callFlash("SetDebugEnabled", [debugEnabled]);
    520 };
    521 
     564    var movie_element = this.getMovieElement();
     565    if (movie_element !== null && typeof(movie_element.SetFileTypes) === "function") {
     566        try {
     567            this.addSetting("file_types", types);
     568            this.addSetting("file_types_description", description);
     569            movie_element.SetFileTypes(this.getSetting("file_types"), this.getSetting("file_types_description"));
     570        }
     571        catch (ex) {
     572            this.debug("Could not call SetFileTypes");
     573        }
     574    } else {
     575        this.debug("Could not find Flash element in SetFileTypes");
     576    }
     577};
     578
     579SWFUpload.prototype.setFileSizeLimit = function (file_size_limit) {
     580    var movie_element = this.getMovieElement();
     581    if (movie_element !== null && typeof(movie_element.SetFileSizeLimit) === "function") {
     582        try {
     583            this.addSetting("file_size_limit", file_size_limit);
     584            movie_element.SetFileSizeLimit(this.getSetting("file_size_limit"));
     585        }
     586        catch (ex) {
     587            this.debug("Could not call SetFileSizeLimit");
     588        }
     589    } else {
     590        this.debug("Could not find Flash element in SetFileSizeLimit");
     591    }
     592};
     593
     594SWFUpload.prototype.setFileUploadLimit = function (file_upload_limit) {
     595    var movie_element = this.getMovieElement();
     596    if (movie_element !== null && typeof(movie_element.SetFileUploadLimit) === "function") {
     597        try {
     598            this.addSetting("file_upload_limit", file_upload_limit);
     599            movie_element.SetFileUploadLimit(this.getSetting("file_upload_limit"));
     600        }
     601        catch (ex) {
     602            this.debug("Could not call SetFileUploadLimit");
     603        }
     604    } else {
     605        this.debug("Could not find Flash element in SetFileUploadLimit");
     606    }
     607};
     608
     609SWFUpload.prototype.setFileQueueLimit = function (file_queue_limit) {
     610    var movie_element = this.getMovieElement();
     611    if (movie_element !== null && typeof(movie_element.SetFileQueueLimit) === "function") {
     612        try {
     613            this.addSetting("file_queue_limit", file_queue_limit);
     614            movie_element.SetFileQueueLimit(this.getSetting("file_queue_limit"));
     615        }
     616        catch (ex) {
     617            this.debug("Could not call SetFileQueueLimit");
     618        }
     619    } else {
     620        this.debug("Could not find Flash element in SetFileQueueLimit");
     621    }
     622};
     623
     624SWFUpload.prototype.setFilePostName = function (file_post_name) {
     625    var movie_element = this.getMovieElement();
     626    if (movie_element !== null && typeof(movie_element.SetFilePostName) === "function") {
     627        try {
     628            this.addSetting("file_post_name", file_post_name);
     629            movie_element.SetFilePostName(this.getSetting("file_post_name"));
     630        }
     631        catch (ex) {
     632            this.debug("Could not call SetFilePostName");
     633        }
     634    } else {
     635        this.debug("Could not find Flash element in SetFilePostName");
     636    }
     637};
     638
     639SWFUpload.prototype.setDebugEnabled = function (debug_enabled) {
     640    var movie_element = this.getMovieElement();
     641    if (movie_element !== null && typeof(movie_element.SetDebugEnabled) === "function") {
     642        try {
     643            this.addSetting("debug_enabled", debug_enabled);
     644            movie_element.SetDebugEnabled(this.getSetting("debug_enabled"));
     645        }
     646        catch (ex) {
     647            this.debug("Could not call SetDebugEnabled");
     648        }
     649    } else {
     650        this.debug("Could not find Flash element in SetDebugEnabled");
     651    }
     652};
    522653
    523654/* *******************************
    524     Flash Event Interfaces
    525     These functions are used by Flash to trigger the various
    526     events.
    527    
    528     All these functions a Private.
    529    
    530     Because the ExternalInterface library is buggy the event calls
    531     are added to a queue and the queue then executed by a setTimeout.
    532     This ensures that events are executed in a determinate order and that
    533     the ExternalInterface bugs are avoided.
     655    Internal Event Callers
     656    Don't override these! These event callers ensure that your custom event handlers
     657    are called safely and in order.
    534658******************************* */
    535659
    536 SWFUpload.prototype.queueEvent = function (handlerName, argumentArray) {
    537     // Warning: Don't call this.debug inside here or you'll create an infinite loop
    538    
    539     if (argumentArray == undefined) {
    540         argumentArray = [];
    541     } else if (!(argumentArray instanceof Array)) {
    542         argumentArray = [argumentArray];
    543     }
    544    
    545     var self = this;
    546     if (typeof(this.settings[handlerName]) === "function") {
    547         // Queue the event
    548         this.eventQueue.push(function () {
    549             this.settings[handlerName].apply(this, argumentArray);
    550         });
    551        
    552         // Execute the next queued event
    553         setTimeout(function () {
    554             self.executeNextEvent();
    555         }, 0);
    556        
    557     } else if (this.settings[handlerName] !== null) {
    558         throw "Event handler " + handlerName + " is unknown or is not a function";
    559     }
    560 };
    561 
    562 // Private: Causes the next event in the queue to be executed.  Since events are queued using a setTimeout
    563 // we must queue them in order to garentee that they are executed in order.
    564 SWFUpload.prototype.executeNextEvent = function () {
    565     // Warning: Don't call this.debug inside here or you'll create an infinite loop
    566 
    567     var  f = this.eventQueue ? this.eventQueue.shift() : null;
    568     if (typeof(f) === "function") {
    569         f.apply(this);
    570     }
    571 };
    572 
    573 // Private: unescapeFileParams is part of a workaround for a flash bug where objects passed through ExternalInterfance cannot have
    574 // properties that contain characters that are not valid for JavaScript identifiers. To work around this
    575 // the Flash Component escapes the parameter names and we must unescape again before passing them along.
    576 SWFUpload.prototype.unescapeFilePostParams = function (file) {
    577     var reg = /[$]([0-9a-f]{4})/i;
    578     var unescapedPost = {};
    579     var uk;
    580 
    581     if (file != undefined) {
    582         for (var k in file.post) {
    583             if (file.post.hasOwnProperty(k)) {
    584                 uk = k;
    585                 var match;
    586                 while ((match = reg.exec(uk)) !== null) {
    587                     uk = uk.replace(match[0], String.fromCharCode(parseInt("0x"+match[1], 16)));
    588                 }
    589                 unescapedPost[uk] = file.post[k];
    590             }
    591         }
    592 
    593         file.post = unescapedPost;
    594     }
    595 
    596     return file;
    597 };
    598 
     660/* This is the callback method that the Flash movie will call when it has been loaded and is ready to go.
     661   Calling this or showUI() "manually" will bypass the Flash Detection built in to SWFUpload.
     662   Use a ui_function setting if you want to control the UI loading after the flash has loaded.
     663*/
    599664SWFUpload.prototype.flashReady = function () {
    600665    // Check that the movie element is loaded correctly with its ExternalInterface methods defined
    601     var movieElement = this.getMovieElement();
    602     if (typeof(movieElement.StartUpload) !== "function") {
    603         throw "ExternalInterface methods failed to initialize.";
     666    var movie_element = this.getMovieElement();
     667    if (movie_element === null || typeof(movie_element.StartUpload) !== "function") {
     668        this.debug("ExternalInterface methods failed to initialize.");
     669        return;
    604670    }
    605671   
    606     this.queueEvent("swfupload_loaded_handler");
    607 };
    608 
     672    var self = this;
     673    if (typeof(self.flashReady_handler) === "function") {
     674        this.eventQueue[this.eventQueue.length] = function() { self.flashReady_handler(); };
     675        setTimeout(function () { self.executeNextEvent();}, 0);
     676    } else {
     677        this.debug("flashReady_handler event not defined");
     678    }
     679};
     680
     681/*
     682    Event Queue.  Rather can call events directly from Flash they events are
     683    are placed in a queue and then executed.  This ensures that each event is
     684    executed in the order it was called which is not guarenteed when calling
     685    setTimeout.  Out of order events was especially problematic in Safari.
     686*/
     687SWFUpload.prototype.executeNextEvent = function () {
     688    var  f = this.eventQueue.shift();
     689    if (typeof(f) === "function") {
     690        f();
     691    }
     692}
    609693
    610694/* This is a chance to do something before the browse window opens */
    611695SWFUpload.prototype.fileDialogStart = function () {
    612     this.queueEvent("file_dialog_start_handler");
     696    var self = this;
     697    if (typeof(self.fileDialogStart_handler) === "function") {
     698        this.eventQueue[this.eventQueue.length] = function() { self.fileDialogStart_handler(); };
     699        setTimeout(function () { self.executeNextEvent();}, 0);
     700    } else {
     701        this.debug("fileDialogStart event not defined");
     702    }
    613703};
    614704
     
    616706/* Called when a file is successfully added to the queue. */
    617707SWFUpload.prototype.fileQueued = function (file) {
    618     file = this.unescapeFilePostParams(file);
    619     this.queueEvent("file_queued_handler", file);
     708    var self = this;
     709    if (typeof(self.fileQueued_handler) === "function") {
     710        this.eventQueue[this.eventQueue.length] = function() { self.fileQueued_handler(file); };
     711        setTimeout(function () { self.executeNextEvent();}, 0);
     712    } else {
     713        this.debug("fileQueued event not defined");
     714    }
    620715};
    621716
    622717
    623718/* Handle errors that occur when an attempt to queue a file fails. */
    624 SWFUpload.prototype.fileQueueError = function (file, errorCode, message) {
    625     file = this.unescapeFilePostParams(file);
    626     this.queueEvent("file_queue_error_handler", [file, errorCode, message]);
     719SWFUpload.prototype.fileQueueError = function (file, error_code, message) {
     720    var self = this;
     721    if (typeof(self.fileQueueError_handler) === "function") {
     722        this.eventQueue[this.eventQueue.length] = function() {  self.fileQueueError_handler(file, error_code, message); };
     723        setTimeout(function () { self.executeNextEvent();}, 0);
     724    } else {
     725        this.debug("fileQueueError event not defined");
     726    }
    627727};
    628728
    629729/* Called after the file dialog has closed and the selected files have been queued.
    630730    You could call startUpload here if you want the queued files to begin uploading immediately. */
    631 SWFUpload.prototype.fileDialogComplete = function (numFilesSelected, numFilesQueued) {
    632     this.queueEvent("file_dialog_complete_handler", [numFilesSelected, numFilesQueued]);
    633 };
    634 
     731SWFUpload.prototype.fileDialogComplete = function (num_files_selected) {
     732    var self = this;
     733    if (typeof(self.fileDialogComplete_handler) === "function") {
     734        this.eventQueue[this.eventQueue.length] = function() { self.fileDialogComplete_handler(num_files_selected); };
     735        setTimeout(function () { self.executeNextEvent();}, 0);
     736    } else {
     737        this.debug("fileDialogComplete event not defined");
     738    }
     739};
     740
     741/* Gets called when a file upload is about to be started.  Return true to continue the upload. Return false to stop the upload.
     742    If you return false then uploadError and uploadComplete are called (like normal).
     743   
     744    This is a good place to do any file validation you need.
     745    */
    635746SWFUpload.prototype.uploadStart = function (file) {
    636     file = this.unescapeFilePostParams(file);
    637     this.queueEvent("return_upload_start_handler", file);
    638 };
    639 
    640 SWFUpload.prototype.returnUploadStart = function (file) {
    641     var returnValue;
    642     if (typeof(this.settings.upload_start_handler) === "function") {
    643         file = this.unescapeFilePostParams(file);
    644         returnValue = this.settings.upload_start_handler.call(this, file);
    645     } else if (this.settings.upload_start_handler != undefined) {
    646         throw "upload_start_handler must be a function";
    647     }
    648 
    649     // Convert undefined to true so if nothing is returned from the upload_start_handler it is
    650     // interpretted as 'true'.
    651     if (returnValue === undefined) {
    652         returnValue = true;
    653     }
    654    
    655     returnValue = !!returnValue;
    656    
    657     this.callFlash("ReturnUploadStart", [returnValue]);
    658 };
    659 
    660 
    661 
    662 SWFUpload.prototype.uploadProgress = function (file, bytesComplete, bytesTotal) {
    663     file = this.unescapeFilePostParams(file);
    664     this.queueEvent("upload_progress_handler", [file, bytesComplete, bytesTotal]);
    665 };
    666 
    667 SWFUpload.prototype.uploadError = function (file, errorCode, message) {
    668     file = this.unescapeFilePostParams(file);
    669     this.queueEvent("upload_error_handler", [file, errorCode, message]);
    670 };
    671 
    672 SWFUpload.prototype.uploadSuccess = function (file, serverData) {
    673     file = this.unescapeFilePostParams(file);
    674     this.queueEvent("upload_success_handler", [file, serverData]);
    675 };
    676 
     747    var self = this;
     748    if (typeof(self.fileDialogComplete_handler) === "function") {
     749        this.eventQueue[this.eventQueue.length] = function() { self.returnUploadStart(self.uploadStart_handler(file)); };
     750        setTimeout(function () { self.executeNextEvent();}, 0);
     751    } else {
     752        this.debug("uploadStart event not defined");
     753    }
     754};
     755
     756/* Note: Internal use only.  This function returns the result of uploadStart to
     757    flash.  Since returning values in the normal way can result in Flash/JS circular
     758    call issues we split up the call in a Timeout.  This is transparent from the API
     759    point of view.
     760*/
     761SWFUpload.prototype.returnUploadStart = function (return_value) {
     762    var movie_element = this.getMovieElement();
     763    if (movie_element !== null && typeof(movie_element.ReturnUploadStart) === "function") {
     764        try {
     765            movie_element.ReturnUploadStart(return_value);
     766        }
     767        catch (ex) {
     768            this.debug("Could not call ReturnUploadStart");
     769        }
     770    } else {
     771        this.debug("Could not find Flash element in returnUploadStart");
     772    }
     773};
     774
     775
     776
     777/* Called during upload as the file progresses. Use this event to update your UI. */
     778SWFUpload.prototype.uploadProgress = function (file, bytes_complete, bytes_total) {
     779    var self = this;
     780    if (typeof(self.uploadProgress_handler) === "function") {
     781        this.eventQueue[this.eventQueue.length] = function() { self.uploadProgress_handler(file, bytes_complete, bytes_total); };
     782        setTimeout(function () { self.executeNextEvent();}, 0);
     783    } else {
     784        this.debug("uploadProgress event not defined");
     785    }
     786};
     787
     788/* Called when an error occurs during an upload. Use error_code and the SWFUpload.UPLOAD_ERROR constants to determine
     789   which error occurred. The uploadComplete event is called after an error code indicating that the next file is
     790   ready for upload.  For files cancelled out of order the uploadComplete event will not be called. */
     791SWFUpload.prototype.uploadError = function (file, error_code, message) {
     792    var self = this;
     793    if (typeof(this.uploadError_handler) === "function") {
     794        this.eventQueue[this.eventQueue.length] = function() { self.uploadError_handler(file, error_code, message); };
     795        setTimeout(function () { self.executeNextEvent();}, 0);
     796    } else {
     797        this.debug("uploadError event not defined");
     798    }
     799};
     800
     801/* This gets called when a file finishes uploading and the server-side upload script has completed and returned a 200
     802status code. Any text returned by the server is available in server_data.
     803**NOTE: The upload script MUST return some text or the uploadSuccess and uploadComplete events will not fire and the
     804upload will become 'stuck'. */
     805SWFUpload.prototype.uploadSuccess = function (file, server_data) {
     806    var self = this;
     807    if (typeof(self.uploadSuccess_handler) === "function") {
     808        this.eventQueue[this.eventQueue.length] = function() { self.uploadSuccess_handler(file, server_data); };
     809        setTimeout(function () { self.executeNextEvent();}, 0);
     810    } else {
     811        this.debug("uploadSuccess event not defined");
     812    }
     813};
     814
     815/* uploadComplete is called when the file is uploaded or an error occurred and SWFUpload is ready to make the next upload.
     816   If you want the next upload to start to automatically you can call startUpload() from this event. */
    677817SWFUpload.prototype.uploadComplete = function (file) {
    678     file = this.unescapeFilePostParams(file);
    679     this.queueEvent("upload_complete_handler", file);
     818    var self = this;
     819    if (typeof(self.uploadComplete_handler) === "function") {
     820        this.eventQueue[this.eventQueue.length] = function() { self.uploadComplete_handler(file); };
     821        setTimeout(function () { self.executeNextEvent();}, 0);
     822    } else {
     823        this.debug("uploadComplete event not defined");
     824    }
    680825};
    681826
     
    683828   internal debug console.  You can override this event and have messages written where you want. */
    684829SWFUpload.prototype.debug = function (message) {
    685     this.queueEvent("debug_handler", message);
    686 };
     830    var self = this;
     831    if (typeof(self.debug_handler) === "function") {
     832        this.eventQueue[this.eventQueue.length] = function() { self.debug_handler(message); };
     833        setTimeout(function () { self.executeNextEvent();}, 0);
     834    } else {
     835        this.eventQueue[this.eventQueue.length] = function() { self.debugMessage(message); };
     836        setTimeout(function () { self.executeNextEvent();}, 0);
     837    }
     838};
     839
     840
     841/* **********************************
     842    Default Event Handlers.
     843    These event handlers are used by default if an overriding handler is
     844    not defined in the SWFUpload settings object.
     845   
     846    JS Note: even though these are defined on the SWFUpload object (rather than the prototype) they
     847    are attached (read: copied) to a SWFUpload instance and 'this' is given the proper context.
     848   ********************************** */
     849
     850/* This is a special event handler that has no override in the settings.  Flash calls this when it has
     851   been loaded by the browser and is ready for interaction.  You should not override it.  If you need
     852   to do something with SWFUpload has loaded then use the swfupload_loaded_handler setting.
     853*/
     854SWFUpload.flashReady = function () {
     855    try {
     856        this.debug("Flash called back and is ready.");
     857
     858        if (typeof(this.swfUploadLoaded_handler) === "function") {
     859            this.swfUploadLoaded_handler();
     860        }
     861    } catch (ex) {
     862        this.debug(ex);
     863    }
     864};
     865
     866/* This is a chance to something immediately after SWFUpload has loaded.
     867   Like, hide the default/degraded upload form and display the SWFUpload form. */
     868SWFUpload.swfUploadLoaded = function () {
     869};
     870
     871/* This is a chance to do something before the browse window opens */
     872SWFUpload.fileDialogStart = function () {
     873};
     874
     875
     876/* Called when a file is successfully added to the queue. */
     877SWFUpload.fileQueued = function (file) {
     878};
     879
     880
     881/* Handle errors that occur when an attempt to queue a file fails. */
     882SWFUpload.fileQueueError = function (file, error_code, message) {
     883    try {
     884        switch (error_code) {
     885        case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
     886            this.debug("Error Code: File too big, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
     887            break;
     888        case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
     889            this.debug("Error Code: Zero Byte File, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
     890            break;
     891        case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
     892            this.debug("Error Code: Upload limit reached, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
     893            break;
     894        case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
     895            this.debug("Error Code: File extension is not allowed, Message: " + message);
     896            break;
     897        default:
     898            this.debug("Error Code: Unhandled error occured. Errorcode: " + error_code);
     899        }
     900    } catch (ex) {
     901        this.debug(ex);
     902    }
     903};
     904
     905/* Called after the file dialog has closed and the selected files have been queued.
     906    You could call startUpload here if you want the queued files to begin uploading immediately. */
     907SWFUpload.fileDialogComplete = function (num_files_selected) {
     908};
     909
     910/* Gets called when a file upload is about to be started.  Return true to continue the upload. Return false to stop the upload.
     911    If you return false then the uploadError callback is called and then uploadComplete (like normal).
     912   
     913    This is a good place to do any file validation you need.
     914   
     915    This is the only function that cannot be called on a setTimeout because it must return a value to Flash.
     916    You SHOULD NOT make any calls in to Flash (e.i, changing settings, getting stats, etc).  Flash Player bugs prevent
     917    calls in to Flash from working reliably.
     918*/
     919SWFUpload.uploadStart = function (file) {
     920    return true;
     921};
     922
     923// Called during upload as the file progresses
     924SWFUpload.uploadProgress = function (file, bytes_complete, bytes_total) {
     925    this.debug("File Progress: " + file.id + ", Bytes: " + bytes_complete + ". Total: " + bytes_total);
     926};
     927
     928/* 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
     929server is available in server_data.  The upload script must return some text or uploadSuccess will not fire (neither will uploadComplete). */
     930SWFUpload.uploadSuccess = function (file, server_data) {
     931    this.debug("Upload Success: " + file.id + ", Server: " + server_data);
     932};
     933
     934/* This is called last.  The file is uploaded or an error occurred and SWFUpload is ready to make the next upload.
     935    If you want to automatically start the next file just call startUpload from here.
     936*/
     937SWFUpload.uploadComplete = function (file) {
     938    this.debug("Upload Complete: " + file.id);
     939};
     940
     941// Called by SWFUpload JavaScript and Flash functions when debug is enabled.
     942// Override this method in your settings to call your own debug message handler
     943SWFUpload.debug = function (message) {
     944    if (this.getSetting("debug_enabled")) {
     945        this.debugMessage(message);
     946    }
     947};
     948
     949/* Called when an upload occurs during upload.  For HTTP errors 'message' will contain the HTTP STATUS CODE */
     950SWFUpload.uploadError = function (file, errcode, msg) {
     951    try {
     952        switch (errcode) {
     953        case SWFUpload.UPLOAD_ERROR.SPECIFIED_FILE_ID_NOT_FOUND:
     954            this.debug("Error Code: File ID specified for upload was not found, Message: " + msg);
     955            break;
     956        case SWFUpload.UPLOAD_ERROR.HTTP_ERROR:
     957            this.debug("Error Code: HTTP Error, File name: " + file.name + ", Message: " + msg);
     958            break;
     959        case SWFUpload.UPLOAD_ERROR.MISSING_UPLOAD_URL:
     960            this.debug("Error Code: No backend file, File name: " + file.name + ", Message: " + msg);
     961            break;
     962        case SWFUpload.UPLOAD_ERROR.IO_ERROR:
     963            this.debug("Error Code: IO Error, File name: " + file.name + ", Message: " + msg);
     964            break;
     965        case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR:
     966            this.debug("Error Code: Security Error, File name: " + file.name + ", Message: " + msg);
     967            break;
     968        case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
     969            this.debug("Error Code: Upload limit reached, File name: " + file.name + ", File size: " + file.size + ", Message: " + msg);
     970            break;
     971        case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED:
     972            this.debug("Error Code: Upload Initialization exception, File name: " + file.name + ", File size: " + file.size + ", Message: " + msg);
     973            break;
     974        case SWFUpload.UPLOAD_ERROR.FILE_VALIDATION_FAILED:
     975            this.debug("Error Code: uploadStart callback returned false, File name: " + file.name + ", File size: " + file.size + ", Message: " + msg);
     976            break;
     977        case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
     978            this.debug("Error Code: The file upload was cancelled, File name: " + file.name + ", File size: " + file.size + ", Message: " + msg);
     979            break;
     980        case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
     981            this.debug("Error Code: The file upload was stopped, File name: " + file.name + ", File size: " + file.size + ", Message: " + msg);
     982            break;
     983        default:
     984            this.debug("Error Code: Unhandled error occured. Errorcode: " + errcode);
     985        }
     986    } catch (ex) {
     987        this.debug(ex);
     988    }
     989};
     990
    687991
    688992
     
    695999    The console is automatically scrolled as messages appear.
    6961000   
    697     If you are using your own debug handler or when you deploy to production and
    698     have debug disabled you can remove these functions to reduce the file size
    699     and complexity.
    700 ********************************** */
    701    
    702 // Private: debugMessage is the default debug_handler.  If you want to print debug messages
    703 // call the debug() function.  When overriding the function your own function should
    704 // check to see if the debug setting is true before outputting debug information.
     1001    You can override this console (to use FireBug's console for instance) by setting the debug event method to your own function
     1002    that handles the debug message
     1003   ********************************** */
    7051004SWFUpload.prototype.debugMessage = function (message) {
    706     if (this.settings.debug) {
    707         var exceptionMessage, exceptionValues = [];
    708 
    709         // Check for an exception object and print it nicely
    710         if (typeof(message) === "object" && typeof(message.name) === "string" && typeof(message.message) === "string") {
    711             for (var key in message) {
    712                 if (message.hasOwnProperty(key)) {
    713                     exceptionValues.push(key + ": " + message[key]);
    714                 }
    715             }
    716             exceptionMessage = exceptionValues.join("\n") || "";
    717             exceptionValues = exceptionMessage.split("\n");
    718             exceptionMessage = "EXCEPTION: " + exceptionValues.join("\nEXCEPTION: ");
    719             SWFUpload.Console.writeLine(exceptionMessage);
    720         } else {
    721             SWFUpload.Console.writeLine(message);
    722         }
     1005    var exception_message, exception_values;
     1006
     1007    if (typeof(message) === "object" && typeof(message.name) === "string" && typeof(message.message) === "string") {
     1008        exception_message = "";
     1009        exception_values = [];
     1010        for (var key in message) {
     1011            exception_values.push(key + ": " + message[key]);
     1012        }
     1013        exception_message = exception_values.join("\n");
     1014        exception_values = exception_message.split("\n");
     1015        exception_message = "EXCEPTION: " + exception_values.join("\nEXCEPTION: ");
     1016        SWFUpload.Console.writeLine(exception_message);
     1017    } else {
     1018        SWFUpload.Console.writeLine(message);
    7231019    }
    7241020};
Note: See TracChangeset for help on using the changeset viewer.