PageRenderTime 43ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/admin/template/js/uploadify/jquery.uploadify.js

http://get-simple-cms.googlecode.com/
JavaScript | 677 lines | 567 code | 39 blank | 71 comment | 110 complexity | 19e9a5cea70d2814368a17708a8496f3 MD5 | raw file
Possible License(s): GPL-3.0
  1. /*
  2. SWFUpload: http://www.swfupload.org, http://swfupload.googlecode.com
  3. mmSWFUpload 1.0: Flash upload dialog - http://profandesign.se/swfupload/, http://www.vinterwebb.se/
  4. SWFUpload is (c) 2006-2007 Lars Huring, Olov Nilz?Šn and Mammon Media and is released under the MIT License:
  5. http://www.opensource.org/licenses/mit-license.php
  6. SWFUpload 2 is (c) 2007-2008 Jake Roberts and is released under the MIT License:
  7. http://www.opensource.org/licenses/mit-license.php
  8. */
  9. var SWFUpload;if(SWFUpload==undefined){SWFUpload=function(a){this.initSWFUpload(a)}}SWFUpload.prototype.initSWFUpload=function(b){try{this.customSettings={};this.settings=b;this.eventQueue=[];this.movieName="SWFUpload_"+SWFUpload.movieCount++;this.movieElement=null;SWFUpload.instances[this.movieName]=this;this.initSettings();this.loadFlash();this.displayDebugInfo()}catch(a){delete SWFUpload.instances[this.movieName];throw a}};SWFUpload.instances={};SWFUpload.movieCount=0;SWFUpload.version="2.2.0 2009-03-25";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};SWFUpload.BUTTON_ACTION={SELECT_FILE:-100,SELECT_FILES:-110,START_UPLOAD:-120};SWFUpload.CURSOR={ARROW:-1,HAND:-2};SWFUpload.WINDOW_MODE={WINDOW:"window",TRANSPARENT:"transparent",OPAQUE:"opaque"};SWFUpload.completeURL=function(a){if(typeof(a)!=="string"||a.match(/^https?:\/\//i)||a.match(/^\//)){return a}var c=window.location.protocol+"//"+window.location.hostname+(window.location.port?":"+window.location.port:"");var b=window.location.pathname.lastIndexOf("/");if(b<=0){path="/"}else{path=window.location.pathname.substr(0,b)+"/"}return path+a};SWFUpload.prototype.initSettings=function(){this.ensureDefault=function(b,a){this.settings[b]=(this.settings[b]==undefined)?a:this.settings[b]};this.ensureDefault("upload_url","");this.ensureDefault("preserve_relative_urls",false);this.ensureDefault("file_post_name","Filedata");this.ensureDefault("post_params",{});this.ensureDefault("use_query_string",false);this.ensureDefault("requeue_on_error",false);this.ensureDefault("http_success",[]);this.ensureDefault("assume_success_timeout",0);this.ensureDefault("file_types","*.*");this.ensureDefault("file_types_description","All Files");this.ensureDefault("file_size_limit",0);this.ensureDefault("file_upload_limit",0);this.ensureDefault("file_queue_limit",0);this.ensureDefault("flash_url","swfupload.swf");this.ensureDefault("prevent_swf_caching",true);this.ensureDefault("button_image_url","");this.ensureDefault("button_width",1);this.ensureDefault("button_height",1);this.ensureDefault("button_text","");this.ensureDefault("button_text_style","color: #000000; font-size: 16pt;");this.ensureDefault("button_text_top_padding",0);this.ensureDefault("button_text_left_padding",0);this.ensureDefault("button_action",SWFUpload.BUTTON_ACTION.SELECT_FILES);this.ensureDefault("button_disabled",false);this.ensureDefault("button_placeholder_id","");this.ensureDefault("button_placeholder",null);this.ensureDefault("button_cursor",SWFUpload.CURSOR.ARROW);this.ensureDefault("button_window_mode",SWFUpload.WINDOW_MODE.WINDOW);this.ensureDefault("debug",false);this.settings.debug_enabled=this.settings.debug;this.settings.return_upload_start_handler=this.returnUploadStart;this.ensureDefault("swfupload_loaded_handler",null);this.ensureDefault("file_dialog_start_handler",null);this.ensureDefault("file_queued_handler",null);this.ensureDefault("file_queue_error_handler",null);this.ensureDefault("file_dialog_complete_handler",null);this.ensureDefault("upload_start_handler",null);this.ensureDefault("upload_progress_handler",null);this.ensureDefault("upload_error_handler",null);this.ensureDefault("upload_success_handler",null);this.ensureDefault("upload_complete_handler",null);this.ensureDefault("debug_handler",this.debugMessage);this.ensureDefault("custom_settings",{});this.customSettings=this.settings.custom_settings;if(!!this.settings.prevent_swf_caching){this.settings.flash_url=this.settings.flash_url+(this.settings.flash_url.indexOf("?")<0?"?":"&")+"preventswfcaching="+new Date().getTime()}if(!this.settings.preserve_relative_urls){this.settings.upload_url=SWFUpload.completeURL(this.settings.upload_url);this.settings.button_image_url=SWFUpload.completeURL(this.settings.button_image_url)}delete this.ensureDefault};SWFUpload.prototype.loadFlash=function(){var a,b;if(document.getElementById(this.movieName)!==null){throw"ID "+this.movieName+" is already in use. The Flash Object could not be added"}a=document.getElementById(this.settings.button_placeholder_id)||this.settings.button_placeholder;if(a==undefined){throw"Could not find the placeholder element: "+this.settings.button_placeholder_id}b=document.createElement("div");b.innerHTML=this.getFlashHTML();a.parentNode.replaceChild(b.firstChild,a);if(window[this.movieName]==undefined){window[this.movieName]=this.getMovieElement()}};SWFUpload.prototype.getFlashHTML=function(){return['<object id="',this.movieName,'" type="application/x-shockwave-flash" data="',this.settings.flash_url,'" width="',this.settings.button_width,'" height="',this.settings.button_height,'" class="swfupload">','<param name="wmode" value="',this.settings.button_window_mode,'" />','<param name="movie" value="',this.settings.flash_url,'" />','<param name="quality" value="high" />','<param name="menu" value="false" />','<param name="allowScriptAccess" value="always" />','<param name="flashvars" value="'+this.getFlashVars()+'" />',"</object>"].join("")};SWFUpload.prototype.getFlashVars=function(){var b=this.buildParamString();var a=this.settings.http_success.join(",");return["movieName=",encodeURIComponent(this.movieName),"&amp;uploadURL=",encodeURIComponent(this.settings.upload_url),"&amp;useQueryString=",encodeURIComponent(this.settings.use_query_string),"&amp;requeueOnError=",encodeURIComponent(this.settings.requeue_on_error),"&amp;httpSuccess=",encodeURIComponent(a),"&amp;assumeSuccessTimeout=",encodeURIComponent(this.settings.assume_success_timeout),"&amp;params=",encodeURIComponent(b),"&amp;filePostName=",encodeURIComponent(this.settings.file_post_name),"&amp;fileTypes=",encodeURIComponent(this.settings.file_types),"&amp;fileTypesDescription=",encodeURIComponent(this.settings.file_types_description),"&amp;fileSizeLimit=",encodeURIComponent(this.settings.file_size_limit),"&amp;fileUploadLimit=",encodeURIComponent(this.settings.file_upload_limit),"&amp;fileQueueLimit=",encodeURIComponent(this.settings.file_queue_limit),"&amp;debugEnabled=",encodeURIComponent(this.settings.debug_enabled),"&amp;buttonImageURL=",encodeURIComponent(this.settings.button_image_url),"&amp;buttonWidth=",encodeURIComponent(this.settings.button_width),"&amp;buttonHeight=",encodeURIComponent(this.settings.button_height),"&amp;buttonText=",encodeURIComponent(this.settings.button_text),"&amp;buttonTextTopPadding=",encodeURIComponent(this.settings.button_text_top_padding),"&amp;buttonTextLeftPadding=",encodeURIComponent(this.settings.button_text_left_padding),"&amp;buttonTextStyle=",encodeURIComponent(this.settings.button_text_style),"&amp;buttonAction=",encodeURIComponent(this.settings.button_action),"&amp;buttonDisabled=",encodeURIComponent(this.settings.button_disabled),"&amp;buttonCursor=",encodeURIComponent(this.settings.button_cursor)].join("")};SWFUpload.prototype.getMovieElement=function(){if(this.movieElement==undefined){this.movieElement=document.getElementById(this.movieName)}if(this.movieElement===null){throw"Could not find Flash element"}return this.movieElement};SWFUpload.prototype.buildParamString=function(){var c=this.settings.post_params;var b=[];if(typeof(c)==="object"){for(var a in c){if(c.hasOwnProperty(a)){b.push(encodeURIComponent(a.toString())+"="+encodeURIComponent(c[a].toString()))}}}return b.join("&amp;")};SWFUpload.prototype.destroy=function(){try{this.cancelUpload(null,false);var a=null;a=this.getMovieElement();if(a&&typeof(a.CallFunction)==="unknown"){for(var c in a){try{if(typeof(a[c])==="function"){a[c]=null}}catch(e){}}try{a.parentNode.removeChild(a)}catch(b){}}window[this.movieName]=null;SWFUpload.instances[this.movieName]=null;delete SWFUpload.instances[this.movieName];this.movieElement=null;this.settings=null;this.customSettings=null;this.eventQueue=null;this.movieName=null;return true}catch(d){return false}};SWFUpload.prototype.displayDebugInfo=function(){this.debug(["---SWFUpload Instance Info---\n","Version: ",SWFUpload.version,"\n","Movie Name: ",this.movieName,"\n","Settings:\n","\t","upload_url: ",this.settings.upload_url,"\n","\t","flash_url: ",this.settings.flash_url,"\n","\t","use_query_string: ",this.settings.use_query_string.toString(),"\n","\t","requeue_on_error: ",this.settings.requeue_on_error.toString(),"\n","\t","http_success: ",this.settings.http_success.join(", "),"\n","\t","assume_success_timeout: ",this.settings.assume_success_timeout,"\n","\t","file_post_name: ",this.settings.file_post_name,"\n","\t","post_params: ",this.settings.post_params.toString(),"\n","\t","file_types: ",this.settings.file_types,"\n","\t","file_types_description: ",this.settings.file_types_description,"\n","\t","file_size_limit: ",this.settings.file_size_limit,"\n","\t","file_upload_limit: ",this.settings.file_upload_limit,"\n","\t","file_queue_limit: ",this.settings.file_queue_limit,"\n","\t","debug: ",this.settings.debug.toString(),"\n","\t","prevent_swf_caching: ",this.settings.prevent_swf_caching.toString(),"\n","\t","button_placeholder_id: ",this.settings.button_placeholder_id.toString(),"\n","\t","button_placeholder: ",(this.settings.button_placeholder?"Set":"Not Set"),"\n","\t","button_image_url: ",this.settings.button_image_url.toString(),"\n","\t","button_width: ",this.settings.button_width.toString(),"\n","\t","button_height: ",this.settings.button_height.toString(),"\n","\t","button_text: ",this.settings.button_text.toString(),"\n","\t","button_text_style: ",this.settings.button_text_style.toString(),"\n","\t","button_text_top_padding: ",this.settings.button_text_top_padding.toString(),"\n","\t","button_text_left_padding: ",this.settings.button_text_left_padding.toString(),"\n","\t","button_action: ",this.settings.button_action.toString(),"\n","\t","button_disabled: ",this.settings.button_disabled.toString(),"\n","\t","custom_settings: ",this.settings.custom_settings.toString(),"\n","Event Handlers:\n","\t","swfupload_loaded_handler assigned: ",(typeof this.settings.swfupload_loaded_handler==="function").toString(),"\n","\t","file_dialog_start_handler assigned: ",(typeof this.settings.file_dialog_start_handler==="function").toString(),"\n","\t","file_queued_handler assigned: ",(typeof this.settings.file_queued_handler==="function").toString(),"\n","\t","file_queue_error_handler assigned: ",(typeof this.settings.file_queue_error_handler==="function").toString(),"\n","\t","upload_start_handler assigned: ",(typeof this.settings.upload_start_handler==="function").toString(),"\n","\t","upload_progress_handler assigned: ",(typeof this.settings.upload_progress_handler==="function").toString(),"\n","\t","upload_error_handler assigned: ",(typeof this.settings.upload_error_handler==="function").toString(),"\n","\t","upload_success_handler assigned: ",(typeof this.settings.upload_success_handler==="function").toString(),"\n","\t","upload_complete_handler assigned: ",(typeof this.settings.upload_complete_handler==="function").toString(),"\n","\t","debug_handler assigned: ",(typeof this.settings.debug_handler==="function").toString(),"\n"].join(""))};SWFUpload.prototype.addSetting=function(b,c,a){if(c==undefined){return(this.settings[b]=a)}else{return(this.settings[b]=c)}};SWFUpload.prototype.getSetting=function(a){if(this.settings[a]!=undefined){return this.settings[a]}return""};SWFUpload.prototype.callFlash=function(functionName,argumentArray){argumentArray=argumentArray||[];var movieElement=this.getMovieElement();var returnValue,returnString;try{returnString=movieElement.CallFunction('<invoke name="'+functionName+'" returntype="javascript">'+__flash__argumentsToXML(argumentArray,0)+"</invoke>");returnValue=eval(returnString)}catch(ex){throw"Call to "+functionName+" failed"}if(returnValue!=undefined&&typeof returnValue.post==="object"){returnValue=this.unescapeFilePostParams(returnValue)}return returnValue};SWFUpload.prototype.selectFile=function(){this.callFlash("SelectFile")};SWFUpload.prototype.selectFiles=function(){this.callFlash("SelectFiles")};SWFUpload.prototype.startUpload=function(a){this.callFlash("StartUpload",[a])};SWFUpload.prototype.cancelUpload=function(a,b){if(b!==false){b=true}this.callFlash("CancelUpload",[a,b])};SWFUpload.prototype.stopUpload=function(){this.callFlash("StopUpload")};SWFUpload.prototype.getStats=function(){return this.callFlash("GetStats")};SWFUpload.prototype.setStats=function(a){this.callFlash("SetStats",[a])};SWFUpload.prototype.getFile=function(a){if(typeof(a)==="number"){return this.callFlash("GetFileByIndex",[a])}else{return this.callFlash("GetFile",[a])}};SWFUpload.prototype.addFileParam=function(a,b,c){return this.callFlash("AddFileParam",[a,b,c])};SWFUpload.prototype.removeFileParam=function(a,b){this.callFlash("RemoveFileParam",[a,b])};SWFUpload.prototype.setUploadURL=function(a){this.settings.upload_url=a.toString();this.callFlash("SetUploadURL",[a])};SWFUpload.prototype.setPostParams=function(a){this.settings.post_params=a;this.callFlash("SetPostParams",[a])};SWFUpload.prototype.addPostParam=function(a,b){this.settings.post_params[a]=b;this.callFlash("SetPostParams",[this.settings.post_params])};SWFUpload.prototype.removePostParam=function(a){delete this.settings.post_params[a];this.callFlash("SetPostParams",[this.settings.post_params])};SWFUpload.prototype.setFileTypes=function(a,b){this.settings.file_types=a;this.settings.file_types_description=b;this.callFlash("SetFileTypes",[a,b])};SWFUpload.prototype.setFileSizeLimit=function(a){this.settings.file_size_limit=a;this.callFlash("SetFileSizeLimit",[a])};SWFUpload.prototype.setFileUploadLimit=function(a){this.settings.file_upload_limit=a;this.callFlash("SetFileUploadLimit",[a])};SWFUpload.prototype.setFileQueueLimit=function(a){this.settings.file_queue_limit=a;this.callFlash("SetFileQueueLimit",[a])};SWFUpload.prototype.setFilePostName=function(a){this.settings.file_post_name=a;this.callFlash("SetFilePostName",[a])};SWFUpload.prototype.setUseQueryString=function(a){this.settings.use_query_string=a;this.callFlash("SetUseQueryString",[a])};SWFUpload.prototype.setRequeueOnError=function(a){this.settings.requeue_on_error=a;this.callFlash("SetRequeueOnError",[a])};SWFUpload.prototype.setHTTPSuccess=function(a){if(typeof a==="string"){a=a.replace(" ","").split(",")}this.settings.http_success=a;this.callFlash("SetHTTPSuccess",[a])};SWFUpload.prototype.setAssumeSuccessTimeout=function(a){this.settings.assume_success_timeout=a;this.callFlash("SetAssumeSuccessTimeout",[a])};SWFUpload.prototype.setDebugEnabled=function(a){this.settings.debug_enabled=a;this.callFlash("SetDebugEnabled",[a])};SWFUpload.prototype.setButtonImageURL=function(a){if(a==undefined){a=""}this.settings.button_image_url=a;this.callFlash("SetButtonImageURL",[a])};SWFUpload.prototype.setButtonDimensions=function(c,a){this.settings.button_width=c;this.settings.button_height=a;var b=this.getMovieElement();if(b!=undefined){b.style.width=c+"px";b.style.height=a+"px"}this.callFlash("SetButtonDimensions",[c,a])};SWFUpload.prototype.setButtonText=function(a){this.settings.button_text=a;this.callFlash("SetButtonText",[a])};SWFUpload.prototype.setButtonTextPadding=function(b,a){this.settings.button_text_top_padding=a;this.settings.button_text_left_padding=b;this.callFlash("SetButtonTextPadding",[b,a])};SWFUpload.prototype.setButtonTextStyle=function(a){this.settings.button_text_style=a;this.callFlash("SetButtonTextStyle",[a])};SWFUpload.prototype.setButtonDisabled=function(a){this.settings.button_disabled=a;this.callFlash("SetButtonDisabled",[a])};SWFUpload.prototype.setButtonAction=function(a){this.settings.button_action=a;this.callFlash("SetButtonAction",[a])};SWFUpload.prototype.setButtonCursor=function(a){this.settings.button_cursor=a;this.callFlash("SetButtonCursor",[a])};SWFUpload.prototype.queueEvent=function(b,c){if(c==undefined){c=[]}else{if(!(c instanceof Array)){c=[c]}}var a=this;if(typeof this.settings[b]==="function"){this.eventQueue.push(function(){this.settings[b].apply(this,c)});setTimeout(function(){a.executeNextEvent()},0)}else{if(this.settings[b]!==null){throw"Event handler "+b+" is unknown or is not a function"}}};SWFUpload.prototype.executeNextEvent=function(){var a=this.eventQueue?this.eventQueue.shift():null;if(typeof(a)==="function"){a.apply(this)}};SWFUpload.prototype.unescapeFilePostParams=function(c){var e=/[$]([0-9a-f]{4})/i;var f={};var d;if(c!=undefined){for(var a in c.post){if(c.post.hasOwnProperty(a)){d=a;var b;while((b=e.exec(d))!==null){d=d.replace(b[0],String.fromCharCode(parseInt("0x"+b[1],16)))}f[d]=c.post[a]}}c.post=f}return c};SWFUpload.prototype.testExternalInterface=function(){try{return this.callFlash("TestExternalInterface")}catch(a){return false}};SWFUpload.prototype.flashReady=function(){var a=this.getMovieElement();if(!a){this.debug("Flash called back ready but the flash movie can't be found.");return}this.cleanUp(a);this.queueEvent("swfupload_loaded_handler")};SWFUpload.prototype.cleanUp=function(a){try{if(this.movieElement&&typeof(a.CallFunction)==="unknown"){this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)");for(var c in a){try{if(typeof(a[c])==="function"){a[c]=null}}catch(b){}}}}catch(d){}window.__flash__removeCallback=function(e,f){try{if(e){e[f]=null}}catch(g){}}};SWFUpload.prototype.fileDialogStart=function(){this.queueEvent("file_dialog_start_handler")};SWFUpload.prototype.fileQueued=function(a){a=this.unescapeFilePostParams(a);this.queueEvent("file_queued_handler",a)};SWFUpload.prototype.fileQueueError=function(a,c,b){a=this.unescapeFilePostParams(a);this.queueEvent("file_queue_error_handler",[a,c,b])};SWFUpload.prototype.fileDialogComplete=function(b,c,a){this.queueEvent("file_dialog_complete_handler",[b,c,a])};SWFUpload.prototype.uploadStart=function(a){a=this.unescapeFilePostParams(a);this.queueEvent("return_upload_start_handler",a)};SWFUpload.prototype.returnUploadStart=function(a){var b;if(typeof this.settings.upload_start_handler==="function"){a=this.unescapeFilePostParams(a);b=this.settings.upload_start_handler.call(this,a)}else{if(this.settings.upload_start_handler!=undefined){throw"upload_start_handler must be a function"}}if(b===undefined){b=true}b=!!b;this.callFlash("ReturnUploadStart",[b])};SWFUpload.prototype.uploadProgress=function(a,c,b){a=this.unescapeFilePostParams(a);this.queueEvent("upload_progress_handler",[a,c,b])};SWFUpload.prototype.uploadError=function(a,c,b){a=this.unescapeFilePostParams(a);this.queueEvent("upload_error_handler",[a,c,b])};SWFUpload.prototype.uploadSuccess=function(b,a,c){b=this.unescapeFilePostParams(b);this.queueEvent("upload_success_handler",[b,a,c])};SWFUpload.prototype.uploadComplete=function(a){a=this.unescapeFilePostParams(a);this.queueEvent("upload_complete_handler",a)};SWFUpload.prototype.debug=function(a){this.queueEvent("debug_handler",a)};SWFUpload.prototype.debugMessage=function(c){if(this.settings.debug){var a,d=[];if(typeof c==="object"&&typeof c.name==="string"&&typeof c.message==="string"){for(var b in c){if(c.hasOwnProperty(b)){d.push(b+": "+c[b])}}a=d.join("\n")||"";d=a.split("\n");a="EXCEPTION: "+d.join("\nEXCEPTION: ");SWFUpload.Console.writeLine(a)}else{SWFUpload.Console.writeLine(c)}}};SWFUpload.Console={};SWFUpload.Console.writeLine=function(d){var b,a;try{b=document.getElementById("SWFUpload_Console");if(!b){a=document.createElement("form");document.getElementsByTagName("body")[0].appendChild(a);b=document.createElement("textarea");b.id="SWFUpload_Console";b.style.fontFamily="monospace";b.setAttribute("wrap","off");b.wrap="off";b.style.overflow="auto";b.style.width="700px";b.style.height="350px";b.style.margin="5px";a.appendChild(b)}b.value+=d+"\n";b.scrollTop=b.scrollHeight-b.clientHeight}catch(c){alert("Exception: "+c.name+" Message: "+c.message)}};
  10. /*
  11. Uploadify v3.0.0
  12. Copyright (c) 2010 Ronnie Garcia
  13. Permission is hereby granted, free of charge, to any person obtaining a copy
  14. of this software and associated documentation files (the "Software"), to deal
  15. in the Software without restriction, including without limitation the rights
  16. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  17. copies of the Software, and to permit persons to whom the Software is
  18. furnished to do so, subject to the following conditions:
  19. The above copyright notice and this permission notice shall be included in
  20. all copies or substantial portions of the Software.
  21. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  22. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  24. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  25. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  26. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  27. THE SOFTWARE.
  28. */
  29. if(jQuery)(
  30. function(jQuery){
  31. jQuery.extend(jQuery.fn,{
  32. uploadify:function(options,swfUploadOptions) {
  33. jQuery(this).each(function() {
  34. var clone = jQuery(this).clone();
  35. var settings = jQuery.extend({
  36. // Required Settings
  37. id : jQuery(this).attr('id'),
  38. swf : 'uploadify.swf',
  39. uploader : 'uploadify.php',
  40. // Options
  41. auto : false,
  42. buttonClass : '',
  43. buttonCursor : 'hand',
  44. buttonImage : null,
  45. buttonText : 'SELECT FILES',
  46. cancelImage : 'uploadify-cancel.png',
  47. checkExisting : 'uploadify-check-existing.php',
  48. debug : false,
  49. fileObjName : 'Filedata',
  50. fileSizeLimit : 0,
  51. fileTypeDesc : 'All Files (*.*)',
  52. fileTypeExts : '*.*',
  53. height : 30,
  54. method : 'post',
  55. multi : false,
  56. queueID : false,
  57. queueSizeLimit : 999,
  58. removeCompleted : true,
  59. removeTimeout : 3,
  60. requeueErrors : true,
  61. postData : {},
  62. preventCaching : true,
  63. progressData : 'percentage',
  64. // simUploadLimit : 1, // Not possible with swfUpload
  65. successTimeout : 30,
  66. transparent : true,
  67. uploadLimit : 999,
  68. uploaderType : 'html5', // the other option is 'flash'
  69. width : 120,
  70. // Events
  71. skipDefault : [],
  72. onClearQueue : function() {},
  73. onDialogOpen : function() {},
  74. onDialogClose : function() {},
  75. onInit : function() {},
  76. onQueueComplete : function() {},
  77. onSelectError : function() {},
  78. onSelect : function() {},
  79. onSWFReady : function() {},
  80. onUploadCancel : function() {},
  81. onUploadComplete : function() {},
  82. onUploadError : function() {},
  83. onUploadProgress : function() {},
  84. onUploadStart : function() {}
  85. }, options);
  86. var swfUploadSettings = {
  87. assume_success_timeout : settings.successTimeout,
  88. button_placeholder_id : settings.id,
  89. button_image_url : settings.buttonImage,
  90. button_width : settings.width,
  91. button_height : settings.height,
  92. button_text : null,
  93. button_text_style : null,
  94. button_text_top_padding : 0,
  95. button_text_left_padding : 0,
  96. button_action : (settings.multi ? SWFUpload.BUTTON_ACTION.SELECT_FILES : SWFUpload.BUTTON_ACTION.SELECT_FILE),
  97. button_disabled : false,
  98. button_cursor : (settings.buttonCursor == 'arrow' ? SWFUpload.CURSOR.ARROW : SWFUpload.CURSOR.HAND),
  99. button_window_mode : (settings.transparent && !settings.buttonImage ? SWFUpload.WINDOW_MODE.TRANSPARENT : SWFUpload.WINDOW_MODE.OPAQUE),
  100. debug : settings.debug,
  101. requeue_on_error : settings.requeueErrors,
  102. file_post_name : settings.fileObjName,
  103. file_size_limit : settings.fileSizeLimit,
  104. file_types : settings.fileTypeExts,
  105. file_types_description : settings.fileTypeDesc,
  106. file_queue_limit : settings.queueSizeLimit,
  107. file_upload_limit : settings.uploadLimit,
  108. flash_url : settings.swf,
  109. prevent_swf_caching : settings.preventCaching,
  110. post_params : settings.postData,
  111. upload_url : settings.uploader,
  112. use_query_string : (settings.method == 'get'),
  113. // Event Handlers
  114. file_dialog_complete_handler : onDialogClose,
  115. file_dialog_start_handler : onDialogOpen,
  116. file_queued_handler : onSelect,
  117. file_queue_error_handler : onSelectError,
  118. flash_ready_handler : settings.onSWFReady,
  119. upload_complete_handler : onUploadComplete,
  120. upload_error_handler : onUploadError,
  121. upload_progress_handler : onUploadProgress,
  122. upload_start_handler : onUploadStart,
  123. upload_success_handler : onUploadSuccess
  124. }
  125. if (swfUploadOptions) {
  126. swfUploadSettings = jQuery.extend(swfUploadSettings,swfUploadOptions);
  127. }
  128. swfUploadSettings = jQuery.extend(swfUploadSettings,settings);
  129. // Create the swfUpload instance
  130. window['uploadify_' + settings.id] = new SWFUpload(swfUploadSettings);
  131. var swfuploadify = window['uploadify_' + settings.id];
  132. swfuploadify.original = clone;
  133. // Wrap the uploadify instance
  134. var wrapper = jQuery('<div />',{
  135. id : settings.id,
  136. 'class' : 'uploadify',
  137. css : {
  138. 'height' : settings.height + 'px',
  139. 'position' : 'relative',
  140. 'width' : settings.width + 'px'
  141. }
  142. });
  143. jQuery('#' + swfuploadify.movieName).wrap(wrapper);
  144. // Create the file queue
  145. if (!settings.queueID) {
  146. var queue = jQuery('<div />', {
  147. id : settings.id + '_queue',
  148. 'class' : 'uploadifyQueue'
  149. });
  150. jQuery('#' + settings.id).after(queue);
  151. swfuploadify.settings.queueID = settings.queueID = settings.id + '_queue';
  152. }
  153. // Create some queue related objects and variables
  154. swfuploadify.queue = {
  155. files : {}, // The files in the queue
  156. filesSelected : 0, // The number of files selected in the last select operation
  157. filesQueued : 0, // The number of files added to the queue in the last select operation
  158. filesReplaced : 0, // The number of files replaced in the last select operation
  159. filesCancelled : 0, // The number of files that were cancelled instead of replaced
  160. filesErrored : 0, // The number of files that caused error in the last select operation
  161. averageSpeed : 0, // The average speed of the uploads in KB
  162. queueLength : 0, // The number of files in the queue
  163. queueSize : 0, // The size in bytes of the entire queue
  164. uploadSize : 0, // The size in bytes of the upload queue
  165. queueBytesUploaded : 0, // The size in bytes that have been uploaded for the current upload queue
  166. uploadQueue : [], // The files currently to be uploaded
  167. errorMsg : 'Some files were not added to the queue:'
  168. };
  169. // Create the button
  170. if (!settings.buttonImage) {
  171. var button = jQuery('<div />', {
  172. id : settings.id + '_button',
  173. 'class' : 'uploadifyButton ' + settings.buttonClass,
  174. html : '<span class="uploadifyButtonText">' + settings.buttonText + '</span>'
  175. });
  176. jQuery('#' + settings.id).append(button);
  177. jQuery('#' + swfuploadify.movieName).css({position: 'absolute', 'z-index': 1});
  178. } else {
  179. jQuery('#' + swfuploadify.movieName).addClass(settings.buttonClass);
  180. }
  181. // -----------------------------
  182. // Begin Event Handler Functions
  183. // -----------------------------
  184. // Triggered once when file dialog is closed
  185. function onDialogClose(filesSelected,filesQueued,queueLength) {
  186. var stats = swfuploadify.getStats();
  187. swfuploadify.queue.filesErrored = filesSelected - filesQueued;
  188. swfuploadify.queue.filesSelected = filesSelected;
  189. swfuploadify.queue.filesQueued = filesQueued - swfuploadify.queue.filesCancelled;
  190. swfuploadify.queue.queueLength = queueLength;
  191. if (jQuery.inArray('onDialogClose',swfuploadify.settings.skipDefault) < 0) {
  192. if (swfuploadify.queue.filesErrored > 0) {
  193. alert(swfuploadify.queue.errorMsg);
  194. }
  195. }
  196. if (swfuploadify.settings.onDialogClose) swfuploadify.settings.onDialogClose(swfuploadify.queue);
  197. if (swfuploadify.settings.auto) jQuery('#' + swfuploadify.settings.id).uploadifyUpload('*');
  198. }
  199. function onDialogOpen() {
  200. // Reset some queue info
  201. swfuploadify.queue.errorMsg = 'Some files were not added to the queue:';
  202. swfuploadify.queue.filesReplaced = 0;
  203. swfuploadify.queue.filesCancelled = 0;
  204. if (swfuploadify.settings.onDialogOpen) swfuploadify.settings.onDialogOpen();
  205. }
  206. // Triggered once for each file added to the queue
  207. function onSelect(file) {
  208. if (jQuery.inArray('onSelect',swfuploadify.settings.skipDefault) < 0) {
  209. // Check if a file with the same name exists in the queue
  210. var queuedFile = {};
  211. for (var n in swfuploadify.queue.files) {
  212. queuedFile = swfuploadify.queue.files[n];
  213. if (queuedFile.name == file.name) {
  214. var replaceQueueItem = confirm('The file named "' + file.name + '" is already in the queue.\nDo you want to replace the existing item in the queue?');
  215. if (!replaceQueueItem) {
  216. swfuploadify.cancelUpload(file.id);
  217. swfuploadify.queue.filesCancelled++;
  218. return false;
  219. } else {
  220. jQuery('#' + queuedFile.id).remove();
  221. swfuploadify.cancelUpload(queuedFile.id);
  222. swfuploadify.queue.filesReplaced++;
  223. }
  224. }
  225. }
  226. // Get the size of the file
  227. var fileSize = Math.round(file.size / 1024);
  228. var suffix = 'KB';
  229. if (fileSize > 1000) {
  230. fileSize = Math.round(fileSize / 1000);
  231. suffix = 'MB';
  232. }
  233. var fileSizeParts = fileSize.toString().split('.');
  234. fileSize = fileSizeParts[0];
  235. if (fileSizeParts.length > 1) {
  236. fileSize += '.' + fileSizeParts[1].substr(0,2);
  237. }
  238. fileSize += suffix;
  239. // Truncate the filename if it's too long
  240. var fileName = file.name;
  241. if (fileName.length > 25) {
  242. fileName = fileName.substr(0,25) + '...';
  243. }
  244. // Add the file item to the queue
  245. jQuery('#' + swfuploadify.settings.queueID).append('<div id="' + file.id + '" class="uploadifyQueueItem">\
  246. <div class="cancel">\
  247. <a href="javascript:jQuery(\'#' + swfuploadify.settings.id + '\').uploadifyCancel(\'' + file.id + '\')"><img src="' + swfuploadify.settings.cancelImage + '" border="0" /></a>\
  248. </div>\
  249. <span class="fileName">' + fileName + ' (' + fileSize + ')</span><span class="data"></span>\
  250. <div class="uploadifyProgress">\
  251. <div class="uploadifyProgressBar"><!--Progress Bar--></div>\
  252. </div>\
  253. </div>');
  254. swfuploadify.queue.queueSize += file.size;
  255. }
  256. swfuploadify.queue.files[file.id] = file;
  257. if (swfuploadify.settings.onSelect) swfuploadify.settings.onSelect(file);
  258. }
  259. // Triggered when a file is not added to the queue
  260. function onSelectError(file,errorCode,errorMsg) {
  261. if (jQuery.inArray('onSelectError',swfuploadify.settings.skipDefault) < 0) {
  262. switch(errorCode) {
  263. case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
  264. if (swfuploadify.settings.queueSizeLimit > errorMsg) {
  265. swfuploadify.queue.errorMsg += '\nThe number of files selected exceeds the remaining upload limit (' + errorMsg + ').';
  266. } else {
  267. swfuploadify.queue.errorMsg += '\nThe number of files selected exceeds the queue size limit (' + swfuploadify.settings.queueSizeLimit + ').';
  268. }
  269. break;
  270. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  271. swfuploadify.queue.errorMsg += '\nThe file "' + file.name + '" exceeds the size limit (' + swfuploadify.settings.fileSizeLimit + ').';
  272. break;
  273. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  274. swfuploadify.queue.errorMsg += '\nThe file "' + file.name + '" is empty.';
  275. break;
  276. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  277. swfuploadify.queue.errorMsg += '\nThe file "' + file.name + '" is not an accepted file type (' + swfuploadify.settings.fileTypeDesc + ').';
  278. break;
  279. }
  280. }
  281. if (errorCode != SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED) {
  282. delete swfuploadify.queue.files[file.id];
  283. }
  284. if (swfuploadify.settings.onSelectError) swfuploadify.settings.onSelectError(file,errorCode,errorMsg);
  285. }
  286. // Triggered when all the files in the queue have been processed
  287. function onQueueComplete() {
  288. var stats = swfuploadify.getStats();
  289. if (swfuploadify.settings.onQueueComplete) swfuploadify.settings.onQueueComplete(stats);
  290. }
  291. // Triggered when a file upload successfully completes
  292. function onUploadComplete(file) {
  293. var stats = swfuploadify.getStats();
  294. swfuploadify.queue.queueLength = stats.files_queued;
  295. if (swfuploadify.queue.uploadQueue[0] == '*') {
  296. if (swfuploadify.queue.queueLength > 0) {
  297. swfuploadify.startUpload();
  298. } else {
  299. swfuploadify.queue.uploadQueue = [];
  300. if (swfuploadify.settings.onQueueComplete) swfuploadify.settings.onQueueComplete(stats);
  301. }
  302. } else {
  303. if (swfuploadify.queue.uploadQueue.length > 0) {
  304. swfuploadify.startUpload(swfuploadify.queue.uploadQueue.shift());
  305. } else {
  306. swfuploadify.queue.uploadQueue = [];
  307. if (swfuploadify.settings.onQueueComplete) setting.onQueueComplete(stats);
  308. }
  309. }
  310. if (jQuery.inArray('onUploadComplete',swfuploadify.settings.skipDefault) < 0) {
  311. if (swfuploadify.settings.removeCompleted) {
  312. switch (file.filestatus) {
  313. case SWFUpload.FILE_STATUS.COMPLETE:
  314. setTimeout(function() {
  315. if (jQuery('#' + file.id)) {
  316. swfuploadify.queue.queueSize -= file.size;
  317. delete swfuploadify.queue.files[file.id]
  318. jQuery('#' + file.id).fadeOut(500,function() {
  319. jQuery(this).remove();
  320. });
  321. }
  322. },swfuploadify.settings.removeTimeout * 1000);
  323. break;
  324. case SWFUpload.FILE_STATUS.ERROR:
  325. if (!swfuploadify.settings.requeueErrors) {
  326. setTimeout(function() {
  327. if (jQuery('#' + file.id)) {
  328. swfuploadify.queue.queueSize -= file.size;
  329. delete swfuploadify.queue.files[file.id];
  330. jQuery('#' + file.id).fadeOut(500,function() {
  331. jQuery(this).remove();
  332. });
  333. }
  334. },swfuploadify.settings.removeTimeout * 1000);
  335. }
  336. break;
  337. }
  338. }
  339. }
  340. if (swfuploadify.settings.onUploadComplete) swfuploadify.settings.onUploadComplete(file,swfuploadify.queue);
  341. }
  342. // Triggered when a file upload returns an error
  343. function onUploadError(file,errorCode,errorMsg) {
  344. var errorString = 'Error';
  345. if (errorCode != SWFUpload.UPLOAD_ERROR.FILE_CANCELLED && errorCode != SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED) {
  346. jQuery('#' + file.id).addClass('uploadifyError');
  347. }
  348. jQuery('#' + file.id).find('.uploadifyProgressBar').css('width','1px');
  349. switch(errorCode) {
  350. case SWFUpload.UPLOAD_ERROR.HTTP_ERROR:
  351. errorString = 'HTTP Error (' + errorMsg + ')';
  352. break;
  353. case SWFUpload.UPLOAD_ERROR.MISSING_UPLOAD_URL:
  354. errorString = 'Missing Upload URL';
  355. break;
  356. case SWFUpload.UPLOAD_ERROR.IO_ERROR:
  357. errorString = 'IO Error';
  358. break;
  359. case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR:
  360. errorString = 'Security Error';
  361. break;
  362. case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
  363. alert('The upload limit has been reached (' + errorMsg + ').');
  364. errorString = 'Exceeds Upload Limit';
  365. break;
  366. case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED:
  367. errorString = 'Failed';
  368. break;
  369. case SWFUpload.UPLOAD_ERROR.SPECIFIED_FILE_ID_NOT_FOUND:
  370. break;
  371. case SWFUpload.UPLOAD_ERROR.FILE_VALIDATION_FAILED:
  372. errorString = 'Validation Error';
  373. break;
  374. case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
  375. errorString = 'Cancelled';
  376. swfuploadify.queue.queueSize -= file.size;
  377. if (file.status == SWFUpload.FILE_STATUS.IN_PROGRESS || jQuery.inArray(file.id,swfuploadify.queue.uploadQueue) >= 0) {
  378. swfuploadify.queue.uploadSize -= file.size;
  379. }
  380. delete swfuploadify.queue.files[file.id];
  381. break;
  382. case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
  383. errorString = 'Stopped';
  384. break;
  385. }
  386. if (errorCode != SWFUpload.UPLOAD_ERROR.SPECIFIED_FILE_ID_NOT_FOUND && file.status != SWFUpload.FILE_STATUS.COMPLETE) {
  387. jQuery('#' + file.id).find('.data').html(' - ' + errorString);
  388. }
  389. if (swfuploadify.settings.onUploadError) swfuploadify.settings.onUploadError(file,errorCode,errorMsg,errorString,swfuploadify.queue);
  390. }
  391. // Triggered periodically during a file upload
  392. function onUploadProgress(file,fileBytesLoaded,fileTotalBytes) {
  393. var timer = new Date();
  394. var newTime = timer.getTime();
  395. var lapsedTime = newTime - swfuploadify.timer;
  396. swfuploadify.timer = newTime;
  397. var lapsedBytes = fileBytesLoaded - swfuploadify.bytesLoaded;
  398. swfuploadify.bytesLoaded = fileBytesLoaded;
  399. var queueBytesLoaded = swfuploadify.queue.queueBytesUploaded + fileBytesLoaded;
  400. var percentage = Math.round(fileBytesLoaded / fileTotalBytes * 100);
  401. // Calculate the average speed
  402. var mbs = 0;
  403. var kbs = (lapsedBytes / 1024) / (lapsedTime / 1000);
  404. kbs = Math.floor(kbs * 10) / 10;
  405. if (swfuploadify.queue.averageSpeed > 0) {
  406. swfuploadify.queue.averageSpeed = (swfuploadify.queue.averageSpeed + kbs) / 2;
  407. } else {
  408. swfuploadify.queue.averageSpeed = kbs;
  409. }
  410. if (kbs > 1000) {
  411. mbs = (kbs * .001);
  412. swfuploadify.queue.averageSpeed = mbs;
  413. }
  414. var suffix = 'KB/s';
  415. if (mbs > 0) {
  416. suffix = 'MB/s';
  417. }
  418. if (jQuery.inArray('onUploadProgress',swfuploadify.settings.skipDefault) < 0) {
  419. if (swfuploadify.settings.progressData == 'percentage') {
  420. jQuery('#' + file.id).find('.data').html(' - ' + percentage + '%');
  421. } else if (swfuploadify.settings.progressData == 'speed') {
  422. jQuery('#' + file.id).find('.data').html(' - ' + percentage + suffix);
  423. }
  424. jQuery('#' + file.id).find('.uploadifyProgressBar').css('width',percentage + '%');
  425. }
  426. if (swfuploadify.settings.onUploadProgress) swfuploadify.settings.onUploadProgress(file,fileBytesLoaded,fileTotalBytes,queueBytesLoaded,swfuploadify.queue.uploadSize);
  427. }
  428. // Triggered right before a file is uploaded
  429. function onUploadStart(file) {
  430. var timer = new Date();
  431. swfuploadify.timer = timer.getTime();
  432. swfuploadify.bytesLoaded = 0;
  433. if (swfuploadify.queue.uploadQueue.length == 0) {
  434. swfuploadify.queue.uploadSize = file.size;
  435. }
  436. if (swfuploadify.settings.checkExisting !== false) {
  437. jQuery.ajax({
  438. type : 'POST',
  439. async : false,
  440. url : swfuploadify.settings.checkExisting,
  441. data : {filename: file.name},
  442. success : function(data) {
  443. if (data == 1) {
  444. var overwrite = confirm('A file with the name "' + file.name + '" already exists on the server.\nWould you like to replace the existing file?');
  445. if (!overwrite) {
  446. swfuploadify.cancelUpload(file.id);
  447. jQuery('#' + file.id).remove();
  448. if (swfuploadify.queue.uploadQueue.length > 0 && swfuploadify.queue.queueLength > 0) {
  449. if (swfuploadify.queue.uploadQueue[0] == '*') {
  450. swfuploadify.startUpload();
  451. } else {
  452. swfuploadify.startUpload(swfuploadify.queue.uploadQueue.shift());
  453. }
  454. }
  455. }
  456. }
  457. }
  458. });
  459. }
  460. if (swfuploadify.settings.onUploadStart) swfuploadify.settings.onUploadStart(file);
  461. }
  462. // Triggered when a file upload returns a successful code
  463. function onUploadSuccess(file,data,response) {
  464. swfuploadify.queue.queueBytesUploaded += file.size;
  465. jQuery('#' + file.id).find('.data').html(' - Complete');
  466. if (swfuploadify.settings.onUploadSuccess) swfuploadify.settings.onUploadSuccess(file,data,response);
  467. }
  468. // ---------------------------
  469. // End Event Handler Functions
  470. // ---------------------------
  471. });
  472. },
  473. // Cancel a file upload and remove it from the queue
  474. uploadifyCancel:function(fileID) {
  475. var id = jQuery(this).selector.replace('#','');
  476. var swfuploadify = window['uploadify_' + id];
  477. var delay = -1;
  478. if (arguments[0]) {
  479. if (arguments[0] == '*') {
  480. jQuery('#' + swfuploadify.settings.queueID).find('.uploadifyQueueItem').each(function() {
  481. delay++;
  482. swfuploadify.cancelUpload(jQuery(this).attr('id'));
  483. jQuery(this).delay(100 * delay).fadeOut(500,function() {
  484. jQuery(this).remove();
  485. });
  486. });
  487. swfuploadify.queue.queueSize = 0;
  488. } else {
  489. for (var n = 0; n < arguments.length; n++) {
  490. swfuploadify.cancelUpload(arguments[n]);
  491. jQuery('#' + arguments[n]).delay(100 * n).fadeOut(500,function() {
  492. jQuery(this).remove();
  493. });
  494. }
  495. }
  496. } else {
  497. jQuery('#' + swfuploadify.settings.queueID).find('.uploadifyQueueItem').get(0).fadeOut(500,function() {
  498. jQuery(this).remove();
  499. swfuploadify.cancelUpload(jQuery(this).attr('id'));
  500. });
  501. }
  502. },
  503. // Get rid of the instance of Uploadify
  504. uploadifyDestroy:function() {
  505. var id = jQuery(this).selector.replace('#','');
  506. var swfuploadify = window['uploadify_' + id];
  507. swfuploadify.destroy();
  508. jQuery('#' + id + '_queue').remove();
  509. jQuery('#' + id).replaceWith(swfuploadify.original);
  510. delete window['uploadify_' + id];
  511. },
  512. // Disable the select button
  513. uploadifyDisable:function(isDisabled) {
  514. var id = jQuery(this).selector.replace('#','');
  515. var swfuploadify = window['uploadify_' + id];
  516. swfuploadify.setButtonDisabled(isDisabled);
  517. },
  518. // Update or retrieve a setting
  519. uploadifySettings:function(name,value,resetObjects) {
  520. var id = jQuery(this).selector.replace('#','');
  521. var swfuploadify = window['uploadify_' + id];
  522. if (typeof(arguments[0]) == 'object') {
  523. for (var n in value) {
  524. setData(n,value[n]);
  525. }
  526. }
  527. if (arguments.length == 1) {
  528. return swfuploadify.settings[name];
  529. } else {
  530. setData(name,value,resetObjects);
  531. }
  532. function setData(settingName,settingValue,resetObjects) {
  533. switch (settingName) {
  534. case 'uploader':
  535. swfuploadify.setUploadURL(settingValue);
  536. break;
  537. case 'postData':
  538. if (!resetObjects) {
  539. value = jQuery.extend(swfuploadify.settings.postData,settingValue);
  540. }
  541. swfuploadify.setPostParams(settingValue);
  542. break;
  543. case 'method':
  544. if (settingValue == 'get') {
  545. swfuploadify.setUseQueryString(true);
  546. } else {
  547. swfuploadify.setUseQueryString(false);
  548. }
  549. break;
  550. case 'fileObjName':
  551. swfuploadify.setFilePostName(settingValue);
  552. break;
  553. case 'fileTypeExts':
  554. swfuploadify.setFileTypes(settingValue,swfuploadify.settings.fileTypeDesc);
  555. break;
  556. case 'fileTypeDesc':
  557. swfuploadify.setFileTypes(swfuploadify.settings.fileTypeExts,settingValue);
  558. break;
  559. case 'fileSizeLimit':
  560. swfuploadify.setFileSizeLimit(settingValue);
  561. break;
  562. case 'uploadLimit':
  563. swfuploadify.setFileUploadLimit(settingValue);
  564. break;
  565. case 'queueSizeLimit':
  566. swfuploadify.setFileQueueLimit(settingValue);
  567. break;
  568. case 'buttonImage':
  569. jQuery('#' + swfuploadify.settings.id + '_button').remove();
  570. swfuploadify.setButtonImageURL(settingValue);
  571. break;
  572. case 'buttonCursor':
  573. if (settingValue == 'arrow') {
  574. swfuploadify.setButtonCursor(SWFUpload.CURSOR.ARROW);
  575. } else {
  576. swfuploadify.setButtonCursor(SWFUpload.CURSOR.HAND);
  577. }
  578. break;
  579. case 'buttonText':
  580. jQuery('#' + swfuploadify.settings.id + '_button').find('.uploadifyButtonText').html(settingValue);
  581. break;
  582. case 'width':
  583. swfuploadify.setButtonDimensions(settingValue,swfuploadify.settings.height);
  584. break;
  585. case 'height':
  586. swfuploadify.setButtonDimensions(swfuploadify.settings.width,settingValue);
  587. break;
  588. case 'multi':
  589. if (settingValue) {
  590. swfuploadify.setButtonAction(SWFUpload.BUTTON_ACTION.SELECT_FILES);
  591. } else {
  592. swfuploadify.setButtonAction(SWFUpload.BUTTON_ACTION.SELECT_FILE);
  593. }
  594. break;
  595. }
  596. swfuploadify.settings[settingName] = value;
  597. }
  598. },
  599. // Stop the current upload and requeue what is in progress
  600. uploadifyStop:function() {
  601. var id = jQuery(this).selector.replace('#','');
  602. var swfuploadify = window['uploadify_' + id];
  603. swfuploadify.stopUpload();
  604. },
  605. // Upload the first file, a select number of files, or all the files in the queue
  606. uploadifyUpload:function() {
  607. var id = jQuery(this).selector.replace('#','');
  608. var swfuploadify = window['uploadify_' + id];
  609. // Reset the queue information
  610. swfuploadify.queue.averageSpeed = 0;
  611. swfuploadify.queue.uploadSize = 0;
  612. swfuploadify.queue.bytesUploaded = 0;
  613. swfuploadify.queue.uploadQueue = [];
  614. if (arguments[0]) {
  615. if (arguments[0] == '*') {
  616. swfuploadify.queue.uploadSize = swfuploadify.queue.queueSize;
  617. swfuploadify.queue.uploadQueue.push('*');
  618. swfuploadify.startUpload();
  619. } else {
  620. for (var n = 0; n < arguments.length; n++) {
  621. swfuploadify.queue.uploadSize += swfuploadify.queue.files[arguments[n]].size;
  622. swfuploadify.queue.uploadQueue.push(arguments[n]);
  623. }
  624. swfuploadify.startUpload(swfuploadify.queue.uploadQueue.shift());
  625. }
  626. } else {
  627. swfuploadify.startUpload();
  628. }
  629. }
  630. })
  631. }
  632. )(jQuery);