2008-01-25 14:21:11 -05:00
/ * *
2008-06-06 03:34:30 -04:00
* SWFUpload v2 . 0 by Jacob Roberts , Nov 2007 , http : //www.swfupload.org, http://linebyline.blogspot.com
2008-01-25 14:21:11 -05:00
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
2008-06-06 03:34:30 -04:00
* SWFUpload is ( c ) 2006 Lars Huring and Mammon Media and is released under the MIT License :
2008-01-25 14:21:11 -05:00
* http : //www.opensource.org/licenses/mit-license.php
*
* See Changelog . txt for version history
*
2008-06-06 03:34:30 -04:00
* Development Notes :
* * This version of SWFUpload requires Flash Player 9.0 . 28 and should autodetect the correct flash version .
* * In Linux Flash Player 9 setting the post file variable name does not work . It is always set to "Filedata" .
* * There is a lot of repeated code that could be refactored to single functions . Feel free .
* * It 's dangerous to do "circular calls" between Flash and JavaScript. I' ve taken steps to try to work around issues
* by having the event calls pipe through setTimeout . However you should still avoid calling in to Flash from
* within the event handler methods . Especially the "startUpload" event since it cannot use the setTimeout hack .
2008-01-25 14:21:11 -05:00
* /
/* *********** */
/* Constructor */
/* *********** */
2008-06-06 03:34:30 -04:00
var SWFUpload = function ( init _settings ) {
this . initSWFUpload ( init _settings ) ;
2008-01-25 14:21:11 -05:00
} ;
2008-06-06 03:34:30 -04:00
SWFUpload . prototype . initSWFUpload = function ( init _settings ) {
// Remove background flicker in IE (read this: http://misterpixel.blogspot.com/2006/09/forensic-analysis-of-ie6.html)
// This doesn't have anything to do with SWFUpload but can help your UI behave better in IE.
try {
document . execCommand ( 'BackgroundImageCache' , false , true ) ;
} catch ( ex1 ) {
}
2008-01-25 14:21:11 -05:00
try {
this . customSettings = { } ; // A container where developers can place their own settings associated with this instance.
2008-06-06 03:34:30 -04:00
this . settings = { } ;
2008-01-25 14:21:11 -05:00
this . eventQueue = [ ] ;
this . movieName = "SWFUpload_" + SWFUpload . movieCount ++ ;
this . movieElement = null ;
// Setup global control tracking
SWFUpload . instances [ this . movieName ] = this ;
// Load the settings. Load the Flash movie.
2008-06-06 03:34:30 -04:00
this . initSettings ( init _settings ) ;
2008-01-25 14:21:11 -05:00
this . loadFlash ( ) ;
2008-06-06 03:34:30 -04:00
2008-01-25 14:21:11 -05:00
this . displayDebugInfo ( ) ;
2008-06-06 03:34:30 -04:00
} catch ( ex2 ) {
this . debug ( ex2 ) ;
2008-01-25 14:21:11 -05:00
}
2008-06-06 03:34:30 -04:00
}
2008-01-25 14:21:11 -05:00
/* *************** */
2008-06-06 03:34:30 -04:00
/* Static thingies */
2008-01-25 14:21:11 -05:00
/* *************** */
SWFUpload . instances = { } ;
SWFUpload . movieCount = 0 ;
SWFUpload . QUEUE _ERROR = {
QUEUE _LIMIT _EXCEEDED : - 100 ,
FILE _EXCEEDS _SIZE _LIMIT : - 110 ,
ZERO _BYTE _FILE : - 120 ,
INVALID _FILETYPE : - 130
} ;
SWFUpload . UPLOAD _ERROR = {
HTTP _ERROR : - 200 ,
MISSING _UPLOAD _URL : - 210 ,
IO _ERROR : - 220 ,
SECURITY _ERROR : - 230 ,
UPLOAD _LIMIT _EXCEEDED : - 240 ,
UPLOAD _FAILED : - 250 ,
SPECIFIED _FILE _ID _NOT _FOUND : - 260 ,
FILE _VALIDATION _FAILED : - 270 ,
FILE _CANCELLED : - 280 ,
UPLOAD _STOPPED : - 290
} ;
SWFUpload . FILE _STATUS = {
QUEUED : - 1 ,
IN _PROGRESS : - 2 ,
ERROR : - 3 ,
COMPLETE : - 4 ,
CANCELLED : - 5
} ;
2008-06-06 03:34:30 -04:00
/* ***************** */
/* Instance Thingies */
/* ***************** */
// init is a private method that ensures that all the object settings are set, getting a default value if one was not assigned.
2008-01-25 14:21:11 -05:00
2008-06-06 03:34:30 -04:00
SWFUpload . prototype . initSettings = function ( init _settings ) {
2008-01-25 14:21:11 -05:00
// Upload backend settings
2008-06-06 03:34:30 -04:00
this . addSetting ( "upload_url" , init _settings . upload _url , "" ) ;
this . addSetting ( "file_post_name" , init _settings . file _post _name , "Filedata" ) ;
this . addSetting ( "post_params" , init _settings . post _params , { } ) ;
2008-01-25 14:21:11 -05:00
// File Settings
2008-06-06 03:34:30 -04:00
this . addSetting ( "file_types" , init _settings . file _types , "*.*" ) ;
this . addSetting ( "file_types_description" , init _settings . file _types _description , "All Files" ) ;
this . addSetting ( "file_size_limit" , init _settings . file _size _limit , "1024" ) ;
this . addSetting ( "file_upload_limit" , init _settings . file _upload _limit , "0" ) ;
this . addSetting ( "file_queue_limit" , init _settings . file _queue _limit , "0" ) ;
2008-01-25 14:21:11 -05:00
// Flash Settings
2008-06-06 03:34:30 -04:00
this . addSetting ( "flash_url" , init _settings . flash _url , "swfupload.swf" ) ;
this . addSetting ( "flash_width" , init _settings . flash _width , "1px" ) ;
this . addSetting ( "flash_height" , init _settings . flash _height , "1px" ) ;
this . addSetting ( "flash_color" , init _settings . flash _color , "#FFFFFF" ) ;
2008-01-25 14:21:11 -05:00
// Debug Settings
2008-06-06 03:34:30 -04:00
this . addSetting ( "debug_enabled" , init _settings . debug , false ) ;
2008-01-25 14:21:11 -05:00
// Event Handlers
2008-06-06 03:34:30 -04:00
this . flashReady _handler = SWFUpload . flashReady ; // This is a non-overrideable event handler
this . swfUploadLoaded _handler = this . retrieveSetting ( init _settings . swfupload _loaded _handler , SWFUpload . swfUploadLoaded ) ;
2008-01-25 14:21:11 -05:00
2008-06-06 03:34:30 -04:00
this . fileDialogStart _handler = this . retrieveSetting ( init _settings . file _dialog _start _handler , SWFUpload . fileDialogStart ) ;
this . fileQueued _handler = this . retrieveSetting ( init _settings . file _queued _handler , SWFUpload . fileQueued ) ;
this . fileQueueError _handler = this . retrieveSetting ( init _settings . file _queue _error _handler , SWFUpload . fileQueueError ) ;
this . fileDialogComplete _handler = this . retrieveSetting ( init _settings . file _dialog _complete _handler , SWFUpload . fileDialogComplete ) ;
2008-01-25 14:21:11 -05:00
2008-06-06 03:34:30 -04:00
this . uploadStart _handler = this . retrieveSetting ( init _settings . upload _start _handler , SWFUpload . uploadStart ) ;
this . uploadProgress _handler = this . retrieveSetting ( init _settings . upload _progress _handler , SWFUpload . uploadProgress ) ;
this . uploadError _handler = this . retrieveSetting ( init _settings . upload _error _handler , SWFUpload . uploadError ) ;
this . uploadSuccess _handler = this . retrieveSetting ( init _settings . upload _success _handler , SWFUpload . uploadSuccess ) ;
this . uploadComplete _handler = this . retrieveSetting ( init _settings . upload _complete _handler , SWFUpload . uploadComplete ) ;
2008-01-25 14:21:11 -05:00
2008-06-06 03:34:30 -04:00
this . debug _handler = this . retrieveSetting ( init _settings . debug _handler , SWFUpload . debug ) ;
2008-01-25 14:21:11 -05:00
// Other settings
2008-06-06 03:34:30 -04:00
this . customSettings = this . retrieveSetting ( init _settings . custom _settings , { } ) ;
2008-01-25 14:21:11 -05:00
} ;
2008-06-06 03:34:30 -04:00
// loadFlash is a private method that generates the HTML tag for the Flash
// It then adds the flash to the "target" or to the body and stores a
// reference to the flash element in "movieElement".
2008-01-25 14:21:11 -05:00
SWFUpload . prototype . loadFlash = function ( ) {
2008-06-06 03:34:30 -04:00
var html , target _element , container ;
2008-01-25 14:21:11 -05:00
// Make sure an element with the ID we are going to use doesn't already exist
if ( document . getElementById ( this . movieName ) !== null ) {
2008-06-06 03:34:30 -04:00
return false ;
2008-01-25 14:21:11 -05:00
}
// Get the body tag where we will be adding the flash movie
2008-06-06 03:34:30 -04:00
try {
target _element = document . getElementsByTagName ( "body" ) [ 0 ] ;
if ( typeof ( target _element ) === "undefined" || target _element === null ) {
this . debug ( 'Could not find the BODY element. SWFUpload failed to load.' ) ;
return false ;
}
} catch ( ex ) {
return false ;
2008-01-25 14:21:11 -05:00
}
// Append the container and load the flash
container = document . createElement ( "div" ) ;
2008-06-06 03:34:30 -04:00
container . style . width = this . getSetting ( "flash_width" ) ;
container . style . height = this . getSetting ( "flash_height" ) ;
2008-01-25 14:21:11 -05:00
2008-06-06 03:34:30 -04:00
target _element . appendChild ( container ) ;
2008-01-25 14:21:11 -05:00
container . innerHTML = this . getFlashHTML ( ) ; // Using innerHTML is non-standard but the only sensible way to dynamically add Flash in IE (and maybe other browsers)
} ;
2008-06-06 03:34:30 -04:00
// Generates the embed/object tags needed to embed the flash in to the document
2008-01-25 14:21:11 -05:00
SWFUpload . prototype . getFlashHTML = function ( ) {
2008-06-06 03:34:30 -04:00
var html = "" ;
// Create Mozilla Embed HTML
if ( navigator . plugins && navigator . mimeTypes && navigator . mimeTypes . length ) {
// Build the basic embed html
html = '<embed type="application/x-shockwave-flash" src="' + this . getSetting ( "flash_url" ) + '" width="' + this . getSetting ( "flash_width" ) + '" height="' + this . getSetting ( "flash_height" ) + '"' ;
html += ' id="' + this . movieName + '" name="' + this . movieName + '" ' ;
html += 'bgcolor="' + this . getSetting ( "flash_color" ) + '" quality="high" menu="false" flashvars="' ;
html += this . getFlashVars ( ) ;
html += '" />' ;
// Create IE Object HTML
} else {
// Build the basic Object tag
html = '<object id="' + this . movieName + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + this . getSetting ( "flash_width" ) + '" height="' + this . getSetting ( "flash_height" ) + '">' ;
html += '<param name="movie" value="' + this . getSetting ( "flash_url" ) + '">' ;
html += '<param name="bgcolor" value="' + this . getSetting ( "flash_color" ) + '" />' ;
html += '<param name="quality" value="high" />' ;
html += '<param name="menu" value="false" />' ;
html += '<param name="flashvars" value="' + this . getFlashVars ( ) + '" />' ;
html += '</object>' ;
}
return html ;
} ;
// This private method builds the parameter string that will be passed
// to flash.
2008-01-25 14:21:11 -05:00
SWFUpload . prototype . getFlashVars = function ( ) {
// Build a string from the post param object
2008-06-06 03:34:30 -04:00
var param _string = this . buildParamString ( ) ;
2008-01-25 14:21:11 -05:00
// Build the parameter string
2008-06-06 03:34:30 -04:00
var html = "" ;
html += "movieName=" + encodeURIComponent ( this . movieName ) ;
html += "&uploadURL=" + encodeURIComponent ( this . getSetting ( "upload_url" ) ) ;
html += "¶ms=" + encodeURIComponent ( param _string ) ;
html += "&filePostName=" + encodeURIComponent ( this . getSetting ( "file_post_name" ) ) ;
html += "&fileTypes=" + encodeURIComponent ( this . getSetting ( "file_types" ) ) ;
html += "&fileTypesDescription=" + encodeURIComponent ( this . getSetting ( "file_types_description" ) ) ;
html += "&fileSizeLimit=" + encodeURIComponent ( this . getSetting ( "file_size_limit" ) ) ;
html += "&fileUploadLimit=" + encodeURIComponent ( this . getSetting ( "file_upload_limit" ) ) ;
html += "&fileQueueLimit=" + encodeURIComponent ( this . getSetting ( "file_queue_limit" ) ) ;
html += "&debugEnabled=" + encodeURIComponent ( this . getSetting ( "debug_enabled" ) ) ;
return html ;
} ;
2008-01-25 14:21:11 -05:00
SWFUpload . prototype . getMovieElement = function ( ) {
2008-06-06 03:34:30 -04:00
if ( typeof ( this . movieElement ) === "undefined" || this . movieElement === null ) {
2008-01-25 14:21:11 -05:00
this . movieElement = document . getElementById ( this . movieName ) ;
2008-06-06 03:34:30 -04:00
// 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)
// Removed because Revision 6 always adds the flash to the body (inside a containing div)
// 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
// and run this code to make the form's ID available from the window object so Flash and JavaScript can communicate.
//if (typeof(window[this.movieName]) === "undefined" || window[this.moveName] !== this.movieElement) {
// window[this.movieName] = this.movieElement;
//}
2008-06-06 03:29:15 -04:00
}
2008-06-06 03:34:30 -04:00
2008-01-25 14:21:11 -05:00
return this . movieElement ;
} ;
SWFUpload . prototype . buildParamString = function ( ) {
2008-06-06 03:34:30 -04:00
var post _params = this . getSetting ( "post_params" ) ;
var param _string _pairs = [ ] ;
var i , value , name ;
// Retrieve the user defined parameters
if ( typeof ( post _params ) === "object" ) {
for ( name in post _params ) {
if ( post _params . hasOwnProperty ( name ) ) {
if ( typeof ( post _params [ name ] ) === "string" ) {
param _string _pairs . push ( encodeURIComponent ( name ) + "=" + encodeURIComponent ( post _params [ name ] ) ) ;
2008-06-06 03:29:15 -04:00
}
}
}
2008-01-25 14:21:11 -05:00
}
2008-06-06 03:34:30 -04:00
return param _string _pairs . join ( "&" ) ;
2008-01-25 14:21:11 -05:00
} ;
2008-06-06 03:34:30 -04:00
// Saves a setting. If the value given is undefined or null then the default_value is used.
2008-06-06 03:29:15 -04:00
SWFUpload . prototype . addSetting = function ( name , value , default _value ) {
2008-06-06 03:34:30 -04:00
if ( typeof ( value ) === "undefined" || value === null ) {
this . settings [ name ] = default _value ;
} else {
this . settings [ name ] = value ;
2008-01-25 14:21:11 -05:00
}
2008-06-06 03:34:30 -04:00
return this . settings [ name ] ;
2008-01-25 14:21:11 -05:00
} ;
2008-06-06 03:34:30 -04:00
// Gets a setting. Returns empty string if not found.
2008-06-06 03:29:15 -04:00
SWFUpload . prototype . getSetting = function ( name ) {
2008-06-06 03:34:30 -04:00
if ( typeof ( this . settings [ name ] ) === "undefined" ) {
return "" ;
} else {
return this . settings [ name ] ;
2008-01-25 14:21:11 -05:00
}
2008-06-06 03:34:30 -04:00
} ;
2008-01-25 14:21:11 -05:00
2008-06-06 03:34:30 -04:00
// Gets a setting, if the setting is undefined then return the default value
// This does not affect or use the interal setting object.
SWFUpload . prototype . retrieveSetting = function ( value , default _value ) {
if ( typeof ( value ) === "undefined" || value === null ) {
return default _value ;
} else {
return value ;
}
2008-01-25 14:21:11 -05:00
} ;
2008-06-06 03:34:30 -04:00
// It loops through all the settings and displays
// them in the debug Console.
SWFUpload . prototype . displayDebugInfo = function ( ) {
var key , debug _message = "" ;
2008-06-06 03:29:15 -04:00
2008-06-06 03:34:30 -04:00
debug _message += "----- SWFUPLOAD SETTINGS ----\nID: " + this . moveName + "\n" ;
debug _message += this . outputObject ( this . settings ) ;
debug _message += "----- SWFUPLOAD SETTINGS END ----\n" ;
debug _message += "\n" ;
this . debug ( debug _message ) ;
} ;
SWFUpload . prototype . outputObject = function ( object , prefix ) {
var output = "" , key ;
if ( typeof ( prefix ) !== "string" ) {
prefix = "" ;
}
if ( typeof ( object ) !== "object" ) {
return "" ;
}
for ( key in object ) {
if ( object . hasOwnProperty ( key ) ) {
if ( typeof ( object [ key ] ) === "object" ) {
output += ( prefix + key + ": { \n" + this . outputObject ( object [ key ] , "\t" + prefix ) + prefix + "}" + "\n" ) ;
2008-01-25 14:21:11 -05:00
} else {
2008-06-06 03:34:30 -04:00
output += ( prefix + key + ": " + object [ key ] + "\n" ) ;
2008-01-25 14:21:11 -05:00
}
}
2008-06-06 03:34:30 -04:00
}
2008-01-25 14:21:11 -05:00
2008-06-06 03:34:30 -04:00
return output ;
} ;
2008-06-06 03:29:15 -04:00
2008-01-25 14:21:11 -05:00
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-- Flash control methods --
Your UI should use these
to operate SWFUpload
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
SWFUpload . prototype . selectFile = function ( ) {
2008-06-06 03:34:30 -04:00
var movie _element = this . getMovieElement ( ) ;
if ( movie _element !== null && typeof ( movie _element . SelectFile ) === "function" ) {
try {
movie _element . SelectFile ( ) ;
}
catch ( ex ) {
this . debug ( "Could not call SelectFile: " + ex ) ;
}
} else {
this . debug ( "Could not find Flash element" ) ;
}
2008-01-25 14:21:11 -05:00
} ;
SWFUpload . prototype . selectFiles = function ( ) {
2008-06-06 03:34:30 -04:00
var movie _element = this . getMovieElement ( ) ;
if ( movie _element !== null && typeof ( movie _element . SelectFiles ) === "function" ) {
try {
movie _element . SelectFiles ( ) ;
}
catch ( ex ) {
this . debug ( "Could not call SelectFiles: " + ex ) ;
}
} else {
this . debug ( "Could not find Flash element" ) ;
}
2008-01-25 14:21:11 -05:00
} ;
2008-06-06 03:34:30 -04:00
/ * S t a r t t h e u p l o a d . I f a f i l e _ i d i s s p e c i f i e d t h a t f i l e i s u p l o a d e d . O t h e r w i s e t h e f i r s t
* file in the queue is uploaded . If no files are in the queue then nothing happens .
* This call uses setTimeout since Flash will be calling back in to JavaScript
* /
SWFUpload . prototype . startUpload = function ( file _id ) {
var self = this ;
var movie _element = this . getMovieElement ( ) ;
if ( movie _element !== null && typeof ( movie _element . StartUpload ) === "function" ) {
setTimeout (
function ( ) {
try {
movie _element . StartUpload ( file _id ) ;
}
catch ( ex ) {
self . debug ( "Could not call StartUpload: " + ex ) ;
}
} , 0
) ;
} else {
this . debug ( "Could not find Flash element" ) ;
}
2008-01-25 14:21:11 -05:00
} ;
/* Cancels a the file upload. You must specify a file_id */
2008-06-06 03:34:30 -04:00
SWFUpload . prototype . cancelUpload = function ( file _id ) {
var movie _element = this . getMovieElement ( ) ;
if ( movie _element !== null && typeof ( movie _element . CancelUpload ) === "function" ) {
try {
movie _element . CancelUpload ( file _id ) ;
}
catch ( ex ) {
this . debug ( "Could not call CancelUpload: " + ex ) ;
}
} else {
this . debug ( "Could not find Flash element" ) ;
}
2008-01-25 14:21:11 -05:00
} ;
2008-06-06 03:34:30 -04:00
// Stops the current upload. The file is re-queued. If nothing is currently uploading then nothing happens.
2008-01-25 14:21:11 -05:00
SWFUpload . prototype . stopUpload = function ( ) {
2008-06-06 03:34:30 -04:00
var movie _element = this . getMovieElement ( ) ;
if ( movie _element !== null && typeof ( movie _element . StopUpload ) === "function" ) {
try {
movie _element . StopUpload ( ) ;
}
catch ( ex ) {
this . debug ( "Could not call StopUpload: " + ex ) ;
}
} else {
this . debug ( "Could not find Flash element" ) ;
}
2008-01-25 14:21:11 -05:00
} ;
/ * * * * * * * * * * * * * * * * * * * * * * * * *
* Settings methods
2008-06-06 03:34:30 -04:00
* These methods change the settings inside SWFUpload
* They shouldn ' t need to be called in a setTimeout since they
* should not call back from Flash to JavaScript ( except perhaps in a Debug call )
* and some need to return data so setTimeout won ' t work .
* /
2008-01-25 14:21:11 -05:00
2008-06-06 03:34:30 -04:00
/ * G e t s t h e f i l e s t a t i s t i c s o b j e c t . I t l o o k s l i k e t h i s ( w h e r e n = n u m b e r ) :
{
files _queued : n ,
complete _uploads : n ,
upload _errors : n ,
uploads _cancelled : n ,
queue _errors : n
}
* /
2008-01-25 14:21:11 -05:00
SWFUpload . prototype . getStats = function ( ) {
2008-06-06 03:34:30 -04:00
var movie _element = this . getMovieElement ( ) ;
if ( movie _element !== null && typeof ( movie _element . GetStats ) === "function" ) {
try {
return movie _element . GetStats ( ) ;
}
catch ( ex ) {
this . debug ( "Could not call GetStats" ) ;
}
} else {
this . debug ( "Could not find Flash element" ) ;
}
2008-01-25 14:21:11 -05:00
} ;
2008-06-06 03:34:30 -04:00
SWFUpload . prototype . setStats = function ( stats _object ) {
var movie _element = this . getMovieElement ( ) ;
if ( movie _element !== null && typeof ( movie _element . SetStats ) === "function" ) {
try {
movie _element . SetStats ( stats _object ) ;
}
catch ( ex ) {
this . debug ( "Could not call SetStats" ) ;
}
} else {
this . debug ( "Could not find Flash element" ) ;
}
2008-01-25 14:21:11 -05:00
} ;
2008-06-06 03:34:30 -04:00
SWFUpload . prototype . setCredentials = function ( name , password ) {
var movie _element = this . getMovieElement ( ) ;
if ( movie _element !== null && typeof ( movie _element . SetCredentials ) === "function" ) {
try {
return movie _element . SetCredentials ( name , password ) ;
}
catch ( ex ) {
this . debug ( "Could not call SetCredentials" ) ;
}
2008-01-25 14:21:11 -05:00
} else {
2008-06-06 03:34:30 -04:00
this . debug ( "Could not find Flash element" ) ;
2008-01-25 14:21:11 -05:00
}
} ;
2008-06-06 03:34:30 -04:00
SWFUpload . prototype . getFile = function ( file _id ) {
var movie _element = this . getMovieElement ( ) ;
if ( typeof ( file _id ) === "number" ) {
if ( movie _element !== null && typeof ( movie _element . GetFileByIndex ) === "function" ) {
try {
return movie _element . GetFileByIndex ( file _id ) ;
}
catch ( ex ) {
this . debug ( "Could not call GetFileByIndex" ) ;
}
} else {
this . debug ( "Could not find Flash element" ) ;
}
} else {
if ( movie _element !== null && typeof ( movie _element . GetFile ) === "function" ) {
try {
return movie _element . GetFile ( file _id ) ;
}
catch ( ex ) {
this . debug ( "Could not call GetFile" ) ;
}
} else {
this . debug ( "Could not find Flash element" ) ;
}
}
2008-06-06 03:29:15 -04:00
} ;
2008-01-25 14:21:11 -05:00
2008-06-06 03:34:30 -04:00
SWFUpload . prototype . addFileParam = function ( file _id , name , value ) {
var movie _element = this . getMovieElement ( ) ;
if ( movie _element !== null && typeof ( movie _element . AddFileParam ) === "function" ) {
try {
return movie _element . AddFileParam ( file _id , name , value ) ;
}
catch ( ex ) {
this . debug ( "Could not call AddFileParam" ) ;
}
} else {
this . debug ( "Could not find Flash element" ) ;
}
2008-01-25 14:21:11 -05:00
} ;
2008-06-06 03:34:30 -04:00
SWFUpload . prototype . removeFileParam = function ( file _id , name ) {
var movie _element = this . getMovieElement ( ) ;
if ( movie _element !== null && typeof ( movie _element . RemoveFileParam ) === "function" ) {
try {
return movie _element . RemoveFileParam ( file _id , name ) ;
}
catch ( ex ) {
this . debug ( "Could not call AddFileParam" ) ;
}
} else {
this . debug ( "Could not find Flash element" ) ;
}
2008-01-25 14:21:11 -05:00
} ;
2008-06-06 03:34:30 -04:00
SWFUpload . prototype . setUploadURL = function ( url ) {
var movie _element = this . getMovieElement ( ) ;
if ( movie _element !== null && typeof ( movie _element . SetUploadURL ) === "function" ) {
try {
this . addSetting ( "upload_url" , url ) ;
movie _element . SetUploadURL ( this . getSetting ( "upload_url" ) ) ;
}
catch ( ex ) {
this . debug ( "Could not call SetUploadURL" ) ;
}
} else {
this . debug ( "Could not find Flash element in setUploadURL" ) ;
}
2008-01-25 14:21:11 -05:00
} ;
2008-06-06 03:34:30 -04:00
SWFUpload . prototype . setPostParams = function ( param _object ) {
var movie _element = this . getMovieElement ( ) ;
if ( movie _element !== null && typeof ( movie _element . SetPostParams ) === "function" ) {
try {
this . addSetting ( "post_params" , param _object ) ;
movie _element . SetPostParams ( this . getSetting ( "post_params" ) ) ;
}
catch ( ex ) {
this . debug ( "Could not call SetPostParams" ) ;
}
} else {
this . debug ( "Could not find Flash element in SetPostParams" ) ;
}
2008-01-25 14:21:11 -05:00
} ;
2008-06-06 03:29:15 -04:00
SWFUpload . prototype . setFileTypes = function ( types , description ) {
2008-06-06 03:34:30 -04:00
var movie _element = this . getMovieElement ( ) ;
if ( movie _element !== null && typeof ( movie _element . SetFileTypes ) === "function" ) {
try {
this . addSetting ( "file_types" , types ) ;
this . addSetting ( "file_types_description" , description ) ;
movie _element . SetFileTypes ( this . getSetting ( "file_types" ) , this . getSetting ( "file_types_description" ) ) ;
}
catch ( ex ) {
this . debug ( "Could not call SetFileTypes" ) ;
}
} else {
this . debug ( "Could not find Flash element in SetFileTypes" ) ;
}
2008-01-25 14:21:11 -05:00
} ;
2008-06-06 03:34:30 -04:00
SWFUpload . prototype . setFileSizeLimit = function ( file _size _limit ) {
var movie _element = this . getMovieElement ( ) ;
if ( movie _element !== null && typeof ( movie _element . SetFileSizeLimit ) === "function" ) {
try {
this . addSetting ( "file_size_limit" , file _size _limit ) ;
movie _element . SetFileSizeLimit ( this . getSetting ( "file_size_limit" ) ) ;
}
catch ( ex ) {
this . debug ( "Could not call SetFileSizeLimit" ) ;
}
} else {
this . debug ( "Could not find Flash element in SetFileSizeLimit" ) ;
}
2008-01-25 14:21:11 -05:00
} ;
2008-06-06 03:34:30 -04:00
SWFUpload . prototype . setFileUploadLimit = function ( file _upload _limit ) {
var movie _element = this . getMovieElement ( ) ;
if ( movie _element !== null && typeof ( movie _element . SetFileUploadLimit ) === "function" ) {
try {
this . addSetting ( "file_upload_limit" , file _upload _limit ) ;
movie _element . SetFileUploadLimit ( this . getSetting ( "file_upload_limit" ) ) ;
}
catch ( ex ) {
this . debug ( "Could not call SetFileUploadLimit" ) ;
}
} else {
this . debug ( "Could not find Flash element in SetFileUploadLimit" ) ;
}
} ;
SWFUpload . prototype . setFileQueueLimit = function ( file _queue _limit ) {
var movie _element = this . getMovieElement ( ) ;
if ( movie _element !== null && typeof ( movie _element . SetFileQueueLimit ) === "function" ) {
try {
this . addSetting ( "file_queue_limit" , file _queue _limit ) ;
movie _element . SetFileQueueLimit ( this . getSetting ( "file_queue_limit" ) ) ;
}
catch ( ex ) {
this . debug ( "Could not call SetFileQueueLimit" ) ;
}
} else {
this . debug ( "Could not find Flash element in SetFileQueueLimit" ) ;
}
2008-01-25 14:21:11 -05:00
} ;
2008-06-06 03:34:30 -04:00
SWFUpload . prototype . setFilePostName = function ( file _post _name ) {
var movie _element = this . getMovieElement ( ) ;
if ( movie _element !== null && typeof ( movie _element . SetFilePostName ) === "function" ) {
try {
this . addSetting ( "file_post_name" , file _post _name ) ;
movie _element . SetFilePostName ( this . getSetting ( "file_post_name" ) ) ;
}
catch ( ex ) {
this . debug ( "Could not call SetFilePostName" ) ;
}
} else {
this . debug ( "Could not find Flash element in SetFilePostName" ) ;
}
2008-01-25 14:21:11 -05:00
} ;
2008-06-06 03:34:30 -04:00
SWFUpload . prototype . setDebugEnabled = function ( debug _enabled ) {
var movie _element = this . getMovieElement ( ) ;
if ( movie _element !== null && typeof ( movie _element . SetDebugEnabled ) === "function" ) {
try {
this . addSetting ( "debug_enabled" , debug _enabled ) ;
movie _element . SetDebugEnabled ( this . getSetting ( "debug_enabled" ) ) ;
}
catch ( ex ) {
this . debug ( "Could not call SetDebugEnabled" ) ;
}
} else {
this . debug ( "Could not find Flash element in SetDebugEnabled" ) ;
}
2008-01-25 14:21:11 -05:00
} ;
2008-06-06 03:34:30 -04:00
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Internal Event Callers
Don ' t override these ! These event callers ensure that your custom event handlers
are called safely and in order .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
/ * T h i s i s t h e c a l l b a c k m e t h o d t h a t t h e F l a s h m o v i e w i l l c a l l w h e n i t h a s b e e n l o a d e d a n d i s r e a d y t o g o .
Calling this or showUI ( ) "manually" will bypass the Flash Detection built in to SWFUpload .
Use a ui _function setting if you want to control the UI loading after the flash has loaded .
* /
SWFUpload . prototype . flashReady = function ( ) {
// Check that the movie element is loaded correctly with its ExternalInterface methods defined
var movie _element = this . getMovieElement ( ) ;
if ( movie _element === null || typeof ( movie _element . StartUpload ) !== "function" ) {
this . debug ( "ExternalInterface methods failed to initialize." ) ;
return ;
}
var self = this ;
if ( typeof ( self . flashReady _handler ) === "function" ) {
this . eventQueue [ this . eventQueue . length ] = function ( ) { self . flashReady _handler ( ) ; } ;
setTimeout ( function ( ) { self . executeNextEvent ( ) ; } , 0 ) ;
} else {
this . debug ( "flashReady_handler event not defined" ) ;
}
2008-01-25 14:21:11 -05:00
} ;
2008-06-06 03:34:30 -04:00
/ *
Event Queue . Rather can call events directly from Flash they events are
are placed in a queue and then executed . This ensures that each event is
executed in the order it was called which is not guarenteed when calling
setTimeout . Out of order events was especially problematic in Safari .
* /
SWFUpload . prototype . executeNextEvent = function ( ) {
var f = this . eventQueue . shift ( ) ;
if ( typeof ( f ) === "function" ) {
f ( ) ;
}
}
/* This is a chance to do something before the browse window opens */
SWFUpload . prototype . fileDialogStart = function ( ) {
var self = this ;
if ( typeof ( self . fileDialogStart _handler ) === "function" ) {
this . eventQueue [ this . eventQueue . length ] = function ( ) { self . fileDialogStart _handler ( ) ; } ;
setTimeout ( function ( ) { self . executeNextEvent ( ) ; } , 0 ) ;
} else {
this . debug ( "fileDialogStart event not defined" ) ;
}
2008-06-06 03:29:15 -04:00
} ;
2008-01-25 14:21:11 -05:00
2008-06-06 03:34:30 -04:00
/* Called when a file is successfully added to the queue. */
SWFUpload . prototype . fileQueued = function ( file ) {
var self = this ;
if ( typeof ( self . fileQueued _handler ) === "function" ) {
this . eventQueue [ this . eventQueue . length ] = function ( ) { self . fileQueued _handler ( file ) ; } ;
setTimeout ( function ( ) { self . executeNextEvent ( ) ; } , 0 ) ;
} else {
this . debug ( "fileQueued event not defined" ) ;
}
2008-01-25 14:21:11 -05:00
} ;
2008-06-06 03:34:30 -04:00
/* Handle errors that occur when an attempt to queue a file fails. */
SWFUpload . prototype . fileQueueError = function ( file , error _code , message ) {
var self = this ;
if ( typeof ( self . fileQueueError _handler ) === "function" ) {
this . eventQueue [ this . eventQueue . length ] = function ( ) { self . fileQueueError _handler ( file , error _code , message ) ; } ;
setTimeout ( function ( ) { self . executeNextEvent ( ) ; } , 0 ) ;
} else {
this . debug ( "fileQueueError event not defined" ) ;
}
} ;
2008-01-25 14:21:11 -05:00
2008-06-06 03:34:30 -04:00
/ * C a l l e d a f t e r t h e f i l e d i a l o g h a s c l o s e d a n d t h e s e l e c t e d f i l e s h a v e b e e n q u e u e d .
You could call startUpload here if you want the queued files to begin uploading immediately . * /
SWFUpload . prototype . fileDialogComplete = function ( num _files _selected ) {
var self = this ;
if ( typeof ( self . fileDialogComplete _handler ) === "function" ) {
this . eventQueue [ this . eventQueue . length ] = function ( ) { self . fileDialogComplete _handler ( num _files _selected ) ; } ;
setTimeout ( function ( ) { self . executeNextEvent ( ) ; } , 0 ) ;
} else {
this . debug ( "fileDialogComplete event not defined" ) ;
2008-01-25 14:21:11 -05:00
}
2008-06-06 03:34:30 -04:00
} ;
/ * G e t s c a l l e d w h e n a f i l e u p l o a d i s a b o u t t o b e s t a r t e d . R e t u r n t r u e t o c o n t i n u e t h e u p l o a d . R e t u r n f a l s e t o s t o p t h e u p l o a d .
If you return false then uploadError and uploadComplete are called ( like normal ) .
2008-01-25 14:21:11 -05:00
2008-06-06 03:34:30 -04:00
This is a good place to do any file validation you need .
* /
SWFUpload . prototype . uploadStart = function ( file ) {
2008-01-25 14:21:11 -05:00
var self = this ;
2008-06-06 03:34:30 -04:00
if ( typeof ( self . fileDialogComplete _handler ) === "function" ) {
this . eventQueue [ this . eventQueue . length ] = function ( ) { self . returnUploadStart ( self . uploadStart _handler ( file ) ) ; } ;
setTimeout ( function ( ) { self . executeNextEvent ( ) ; } , 0 ) ;
} else {
this . debug ( "uploadStart event not defined" ) ;
}
} ;
2008-01-25 14:21:11 -05:00
2008-06-06 03:34:30 -04:00
/ * N o t e : I n t e r n a l u s e o n l y . T h i s f u n c t i o n r e t u r n s t h e r e s u l t o f u p l o a d S t a r t t o
flash . Since returning values in the normal way can result in Flash / JS circular
call issues we split up the call in a Timeout . This is transparent from the API
point of view .
* /
SWFUpload . prototype . returnUploadStart = function ( return _value ) {
var movie _element = this . getMovieElement ( ) ;
if ( movie _element !== null && typeof ( movie _element . ReturnUploadStart ) === "function" ) {
try {
movie _element . ReturnUploadStart ( return _value ) ;
}
catch ( ex ) {
this . debug ( "Could not call ReturnUploadStart" ) ;
}
} else {
this . debug ( "Could not find Flash element in returnUploadStart" ) ;
2008-01-25 14:21:11 -05:00
}
} ;
2008-06-06 03:34:30 -04:00
/* Called during upload as the file progresses. Use this event to update your UI. */
SWFUpload . prototype . uploadProgress = function ( file , bytes _complete , bytes _total ) {
var self = this ;
if ( typeof ( self . uploadProgress _handler ) === "function" ) {
this . eventQueue [ this . eventQueue . length ] = function ( ) { self . uploadProgress _handler ( file , bytes _complete , bytes _total ) ; } ;
setTimeout ( function ( ) { self . executeNextEvent ( ) ; } , 0 ) ;
} else {
this . debug ( "uploadProgress event not defined" ) ;
2008-01-25 14:21:11 -05:00
}
2008-06-06 03:34:30 -04:00
} ;
2008-01-25 14:21:11 -05:00
2008-06-06 03:34:30 -04:00
/ * C a l l e d w h e n a n e r r o r o c c u r s d u r i n g a n u p l o a d . U s e e r r o r _ c o d e a n d t h e S W F U p l o a d . U P L O A D _ E R R O R c o n s t a n t s t o d e t e r m i n e
which error occurred . The uploadComplete event is called after an error code indicating that the next file is
ready for upload . For files cancelled out of order the uploadComplete event will not be called . * /
SWFUpload . prototype . uploadError = function ( file , error _code , message ) {
var self = this ;
if ( typeof ( this . uploadError _handler ) === "function" ) {
this . eventQueue [ this . eventQueue . length ] = function ( ) { self . uploadError _handler ( file , error _code , message ) ; } ;
setTimeout ( function ( ) { self . executeNextEvent ( ) ; } , 0 ) ;
} else {
this . debug ( "uploadError event not defined" ) ;
}
2008-01-25 14:21:11 -05:00
} ;
2008-06-06 03:34:30 -04:00
/ * T h i s g e t s c a l l e d w h e n a f i l e f i n i s h e s u p l o a d i n g a n d t h e s e r v e r - s i d e u p l o a d s c r i p t h a s c o m p l e t e d a n d r e t u r n e d a 2 0 0
status code . Any text returned by the server is available in server _data .
* * NOTE : The upload script MUST return some text or the uploadSuccess and uploadComplete events will not fire and the
upload will become 'stuck' . * /
SWFUpload . prototype . uploadSuccess = function ( file , server _data ) {
var self = this ;
if ( typeof ( self . uploadSuccess _handler ) === "function" ) {
this . eventQueue [ this . eventQueue . length ] = function ( ) { self . uploadSuccess _handler ( file , server _data ) ; } ;
setTimeout ( function ( ) { self . executeNextEvent ( ) ; } , 0 ) ;
} else {
this . debug ( "uploadSuccess event not defined" ) ;
}
} ;
/ * u p l o a d C o m p l e t e i s c a l l e d w h e n t h e f i l e i s u p l o a d e d o r a n e r r o r o c c u r r e d a n d S W F U p l o a d i s r e a d y t o m a k e t h e n e x t u p l o a d .
If you want the next upload to start to automatically you can call startUpload ( ) from this event . * /
SWFUpload . prototype . uploadComplete = function ( file ) {
var self = this ;
if ( typeof ( self . uploadComplete _handler ) === "function" ) {
this . eventQueue [ this . eventQueue . length ] = function ( ) { self . uploadComplete _handler ( file ) ; } ;
setTimeout ( function ( ) { self . executeNextEvent ( ) ; } , 0 ) ;
} else {
this . debug ( "uploadComplete event not defined" ) ;
2008-01-25 14:21:11 -05:00
}
2008-06-06 03:34:30 -04:00
} ;
/ * C a l l e d b y S W F U p l o a d J a v a S c r i p t a n d F l a s h f u n c t i o n s w h e n d e b u g i s e n a b l e d . B y d e f a u l t i t w r i t e s m e s s a g e s t o t h e
internal debug console . You can override this event and have messages written where you want . * /
SWFUpload . prototype . debug = function ( message ) {
var self = this ;
if ( typeof ( self . debug _handler ) === "function" ) {
this . eventQueue [ this . eventQueue . length ] = function ( ) { self . debug _handler ( message ) ; } ;
setTimeout ( function ( ) { self . executeNextEvent ( ) ; } , 0 ) ;
} else {
this . eventQueue [ this . eventQueue . length ] = function ( ) { self . debugMessage ( message ) ; } ;
setTimeout ( function ( ) { self . executeNextEvent ( ) ; } , 0 ) ;
}
} ;
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Default Event Handlers .
These event handlers are used by default if an overriding handler is
not defined in the SWFUpload settings object .
2008-01-25 14:21:11 -05:00
2008-06-06 03:34:30 -04:00
JS Note : even though these are defined on the SWFUpload object ( rather than the prototype ) they
are attached ( read : copied ) to a SWFUpload instance and 'this' is given the proper context .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
/ * T h i s i s a s p e c i a l e v e n t h a n d l e r t h a t h a s n o o v e r r i d e i n t h e s e t t i n g s . F l a s h c a l l s t h i s w h e n i t h a s
been loaded by the browser and is ready for interaction . You should not override it . If you need
to do something with SWFUpload has loaded then use the swfupload _loaded _handler setting .
* /
SWFUpload . flashReady = function ( ) {
try {
this . debug ( "Flash called back and is ready." ) ;
if ( typeof ( this . swfUploadLoaded _handler ) === "function" ) {
this . swfUploadLoaded _handler ( ) ;
}
} catch ( ex ) {
this . debug ( ex ) ;
}
2008-01-25 14:21:11 -05:00
} ;
2008-06-06 03:34:30 -04:00
/ * T h i s i s a c h a n c e t o s o m e t h i n g i m m e d i a t e l y a f t e r S W F U p l o a d h a s l o a d e d .
Like , hide the default /degraded upload form and display the SWFUpload form. */
SWFUpload . swfUploadLoaded = function ( ) {
} ;
2008-01-25 14:21:11 -05:00
/* This is a chance to do something before the browse window opens */
2008-06-06 03:34:30 -04:00
SWFUpload . fileDialogStart = function ( ) {
2008-01-25 14:21:11 -05:00
} ;
/* Called when a file is successfully added to the queue. */
2008-06-06 03:34:30 -04:00
SWFUpload . fileQueued = function ( file ) {
2008-01-25 14:21:11 -05:00
} ;
/* Handle errors that occur when an attempt to queue a file fails. */
2008-06-06 03:34:30 -04:00
SWFUpload . fileQueueError = function ( file , error _code , message ) {
try {
switch ( error _code ) {
case SWFUpload . QUEUE _ERROR . FILE _EXCEEDS _SIZE _LIMIT :
this . debug ( "Error Code: File too big, File name: " + file . name + ", File size: " + file . size + ", Message: " + message ) ;
break ;
case SWFUpload . QUEUE _ERROR . ZERO _BYTE _FILE :
this . debug ( "Error Code: Zero Byte File, File name: " + file . name + ", File size: " + file . size + ", Message: " + message ) ;
break ;
case SWFUpload . QUEUE _ERROR . QUEUE _LIMIT _EXCEEDED :
this . debug ( "Error Code: Upload limit reached, File name: " + file . name + ", File size: " + file . size + ", Message: " + message ) ;
break ;
case SWFUpload . QUEUE _ERROR . INVALID _FILETYPE :
this . debug ( "Error Code: File extension is not allowed, Message: " + message ) ;
break ;
default :
this . debug ( "Error Code: Unhandled error occured. Errorcode: " + error _code ) ;
}
} catch ( ex ) {
this . debug ( ex ) ;
}
2008-01-25 14:21:11 -05:00
} ;
/ * C a l l e d a f t e r t h e f i l e d i a l o g h a s c l o s e d a n d t h e s e l e c t e d f i l e s h a v e b e e n q u e u e d .
You could call startUpload here if you want the queued files to begin uploading immediately . * /
2008-06-06 03:34:30 -04:00
SWFUpload . fileDialogComplete = function ( num _files _selected ) {
2008-01-25 14:21:11 -05:00
} ;
2008-06-06 03:34:30 -04:00
/ * G e t s c a l l e d w h e n a f i l e u p l o a d i s a b o u t t o b e s t a r t e d . R e t u r n t r u e t o c o n t i n u e t h e u p l o a d . R e t u r n f a l s e t o s t o p t h e u p l o a d .
If you return false then the uploadError callback is called and then uploadComplete ( like normal ) .
2008-01-25 14:21:11 -05:00
2008-06-06 03:34:30 -04:00
This is a good place to do any file validation you need .
2008-01-25 14:21:11 -05:00
2008-06-06 03:34:30 -04:00
This is the only function that cannot be called on a setTimeout because it must return a value to Flash .
You SHOULD NOT make any calls in to Flash ( e . i , changing settings , getting stats , etc ) . Flash Player bugs prevent
calls in to Flash from working reliably .
* /
SWFUpload . uploadStart = function ( file ) {
return true ;
2008-01-25 14:21:11 -05:00
} ;
2008-06-06 03:34:30 -04:00
// Called during upload as the file progresses
SWFUpload . uploadProgress = function ( file , bytes _complete , bytes _total ) {
this . debug ( "File Progress: " + file . id + ", Bytes: " + bytes _complete + ". Total: " + bytes _total ) ;
2008-01-25 14:21:11 -05:00
} ;
2008-06-06 03:34:30 -04:00
/ * T h i s g e t s c a l l e d w h e n a f i l e f i n i s h e s u p l o a d i n g a n d t h e u p l o a d s c r i p t h a s c o m p l e t e d a n d r e t u r n e d a 2 0 0 s t a t u s c o d e . A n y t e x t r e t u r n e d b y t h e
server is available in server _data . The upload script must return some text or uploadSuccess will not fire ( neither will uploadComplete ) . * /
SWFUpload . uploadSuccess = function ( file , server _data ) {
this . debug ( "Upload Success: " + file . id + ", Server: " + server _data ) ;
2008-01-25 14:21:11 -05:00
} ;
2008-06-06 03:34:30 -04:00
/ * T h i s i s c a l l e d l a s t . T h e f i l e i s u p l o a d e d o r a n e r r o r o c c u r r e d a n d S W F U p l o a d i s r e a d y t o m a k e t h e n e x t u p l o a d .
If you want to automatically start the next file just call startUpload from here .
* /
SWFUpload . uploadComplete = function ( file ) {
this . debug ( "Upload Complete: " + file . id ) ;
2008-01-25 14:21:11 -05:00
} ;
2008-06-06 03:34:30 -04:00
// Called by SWFUpload JavaScript and Flash functions when debug is enabled.
// Override this method in your settings to call your own debug message handler
SWFUpload . debug = function ( message ) {
if ( this . getSetting ( "debug_enabled" ) ) {
this . debugMessage ( message ) ;
}
2008-01-25 14:21:11 -05:00
} ;
2008-06-06 03:34:30 -04:00
/* Called when an upload occurs during upload. For HTTP errors 'message' will contain the HTTP STATUS CODE */
SWFUpload . uploadError = function ( file , errcode , msg ) {
try {
switch ( errcode ) {
case SWFUpload . UPLOAD _ERROR . SPECIFIED _FILE _ID _NOT _FOUND :
this . debug ( "Error Code: File ID specified for upload was not found, Message: " + msg ) ;
break ;
case SWFUpload . UPLOAD _ERROR . HTTP _ERROR :
this . debug ( "Error Code: HTTP Error, File name: " + file . name + ", Message: " + msg ) ;
break ;
case SWFUpload . UPLOAD _ERROR . MISSING _UPLOAD _URL :
this . debug ( "Error Code: No backend file, File name: " + file . name + ", Message: " + msg ) ;
break ;
case SWFUpload . UPLOAD _ERROR . IO _ERROR :
this . debug ( "Error Code: IO Error, File name: " + file . name + ", Message: " + msg ) ;
break ;
case SWFUpload . UPLOAD _ERROR . SECURITY _ERROR :
this . debug ( "Error Code: Security Error, File name: " + file . name + ", Message: " + msg ) ;
break ;
case SWFUpload . UPLOAD _ERROR . UPLOAD _LIMIT _EXCEEDED :
this . debug ( "Error Code: Upload limit reached, File name: " + file . name + ", File size: " + file . size + ", Message: " + msg ) ;
break ;
case SWFUpload . UPLOAD _ERROR . UPLOAD _FAILED :
this . debug ( "Error Code: Upload Initialization exception, File name: " + file . name + ", File size: " + file . size + ", Message: " + msg ) ;
break ;
case SWFUpload . UPLOAD _ERROR . FILE _VALIDATION _FAILED :
this . debug ( "Error Code: uploadStart callback returned false, File name: " + file . name + ", File size: " + file . size + ", Message: " + msg ) ;
break ;
case SWFUpload . UPLOAD _ERROR . FILE _CANCELLED :
this . debug ( "Error Code: The file upload was cancelled, File name: " + file . name + ", File size: " + file . size + ", Message: " + msg ) ;
break ;
case SWFUpload . UPLOAD _ERROR . UPLOAD _STOPPED :
this . debug ( "Error Code: The file upload was stopped, File name: " + file . name + ", File size: " + file . size + ", Message: " + msg ) ;
break ;
default :
this . debug ( "Error Code: Unhandled error occured. Errorcode: " + errcode ) ;
}
} catch ( ex ) {
this . debug ( ex ) ;
}
2008-06-06 03:29:15 -04:00
} ;
2008-01-25 14:21:11 -05:00
2008-06-06 03:34:30 -04:00
2008-01-25 14:21:11 -05:00
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Debug Console
The debug console is a self contained , in page location
for debug message to be sent . The Debug Console adds
itself to the body if necessary .
The console is automatically scrolled as messages appear .
2008-06-06 03:34:30 -04:00
You can override this console ( to use FireBug ' s console for instance ) by setting the debug event method to your own function
that handles the debug message
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
2008-01-25 14:21:11 -05:00
SWFUpload . prototype . debugMessage = function ( message ) {
2008-06-06 03:34:30 -04:00
var exception _message , exception _values ;
if ( typeof ( message ) === "object" && typeof ( message . name ) === "string" && typeof ( message . message ) === "string" ) {
exception _message = "" ;
exception _values = [ ] ;
for ( var key in message ) {
exception _values . push ( key + ": " + message [ key ] ) ;
2008-01-25 14:21:11 -05:00
}
2008-06-06 03:34:30 -04:00
exception _message = exception _values . join ( "\n" ) ;
exception _values = exception _message . split ( "\n" ) ;
exception _message = "EXCEPTION: " + exception _values . join ( "\nEXCEPTION: " ) ;
SWFUpload . Console . writeLine ( exception _message ) ;
} else {
SWFUpload . Console . writeLine ( message ) ;
2008-01-25 14:21:11 -05:00
}
} ;
SWFUpload . Console = { } ;
SWFUpload . Console . writeLine = function ( message ) {
var console , documentForm ;
try {
console = document . getElementById ( "SWFUpload_Console" ) ;
if ( ! console ) {
documentForm = document . createElement ( "form" ) ;
document . getElementsByTagName ( "body" ) [ 0 ] . appendChild ( documentForm ) ;
console = document . createElement ( "textarea" ) ;
console . id = "SWFUpload_Console" ;
console . style . fontFamily = "monospace" ;
console . setAttribute ( "wrap" , "off" ) ;
console . wrap = "off" ;
console . style . overflow = "auto" ;
console . style . width = "700px" ;
console . style . height = "350px" ;
console . style . margin = "5px" ;
documentForm . appendChild ( console ) ;
}
console . value += message + "\n" ;
console . scrollTop = console . scrollHeight - console . clientHeight ;
} catch ( ex ) {
alert ( "Exception: " + ex . name + " Message: " + ex . message ) ;
}
} ;