You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

985 lines
63 KiB

8 years ago
  1. /*
  2. SWFObject v2.2 <http://code.google.com/p/swfobject/>
  3. is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
  4. */
  5. ;var swfobject=function(){var D="undefined",r="object",S="Shockwave Flash",W="ShockwaveFlash.ShockwaveFlash",q="application/x-shockwave-flash",R="SWFObjectExprInst",x="onreadystatechange",O=window,j=document,t=navigator,T=false,U=[h],o=[],N=[],I=[],l,Q,E,B,J=false,a=false,n,G,m=true,M=function(){var aa=typeof j.getElementById!=D&&typeof j.getElementsByTagName!=D&&typeof j.createElement!=D,ah=t.userAgent.toLowerCase(),Y=t.platform.toLowerCase(),ae=Y?/win/.test(Y):/win/.test(ah),ac=Y?/mac/.test(Y):/mac/.test(ah),af=/webkit/.test(ah)?parseFloat(ah.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):false,X=!+"\v1",ag=[0,0,0],ab=null;
  6. if(typeof t.plugins!=D&&typeof t.plugins[S]==r){ab=t.plugins[S].description;if(ab&&!(typeof t.mimeTypes!=D&&t.mimeTypes[q]&&!t.mimeTypes[q].enabledPlugin)){T=true;
  7. X=false;ab=ab.replace(/^.*\s+(\S+\s+\S+$)/,"$1");ag[0]=parseInt(ab.replace(/^(.*)\..*$/,"$1"),10);ag[1]=parseInt(ab.replace(/^.*\.(.*)\s.*$/,"$1"),10);
  8. ag[2]=/[a-zA-Z]/.test(ab)?parseInt(ab.replace(/^.*[a-zA-Z]+(.*)$/,"$1"),10):0;}}else{if(typeof O.ActiveXObject!=D){try{var ad=new ActiveXObject(W);if(ad){ab=ad.GetVariable("$version");
  9. if(ab){X=true;ab=ab.split(" ")[1].split(",");ag=[parseInt(ab[0],10),parseInt(ab[1],10),parseInt(ab[2],10)];}}}catch(Z){}}}return{w3:aa,pv:ag,wk:af,ie:X,win:ae,mac:ac};
  10. }(),k=function(){if(!M.w3){return;}if((typeof j.readyState!=D&&j.readyState=="complete")||(typeof j.readyState==D&&(j.getElementsByTagName("body")[0]||j.body))){f();
  11. }if(!J){if(typeof j.addEventListener!=D){j.addEventListener("DOMContentLoaded",f,false);}if(M.ie&&M.win){j.attachEvent(x,function(){if(j.readyState=="complete"){j.detachEvent(x,arguments.callee);
  12. f();}});if(O==top){(function(){if(J){return;}try{j.documentElement.doScroll("left");}catch(X){setTimeout(arguments.callee,0);return;}f();})();}}if(M.wk){(function(){if(J){return;
  13. }if(!/loaded|complete/.test(j.readyState)){setTimeout(arguments.callee,0);return;}f();})();}s(f);}}();function f(){if(J){return;}try{var Z=j.getElementsByTagName("body")[0].appendChild(C("span"));
  14. Z.parentNode.removeChild(Z);}catch(aa){return;}J=true;var X=U.length;for(var Y=0;Y<X;Y++){U[Y]();}}function K(X){if(J){X();}else{U[U.length]=X;}}function s(Y){if(typeof O.addEventListener!=D){O.addEventListener("load",Y,false);
  15. }else{if(typeof j.addEventListener!=D){j.addEventListener("load",Y,false);}else{if(typeof O.attachEvent!=D){i(O,"onload",Y);}else{if(typeof O.onload=="function"){var X=O.onload;
  16. O.onload=function(){X();Y();};}else{O.onload=Y;}}}}}function h(){if(T){V();}else{H();}}function V(){var X=j.getElementsByTagName("body")[0];var aa=C(r);
  17. aa.setAttribute("type",q);var Z=X.appendChild(aa);if(Z){var Y=0;(function(){if(typeof Z.GetVariable!=D){var ab=Z.GetVariable("$version");if(ab){ab=ab.split(" ")[1].split(",");
  18. M.pv=[parseInt(ab[0],10),parseInt(ab[1],10),parseInt(ab[2],10)];}}else{if(Y<10){Y++;setTimeout(arguments.callee,10);return;}}X.removeChild(aa);Z=null;H();
  19. })();}else{H();}}function H(){var ag=o.length;if(ag>0){for(var af=0;af<ag;af++){var Y=o[af].id;var ab=o[af].callbackFn;var aa={success:false,id:Y};if(M.pv[0]>0){var ae=c(Y);
  20. if(ae){if(F(o[af].swfVersion)&&!(M.wk&&M.wk<312)){w(Y,true);if(ab){aa.success=true;aa.ref=z(Y);ab(aa);}}else{if(o[af].expressInstall&&A()){var ai={};ai.data=o[af].expressInstall;
  21. ai.width=ae.getAttribute("width")||"0";ai.height=ae.getAttribute("height")||"0";if(ae.getAttribute("class")){ai.styleclass=ae.getAttribute("class");}if(ae.getAttribute("align")){ai.align=ae.getAttribute("align");
  22. }var ah={};var X=ae.getElementsByTagName("param");var ac=X.length;for(var ad=0;ad<ac;ad++){if(X[ad].getAttribute("name").toLowerCase()!="movie"){ah[X[ad].getAttribute("name")]=X[ad].getAttribute("value");
  23. }}P(ai,ah,Y,ab);}else{p(ae);if(ab){ab(aa);}}}}}else{w(Y,true);if(ab){var Z=z(Y);if(Z&&typeof Z.SetVariable!=D){aa.success=true;aa.ref=Z;}ab(aa);}}}}}function z(aa){var X=null;
  24. var Y=c(aa);if(Y&&Y.nodeName=="OBJECT"){if(typeof Y.SetVariable!=D){X=Y;}else{var Z=Y.getElementsByTagName(r)[0];if(Z){X=Z;}}}return X;}function A(){return !a&&F("6.0.65")&&(M.win||M.mac)&&!(M.wk&&M.wk<312);
  25. }function P(aa,ab,X,Z){a=true;E=Z||null;B={success:false,id:X};var ae=c(X);if(ae){if(ae.nodeName=="OBJECT"){l=g(ae);Q=null;}else{l=ae;Q=X;}aa.id=R;if(typeof aa.width==D||(!/%$/.test(aa.width)&&parseInt(aa.width,10)<310)){aa.width="310";
  26. }if(typeof aa.height==D||(!/%$/.test(aa.height)&&parseInt(aa.height,10)<137)){aa.height="137";}j.title=j.title.slice(0,47)+" - Flash Player Installation";
  27. var ad=M.ie&&M.win?"ActiveX":"PlugIn",ac="MMredirectURL="+O.location.toString().replace(/&/g,"%26")+"&MMplayerType="+ad+"&MMdoctitle="+j.title;if(typeof ab.flashvars!=D){ab.flashvars+="&"+ac;
  28. }else{ab.flashvars=ac;}if(M.ie&&M.win&&ae.readyState!=4){var Y=C("div");X+="SWFObjectNew";Y.setAttribute("id",X);ae.parentNode.insertBefore(Y,ae);ae.style.display="none";
  29. (function(){if(ae.readyState==4){ae.parentNode.removeChild(ae);}else{setTimeout(arguments.callee,10);}})();}u(aa,ab,X);}}function p(Y){if(M.ie&&M.win&&Y.readyState!=4){var X=C("div");
  30. Y.parentNode.insertBefore(X,Y);X.parentNode.replaceChild(g(Y),X);Y.style.display="none";(function(){if(Y.readyState==4){Y.parentNode.removeChild(Y);}else{setTimeout(arguments.callee,10);
  31. }})();}else{Y.parentNode.replaceChild(g(Y),Y);}}function g(ab){var aa=C("div");if(M.win&&M.ie){aa.innerHTML=ab.innerHTML;}else{var Y=ab.getElementsByTagName(r)[0];
  32. if(Y){var ad=Y.childNodes;if(ad){var X=ad.length;for(var Z=0;Z<X;Z++){if(!(ad[Z].nodeType==1&&ad[Z].nodeName=="PARAM")&&!(ad[Z].nodeType==8)){aa.appendChild(ad[Z].cloneNode(true));
  33. }}}}}return aa;}function u(ai,ag,Y){var X,aa=c(Y);if(M.wk&&M.wk<312){return X;}if(aa){if(typeof ai.id==D){ai.id=Y;}if(M.ie&&M.win){var ah="";for(var ae in ai){if(ai[ae]!=Object.prototype[ae]){if(ae.toLowerCase()=="data"){ag.movie=ai[ae];
  34. }else{if(ae.toLowerCase()=="styleclass"){ah+=' class="'+ai[ae]+'"';}else{if(ae.toLowerCase()!="classid"){ah+=" "+ae+'="'+ai[ae]+'"';}}}}}var af="";for(var ad in ag){if(ag[ad]!=Object.prototype[ad]){af+='<param name="'+ad+'" value="'+ag[ad]+'" />';
  35. }}aa.outerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+ah+">"+af+"</object>";N[N.length]=ai.id;X=c(ai.id);}else{var Z=C(r);Z.setAttribute("type",q);
  36. for(var ac in ai){if(ai[ac]!=Object.prototype[ac]){if(ac.toLowerCase()=="styleclass"){Z.setAttribute("class",ai[ac]);}else{if(ac.toLowerCase()!="classid"){Z.setAttribute(ac,ai[ac]);
  37. }}}}for(var ab in ag){if(ag[ab]!=Object.prototype[ab]&&ab.toLowerCase()!="movie"){e(Z,ab,ag[ab]);}}aa.parentNode.replaceChild(Z,aa);X=Z;}}return X;}function e(Z,X,Y){var aa=C("param");
  38. aa.setAttribute("name",X);aa.setAttribute("value",Y);Z.appendChild(aa);}function y(Y){var X=c(Y);if(X&&X.nodeName=="OBJECT"){if(M.ie&&M.win){X.style.display="none";
  39. (function(){if(X.readyState==4){b(Y);}else{setTimeout(arguments.callee,10);}})();}else{X.parentNode.removeChild(X);}}}function b(Z){var Y=c(Z);if(Y){for(var X in Y){if(typeof Y[X]=="function"){Y[X]=null;
  40. }}Y.parentNode.removeChild(Y);}}function c(Z){var X=null;try{X=j.getElementById(Z);}catch(Y){}return X;}function C(X){return j.createElement(X);}function i(Z,X,Y){Z.attachEvent(X,Y);
  41. I[I.length]=[Z,X,Y];}function F(Z){var Y=M.pv,X=Z.split(".");X[0]=parseInt(X[0],10);X[1]=parseInt(X[1],10)||0;X[2]=parseInt(X[2],10)||0;return(Y[0]>X[0]||(Y[0]==X[0]&&Y[1]>X[1])||(Y[0]==X[0]&&Y[1]==X[1]&&Y[2]>=X[2]))?true:false;
  42. }function v(ac,Y,ad,ab){if(M.ie&&M.mac){return;}var aa=j.getElementsByTagName("head")[0];if(!aa){return;}var X=(ad&&typeof ad=="string")?ad:"screen";if(ab){n=null;
  43. G=null;}if(!n||G!=X){var Z=C("style");Z.setAttribute("type","text/css");Z.setAttribute("media",X);n=aa.appendChild(Z);if(M.ie&&M.win&&typeof j.styleSheets!=D&&j.styleSheets.length>0){n=j.styleSheets[j.styleSheets.length-1];
  44. }G=X;}if(M.ie&&M.win){if(n&&typeof n.addRule==r){n.addRule(ac,Y);}}else{if(n&&typeof j.createTextNode!=D){n.appendChild(j.createTextNode(ac+" {"+Y+"}"));
  45. }}}function w(Z,X){if(!m){return;}var Y=X?"visible":"hidden";if(J&&c(Z)){c(Z).style.visibility=Y;}else{v("#"+Z,"visibility:"+Y);}}function L(Y){var Z=/[\\\"<>\.;]/;
  46. var X=Z.exec(Y)!=null;return X&&typeof encodeURIComponent!=D?encodeURIComponent(Y):Y;}var d=function(){if(M.ie&&M.win){window.attachEvent("onunload",function(){var ac=I.length;
  47. for(var ab=0;ab<ac;ab++){I[ab][0].detachEvent(I[ab][1],I[ab][2]);}var Z=N.length;for(var aa=0;aa<Z;aa++){y(N[aa]);}for(var Y in M){M[Y]=null;}M=null;for(var X in swfobject){swfobject[X]=null;
  48. }swfobject=null;});}}();return{registerObject:function(ab,X,aa,Z){if(M.w3&&ab&&X){var Y={};Y.id=ab;Y.swfVersion=X;Y.expressInstall=aa;Y.callbackFn=Z;o[o.length]=Y;
  49. w(ab,false);}else{if(Z){Z({success:false,id:ab});}}},getObjectById:function(X){if(M.w3){return z(X);}},embedSWF:function(ab,ah,ae,ag,Y,aa,Z,ad,af,ac){var X={success:false,id:ah};
  50. if(M.w3&&!(M.wk&&M.wk<312)&&ab&&ah&&ae&&ag&&Y){w(ah,false);K(function(){ae+="";ag+="";var aj={};if(af&&typeof af===r){for(var al in af){aj[al]=af[al];}}aj.data=ab;
  51. aj.width=ae;aj.height=ag;var am={};if(ad&&typeof ad===r){for(var ak in ad){am[ak]=ad[ak];}}if(Z&&typeof Z===r){for(var ai in Z){if(typeof am.flashvars!=D){am.flashvars+="&"+ai+"="+Z[ai];
  52. }else{am.flashvars=ai+"="+Z[ai];}}}if(F(Y)){var an=u(aj,am,ah);if(aj.id==ah){w(ah,true);}X.success=true;X.ref=an;}else{if(aa&&A()){aj.data=aa;P(aj,am,ah,ac);
  53. return;}else{w(ah,true);}}if(ac){ac(X);}});}else{if(ac){ac(X);}}},switchOffAutoHideShow:function(){m=false;},ua:M,getFlashPlayerVersion:function(){return{major:M.pv[0],minor:M.pv[1],release:M.pv[2]};
  54. },hasFlashPlayerVersion:F,createSWF:function(Z,Y,X){if(M.w3){return u(Z,Y,X);}else{return undefined;}},showExpressInstall:function(Z,aa,X,Y){if(M.w3&&A()){P(Z,aa,X,Y);
  55. }},removeSWF:function(X){if(M.w3){y(X);}},createCSS:function(aa,Z,Y,X){if(M.w3){v(aa,Z,Y,X);}},addDomLoadEvent:K,addLoadEvent:s,getQueryParamValue:function(aa){var Z=j.location.search||j.location.hash;
  56. if(Z){if(/\?/.test(Z)){Z=Z.split("?")[1];}if(aa==null){return L(Z);}var Y=Z.split("&");for(var X=0;X<Y.length;X++){if(Y[X].substring(0,Y[X].indexOf("="))==aa){return L(Y[X].substring((Y[X].indexOf("=")+1)));
  57. }}}return"";},expressInstallCallback:function(){if(a){var X=c(R);if(X&&l){X.parentNode.replaceChild(l,X);if(Q){w(Q,true);if(M.ie&&M.win){l.style.display="block";
  58. }}if(E){E(B);}}a=false;}}};}();
  59. /*
  60. SWFUpload: http://www.swfupload.org, http://swfupload.googlecode.com
  61. mmSWFUpload 1.0: Flash upload dialog - http://profandesign.se/swfupload/, http://www.vinterwebb.se/
  62. SWFUpload is (c) 2006-2007 Lars Huring, Olov Nilzén and Mammon Media and is released under the MIT License:
  63. http://www.opensource.org/licenses/mit-license.php
  64. SWFUpload 2 is (c) 2007-2008 Jake Roberts and is released under the MIT License:
  65. http://www.opensource.org/licenses/mit-license.php
  66. */
  67. 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.but
  68. /*
  69. Uploadify v3.2.1
  70. Copyright (c) 2012 Reactive Apps, Ronnie Garcia
  71. Released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
  72. */
  73. (function($) {
  74. // These methods can be called by adding them as the first argument in the uploadify plugin call
  75. var methods = {
  76. init : function(options, swfUploadOptions) {
  77. return this.each(function() {
  78. // Create a reference to the jQuery DOM object
  79. var $this = $(this);
  80. // Clone the original DOM object
  81. var $clone = $this.clone();
  82. // Setup the default options
  83. var settings = $.extend({
  84. // Required Settings
  85. id : $this.attr('id'), // The ID of the DOM object
  86. swf : 'uploadify.swf', // The path to the uploadify SWF file
  87. uploader : 'uploadify.php', // The path to the server-side upload script
  88. // Options
  89. auto : true, // Automatically upload files when added to the queue
  90. buttonClass : '', // A class name to add to the browse button DOM object
  91. buttonCursor : 'hand', // The cursor to use with the browse button
  92. buttonImage : null, // (String or null) The path to an image to use for the Flash browse button if not using CSS to style the button
  93. buttonText : 'SELECT FILES', // The text to use for the browse button
  94. checkExisting : false, // The path to a server-side script that checks for existing files on the server
  95. debug : false, // Turn on swfUpload debugging mode
  96. fileObjName : 'Filedata', // The name of the file object to use in your server-side script
  97. fileSizeLimit : 0, // The maximum size of an uploadable file in KB (Accepts units B KB MB GB if string, 0 for no limit)
  98. fileTypeDesc : 'All Files', // The description for file types in the browse dialog
  99. fileTypeExts : '*.*', // Allowed extensions in the browse dialog (server-side validation should also be used)
  100. height : 30, // The height of the browse button
  101. itemTemplate : false, // The template for the file item in the queue
  102. method : 'post', // The method to use when sending files to the server-side upload script
  103. multi : true, // Allow multiple file selection in the browse dialog
  104. formData : {}, // An object with additional data to send to the server-side upload script with every file upload
  105. preventCaching : true, // Adds a random value to the Flash URL to prevent caching of it (conflicts with existing parameters)
  106. progressData : 'percentage', // ('percentage' or 'speed') Data to show in the queue item during a file upload
  107. queueID : false, // The ID of the DOM object to use as a file queue (without the #)
  108. queueSizeLimit : 999, // The maximum number of files that can be in the queue at one time
  109. removeCompleted : true, // Remove queue items from the queue when they are done uploading
  110. removeTimeout : 3, // The delay in seconds before removing a queue item if removeCompleted is set to true
  111. requeueErrors : false, // Keep errored files in the queue and keep trying to upload them
  112. successTimeout : 30, // The number of seconds to wait for Flash to detect the server's response after the file has finished uploading
  113. uploadLimit : 0, // The maximum number of files you can upload
  114. width : 120, // The width of the browse button
  115. // Events
  116. overrideEvents : [] // (Array) A list of default event handlers to skip
  117. /*
  118. onCancel // Triggered when a file is cancelled from the queue
  119. onClearQueue // Triggered during the 'clear queue' method
  120. onDestroy // Triggered when the uploadify object is destroyed
  121. onDialogClose // Triggered when the browse dialog is closed
  122. onDialogOpen // Triggered when the browse dialog is opened
  123. onDisable // Triggered when the browse button gets disabled
  124. onEnable // Triggered when the browse button gets enabled
  125. onFallback // Triggered is Flash is not detected
  126. onInit // Triggered when Uploadify is initialized
  127. onQueueComplete // Triggered when all files in the queue have been uploaded
  128. onSelectError // Triggered when an error occurs while selecting a file (file size, queue size limit, etc.)
  129. onSelect // Triggered for each file that is selected
  130. onSWFReady // Triggered when the SWF button is loaded
  131. onUploadComplete // Triggered when a file upload completes (success or error)
  132. onUploadError // Triggered when a file upload returns an error
  133. onUploadSuccess // Triggered when a file is uploaded successfully
  134. onUploadProgress // Triggered every time a file progress is updated
  135. onUploadStart // Triggered immediately before a file upload starts
  136. */
  137. }, options);
  138. // Prepare settings for SWFUpload
  139. var swfUploadSettings = {
  140. assume_success_timeout : settings.successTimeout,
  141. button_placeholder_id : settings.id,
  142. button_width : settings.width,
  143. button_height : settings.height,
  144. button_text : null,
  145. button_text_style : null,
  146. button_text_top_padding : 0,
  147. button_text_left_padding : 0,
  148. button_action : (settings.multi ? SWFUpload.BUTTON_ACTION.SELECT_FILES : SWFUpload.BUTTON_ACTION.SELECT_FILE),
  149. button_disabled : false,
  150. button_cursor : (settings.buttonCursor == 'arrow' ? SWFUpload.CURSOR.ARROW : SWFUpload.CURSOR.HAND),
  151. button_window_mode : SWFUpload.WINDOW_MODE.TRANSPARENT,
  152. debug : settings.debug,
  153. requeue_on_error : settings.requeueErrors,
  154. file_post_name : settings.fileObjName,
  155. file_size_limit : settings.fileSizeLimit,
  156. file_types : settings.fileTypeExts,
  157. file_types_description : settings.fileTypeDesc,
  158. file_queue_limit : settings.queueSizeLimit,
  159. file_upload_limit : settings.uploadLimit,
  160. flash_url : settings.swf,
  161. prevent_swf_caching : settings.preventCaching,
  162. post_params : settings.formData,
  163. upload_url : settings.uploader,
  164. use_query_string : (settings.method == 'get'),
  165. // Event Handlers
  166. file_dialog_complete_handler : handlers.onDialogClose,
  167. file_dialog_start_handler : handlers.onDialogOpen,
  168. file_queued_handler : handlers.onSelect,
  169. file_queue_error_handler : handlers.onSelectError,
  170. swfupload_loaded_handler : settings.onSWFReady,
  171. upload_complete_handler : handlers.onUploadComplete,
  172. upload_error_handler : handlers.onUploadError,
  173. upload_progress_handler : handlers.onUploadProgress,
  174. upload_start_handler : handlers.onUploadStart,
  175. upload_success_handler : handlers.onUploadSuccess
  176. }
  177. // Merge the user-defined options with the defaults
  178. if (swfUploadOptions) {
  179. swfUploadSettings = $.extend(swfUploadSettings, swfUploadOptions);
  180. }
  181. // Add the user-defined settings to the swfupload object
  182. swfUploadSettings = $.extend(swfUploadSettings, settings);
  183. // Detect if Flash is available
  184. var playerVersion = swfobject.getFlashPlayerVersion();
  185. var flashInstalled = (playerVersion.major >= 9);
  186. if (flashInstalled) {
  187. // Create the swfUpload instance
  188. window['uploadify_' + settings.id] = new SWFUpload(swfUploadSettings);
  189. var swfuploadify = window['uploadify_' + settings.id];
  190. // Add the SWFUpload object to the elements data object
  191. $this.data('uploadify', swfuploadify);
  192. // Wrap the instance
  193. var $wrapper = $('<div />', {
  194. 'id' : settings.id,
  195. 'class' : 'uploadify',
  196. 'css' : {
  197. 'height' : settings.height + 'px',
  198. 'width' : settings.width + 'px'
  199. }
  200. });
  201. $('#' + swfuploadify.movieName).wrap($wrapper);
  202. // Recreate the reference to wrapper
  203. $wrapper = $('#' + settings.id);
  204. // Add the data object to the wrapper
  205. $wrapper.data('uploadify', swfuploadify);
  206. // Create the button
  207. var $button = $('<div />', {
  208. 'id' : settings.id + '-button',
  209. 'class' : 'uploadify-button ' + settings.buttonClass
  210. });
  211. if (settings.buttonImage) {
  212. $button.css({
  213. 'background-image' : "url('" + settings.buttonImage + "')",
  214. 'text-indent' : '-9999px'
  215. });
  216. }
  217. $button.html('<span class="uploadify-button-text">' + settings.buttonText + '</span>')
  218. .css({
  219. 'height' : settings.height + 'px',
  220. 'line-height' : settings.height + 'px',
  221. 'width' : settings.width + 'px'
  222. });
  223. // Append the button to the wrapper
  224. $wrapper.append($button);
  225. // Adjust the styles of the movie
  226. $('#' + swfuploadify.movieName).css({
  227. 'position' : 'absolute',
  228. 'z-index' : 1
  229. });
  230. // Create the file queue
  231. if (!settings.queueID) {
  232. var $queue = $('<div />', {
  233. 'id' : settings.id + '-queue',
  234. 'class' : 'uploadify-queue'
  235. });
  236. $wrapper.after($queue);
  237. swfuploadify.settings.queueID = settings.id + '-queue';
  238. swfuploadify.settings.defaultQueue = true;
  239. }
  240. // Create some queue related objects and variables
  241. swfuploadify.queueData = {
  242. files : {}, // The files in the queue
  243. filesSelected : 0, // The number of files selected in the last select operation
  244. filesQueued : 0, // The number of files added to the queue in the last select operation
  245. filesReplaced : 0, // The number of files replaced in the last select operation
  246. filesCancelled : 0, // The number of files that were cancelled instead of replaced
  247. filesErrored : 0, // The number of files that caused error in the last select operation
  248. uploadsSuccessful : 0, // The number of files that were successfully uploaded
  249. uploadsErrored : 0, // The number of files that returned errors during upload
  250. averageSpeed : 0, // The average speed of the uploads in KB
  251. queueLength : 0, // The number of files in the queue
  252. queueSize : 0, // The size in bytes of the entire queue
  253. uploadSize : 0, // The size in bytes of the upload queue
  254. queueBytesUploaded : 0, // The size in bytes that have been uploaded for the current upload queue
  255. uploadQueue : [], // The files currently to be uploaded
  256. errorMsg : 'Some files were not added to the queue:'
  257. };
  258. // Save references to all the objects
  259. swfuploadify.original = $clone;
  260. swfuploadify.wrapper = $wrapper;
  261. swfuploadify.button = $button;
  262. swfuploadify.queue = $queue;
  263. // Call the user-defined init event handler
  264. if (settings.onInit) settings.onInit.call($this, swfuploadify);
  265. } else {
  266. // Call the fallback function
  267. if (settings.onFallback) settings.onFallback.call($this);
  268. }
  269. });
  270. },
  271. // Stop a file upload and remove it from the queue
  272. cancel : function(fileID, supressEvent) {
  273. var args = arguments;
  274. this.each(function() {
  275. // Create a reference to the jQuery DOM object
  276. var $this = $(this),
  277. swfuploadify = $this.data('uploadify'),
  278. settings = swfuploadify.settings,
  279. delay = -1;
  280. if (args[0]) {
  281. // Clear the queue
  282. if (args[0] == '*') {
  283. var queueItemCount = swfuploadify.queueData.queueLength;
  284. $('#' + settings.queueID).find('.uploadify-queue-item').each(function() {
  285. delay++;
  286. if (args[1] === true) {
  287. swfuploadify.cancelUpload($(this).attr('id'), false);
  288. } else {
  289. swfuploadify.cancelUpload($(this).attr('id'));
  290. }
  291. $(this).find('.data').removeClass('data').html(' - Cancelled');
  292. $(this).find('.uploadify-progress-bar').remove();
  293. $(this).delay(1000 + 100 * delay).fadeOut(500, function() {
  294. $(this).remove();
  295. });
  296. });
  297. swfuploadify.queueData.queueSize = 0;
  298. swfuploadify.queueData.queueLength = 0;
  299. // Trigger the onClearQueue event
  300. if (settings.onClearQueue) settings.onClearQueue.call($this, queueItemCount);
  301. } else {
  302. for (var n = 0; n < args.length; n++) {
  303. swfuploadify.cancelUpload(args[n]);
  304. $('#' + args[n]).find('.data').removeClass('data').html(' - Cancelled');
  305. $('#' + args[n]).find('.uploadify-progress-bar').remove();
  306. $('#' + args[n]).delay(1000 + 100 * n).fadeOut(500, function() {
  307. $(this).remove();
  308. });
  309. }
  310. }
  311. } else {
  312. var item = $('#' + settings.queueID).find('.uploadify-queue-item').get(0);
  313. $item = $(item);
  314. swfuploadify.cancelUpload($item.attr('id'));
  315. $item.find('.data').removeClass('data').html(' - Cancelled');
  316. $item.find('.uploadify-progress-bar').remove();
  317. $item.delay(1000).fadeOut(500, function() {
  318. $(this).remove();
  319. });
  320. }
  321. });
  322. },
  323. // Revert the DOM object back to its original state
  324. destroy : function() {
  325. this.each(function() {
  326. // Create a reference to the jQuery DOM object
  327. var $this = $(this),
  328. swfuploadify = $this.data('uploadify'),
  329. settings = swfuploadify.settings;
  330. // Destroy the SWF object and
  331. swfuploadify.destroy();
  332. // Destroy the queue
  333. if (settings.defaultQueue) {
  334. $('#' + settings.queueID).remove();
  335. }
  336. // Reload the original DOM element
  337. $('#' + settings.id).replaceWith(swfuploadify.original);
  338. // Call the user-defined event handler
  339. if (settings.onDestroy) settings.onDestroy.call(this);
  340. delete swfuploadify;
  341. });
  342. },
  343. // Disable the select button
  344. disable : function(isDisabled) {
  345. this.each(function() {
  346. // Create a reference to the jQuery DOM object
  347. var $this = $(this),
  348. swfuploadify = $this.data('uploadify'),
  349. settings = swfuploadify.settings;
  350. // Call the user-defined event handlers
  351. if (isDisabled) {
  352. swfuploadify.button.addClass('disabled');
  353. if (settings.onDisable) settings.onDisable.call(this);
  354. } else {
  355. swfuploadify.button.removeClass('disabled');
  356. if (settings.onEnable) settings.onEnable.call(this);
  357. }
  358. // Enable/disable the browse button
  359. swfuploadify.setButtonDisabled(isDisabled);
  360. });
  361. },
  362. // Get or set the settings data
  363. settings : function(name, value, resetObjects) {
  364. var args = arguments;
  365. var returnValue = value;
  366. this.each(function() {
  367. // Create a reference to the jQuery DOM object
  368. var $this = $(this),
  369. swfuploadify = $this.data('uploadify'),
  370. settings = swfuploadify.settings;
  371. if (typeof(args[0]) == 'object') {
  372. for (var n in value) {
  373. setData(n,value[n]);
  374. }
  375. }
  376. if (args.length === 1) {
  377. returnValue = settings[name];
  378. } else {
  379. switch (name) {
  380. case 'uploader':
  381. swfuploadify.setUploadURL(value);
  382. break;
  383. case 'formData':
  384. if (!resetObjects) {
  385. value = $.extend(settings.formData, value);
  386. }
  387. swfuploadify.setPostParams(settings.formData);
  388. break;
  389. case 'method':
  390. if (value == 'get') {
  391. swfuploadify.setUseQueryString(true);
  392. } else {
  393. swfuploadify.setUseQueryString(false);
  394. }
  395. break;
  396. case 'fileObjName':
  397. swfuploadify.setFilePostName(value);
  398. break;
  399. case 'fileTypeExts':
  400. swfuploadify.setFileTypes(value, settings.fileTypeDesc);
  401. break;
  402. case 'fileTypeDesc':
  403. swfuploadify.setFileTypes(settings.fileTypeExts, value);
  404. break;
  405. case 'fileSizeLimit':
  406. swfuploadify.setFileSizeLimit(value);
  407. break;
  408. case 'uploadLimit':
  409. swfuploadify.setFileUploadLimit(value);
  410. break;
  411. case 'queueSizeLimit':
  412. swfuploadify.setFileQueueLimit(value);
  413. break;
  414. case 'buttonImage':
  415. swfuploadify.button.css('background-image', settingValue);
  416. break;
  417. case 'buttonCursor':
  418. if (value == 'arrow') {
  419. swfuploadify.setButtonCursor(SWFUpload.CURSOR.ARROW);
  420. } else {
  421. swfuploadify.setButtonCursor(SWFUpload.CURSOR.HAND);
  422. }
  423. break;
  424. case 'buttonText':
  425. $('#' + settings.id + '-button').find('.uploadify-button-text').html(value);
  426. break;
  427. case 'width':
  428. swfuploadify.setButtonDimensions(value, settings.height);
  429. break;
  430. case 'height':
  431. swfuploadify.setButtonDimensions(settings.width, value);
  432. break;
  433. case 'multi':
  434. if (value) {
  435. swfuploadify.setButtonAction(SWFUpload.BUTTON_ACTION.SELECT_FILES);
  436. } else {
  437. swfuploadify.setButtonAction(SWFUpload.BUTTON_ACTION.SELECT_FILE);
  438. }
  439. break;
  440. }
  441. settings[name] = value;
  442. }
  443. });
  444. if (args.length === 1) {
  445. return returnValue;
  446. }
  447. },
  448. // Stop the current uploads and requeue what is in progress
  449. stop : function() {
  450. this.each(function() {
  451. // Create a reference to the jQuery DOM object
  452. var $this = $(this),
  453. swfuploadify = $this.data('uploadify');
  454. // Reset the queue information
  455. swfuploadify.queueData.averageSpeed = 0;
  456. swfuploadify.queueData.uploadSize = 0;
  457. swfuploadify.queueData.bytesUploaded = 0;
  458. swfuploadify.queueData.uploadQueue = [];
  459. swfuploadify.stopUpload();
  460. });
  461. },
  462. // Start uploading files in the queue
  463. upload : function() {
  464. var args = arguments;
  465. this.each(function() {
  466. // Create a reference to the jQuery DOM object
  467. var $this = $(this),
  468. swfuploadify = $this.data('uploadify');
  469. // Reset the queue information
  470. swfuploadify.queueData.averageSpeed = 0;
  471. swfuploadify.queueData.uploadSize = 0;
  472. swfuploadify.queueData.bytesUploaded = 0;
  473. swfuploadify.queueData.uploadQueue = [];
  474. // Upload the files
  475. if (args[0]) {
  476. if (args[0] == '*') {
  477. swfuploadify.queueData.uploadSize = swfuploadify.queueData.queueSize;
  478. swfuploadify.queueData.uploadQueue.push('*');
  479. swfuploadify.startUpload();
  480. } else {
  481. for (var n = 0; n < args.length; n++) {
  482. swfuploadify.queueData.uploadSize += swfuploadify.queueData.files[args[n]].size;
  483. swfuploadify.queueData.uploadQueue.push(args[n]);
  484. }
  485. swfuploadify.startUpload(swfuploadify.queueData.uploadQueue.shift());
  486. }
  487. } else {
  488. swfuploadify.startUpload();
  489. }
  490. });
  491. }
  492. }
  493. // These functions handle all the events that occur with the file uploader
  494. var handlers = {
  495. // Triggered when the file dialog is opened
  496. onDialogOpen : function() {
  497. // Load the swfupload settings
  498. var settings = this.settings;
  499. // Reset some queue info
  500. this.queueData.errorMsg = 'Some files were not added to the queue:';
  501. this.queueData.filesReplaced = 0;
  502. this.queueData.filesCancelled = 0;
  503. // Call the user-defined event handler
  504. if (settings.onDialogOpen) settings.onDialogOpen.call(this);
  505. },
  506. // Triggered when the browse dialog is closed
  507. onDialogClose : function(filesSelected, filesQueued, queueLength) {
  508. // Load the swfupload settings
  509. var settings = this.settings;
  510. // Update the queue information
  511. this.queueData.filesErrored = filesSelected - filesQueued;
  512. this.queueData.filesSelected = filesSelected;
  513. this.queueData.filesQueued = filesQueued - this.queueData.filesCancelled;
  514. this.queueData.queueLength = queueLength;
  515. // Run the default event handler
  516. if ($.inArray('onDialogClose', settings.overrideEvents) < 0) {
  517. if (this.queueData.filesErrored > 0) {
  518. alert(this.queueData.errorMsg);
  519. }
  520. }
  521. // Call the user-defined event handler
  522. if (settings.onDialogClose) settings.onDialogClose.call(this, this.queueData);
  523. // Upload the files if auto is true
  524. if (settings.auto) $('#' + settings.id).uploadify('upload', '*');
  525. },
  526. // Triggered once for each file added to the queue
  527. onSelect : function(file) {
  528. // Load the swfupload settings
  529. var settings = this.settings;
  530. // Check if a file with the same name exists in the queue
  531. var queuedFile = {};
  532. for (var n in this.queueData.files) {
  533. queuedFile = this.queueData.files[n];
  534. if (queuedFile.uploaded != true && queuedFile.name == file.name) {
  535. var replaceQueueItem = confirm('The file named "' + file.name + '" is already in the queue.\nDo you want to replace the existing item in the queue?');
  536. if (!replaceQueueItem) {
  537. this.cancelUpload(file.id);
  538. this.queueData.filesCancelled++;
  539. return false;
  540. } else {
  541. $('#' + queuedFile.id).remove();
  542. this.cancelUpload(queuedFile.id);
  543. this.queueData.filesReplaced++;
  544. }
  545. }
  546. }
  547. // Get the size of the file
  548. var fileSize = Math.round(file.size / 1024);
  549. var suffix = 'KB';
  550. if (fileSize > 1000) {
  551. fileSize = Math.round(fileSize / 1000);
  552. suffix = 'MB';
  553. }
  554. var fileSizeParts = fileSize.toString().split('.');
  555. fileSize = fileSizeParts[0];
  556. if (fileSizeParts.length > 1) {
  557. fileSize += '.' + fileSizeParts[1].substr(0,2);
  558. }
  559. fileSize += suffix;
  560. // Truncate the filename if it's too long
  561. var fileName = file.name;
  562. if (fileName.length > 25) {
  563. fileName = fileName.substr(0,25) + '...';
  564. }
  565. // Create the file data object
  566. itemData = {
  567. 'fileID' : file.id,
  568. 'instanceID' : settings.id,
  569. 'fileName' : fileName,
  570. 'fileSize' : fileSize
  571. }
  572. // Create the file item template
  573. if (settings.itemTemplate == false) {
  574. settings.itemTemplate = '<div id="${fileID}" class="uploadify-queue-item">\
  575. <div class="cancel">\
  576. <a href="javascript:$(\'#${instanceID}\').uploadify(\'cancel\', \'${fileID}\')">X</a>\
  577. </div>\
  578. <span class="fileName">${fileName} (${fileSize})</span><span class="data"></span>\
  579. <div class="uploadify-progress">\
  580. <div class="uploadify-progress-bar"><!--Progress Bar--></div>\
  581. </div>\
  582. </div>';
  583. }
  584. // Run the default event handler
  585. if ($.inArray('onSelect', settings.overrideEvents) < 0) {
  586. // Replace the item data in the template
  587. itemHTML = settings.itemTemplate;
  588. for (var d in itemData) {
  589. itemHTML = itemHTML.replace(new RegExp('\\$\\{' + d + '\\}', 'g'), itemData[d]);
  590. }
  591. // Add the file item to the queue
  592. $('#' + settings.queueID).append(itemHTML);
  593. }
  594. this.queueData.queueSize += file.size;
  595. this.queueData.files[file.id] = file;
  596. // Call the user-defined event handler
  597. if (settings.onSelect) settings.onSelect.apply(this, arguments);
  598. },
  599. // Triggered when a file is not added to the queue
  600. onSelectError : function(file, errorCode, errorMsg) {
  601. // Load the swfupload settings
  602. var settings = this.settings;
  603. // Run the default event handler
  604. if ($.inArray('onSelectError', settings.overrideEvents) < 0) {
  605. switch(errorCode) {
  606. case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
  607. if (settings.queueSizeLimit > errorMsg) {
  608. this.queueData.errorMsg += '\nThe number of files selected exceeds the remaining upload limit (' + errorMsg + ').';
  609. } else {
  610. this.queueData.errorMsg += '\nThe number of files selected exceeds the queue size limit (' + settings.queueSizeLimit + ').';
  611. }
  612. break;
  613. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  614. this.queueData.errorMsg += '\nThe file "' + file.name + '" exceeds the size limit (' + settings.fileSizeLimit + ').';
  615. break;
  616. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  617. this.queueData.errorMsg += '\nThe file "' + file.name + '" is empty.';
  618. break;
  619. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  620. this.queueData.errorMsg += '\nThe file "' + file.name + '" is not an accepted file type (' + settings.fileTypeDesc + ').';
  621. break;
  622. }
  623. }
  624. if (errorCode != SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED) {
  625. delete this.queueData.files[file.id];
  626. }
  627. // Call the user-defined event handler
  628. if (settings.onSelectError) settings.onSelectError.apply(this, arguments);
  629. },
  630. // Triggered when all the files in the queue have been processed
  631. onQueueComplete : function() {
  632. if (this.settings.onQueueComplete) this.settings.onQueueComplete.call(this, this.settings.queueData);
  633. },
  634. // Triggered when a file upload successfully completes
  635. onUploadComplete : function(file) {
  636. // Load the swfupload settings
  637. var settings = this.settings,
  638. swfuploadify = this;
  639. // Check if all the files have completed uploading
  640. var stats = this.getStats();
  641. this.queueData.queueLength = stats.files_queued;
  642. if (this.queueData.uploadQueue[0] == '*') {
  643. if (this.queueData.queueLength > 0) {
  644. this.startUpload();
  645. } else {
  646. this.queueData.uploadQueue = [];
  647. // Call the user-defined event handler for queue complete
  648. if (settings.onQueueComplete) settings.onQueueComplete.call(this, this.queueData);
  649. }
  650. } else {
  651. if (this.queueData.uploadQueue.length > 0) {
  652. this.startUpload(this.queueData.uploadQueue.shift());
  653. } else {
  654. this.queueData.uploadQueue = [];
  655. // Call the user-defined event handler for queue complete
  656. if (settings.onQueueComplete) settings.onQueueComplete.call(this, this.queueData);
  657. }
  658. }
  659. // Call the default event handler
  660. if ($.inArray('onUploadComplete', settings.overrideEvents) < 0) {
  661. if (settings.removeCompleted) {
  662. switch (file.filestatus) {
  663. case SWFUpload.FILE_STATUS.COMPLETE:
  664. setTimeout(function() {
  665. if ($('#' + file.id)) {
  666. swfuploadify.queueData.queueSize -= file.size;
  667. swfuploadify.queueData.queueLength -= 1;
  668. delete swfuploadify.queueData.files[file.id]
  669. $('#' + file.id).fadeOut(500, function() {
  670. $(this).remove();
  671. });
  672. }
  673. }, settings.removeTimeout * 1000);
  674. break;
  675. case SWFUpload.FILE_STATUS.ERROR:
  676. if (!settings.requeueErrors) {
  677. setTimeout(function() {
  678. if ($('#' + file.id)) {
  679. swfuploadify.queueData.queueSize -= file.size;
  680. swfuploadify.queueData.queueLength -= 1;
  681. delete swfuploadify.queueData.files[file.id];
  682. $('#' + file.id).fadeOut(500, function() {
  683. $(this).remove();
  684. });
  685. }
  686. }, settings.removeTimeout * 1000);
  687. }
  688. break;
  689. }
  690. } else {
  691. file.uploaded = true;
  692. }
  693. }
  694. // Call the user-defined event handler
  695. if (settings.onUploadComplete) settings.onUploadComplete.call(this, file);
  696. },
  697. // Triggered when a file upload returns an error
  698. onUploadError : function(file, errorCode, errorMsg) {
  699. // Load the swfupload settings
  700. var settings = this.settings;
  701. // Set the error string
  702. var errorString = 'Error';
  703. switch(errorCode) {
  704. case SWFUpload.UPLOAD_ERROR.HTTP_ERROR:
  705. errorString = 'HTTP Error (' + errorMsg + ')';
  706. break;
  707. case SWFUpload.UPLOAD_ERROR.MISSING_UPLOAD_URL:
  708. errorString = 'Missing Upload URL';
  709. break;
  710. case SWFUpload.UPLOAD_ERROR.IO_ERROR:
  711. errorString = 'IO Error';
  712. break;
  713. case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR:
  714. errorString = 'Security Error';
  715. break;
  716. case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
  717. alert('The upload limit has been reached (' + errorMsg + ').');
  718. errorString = 'Exceeds Upload Limit';
  719. break;
  720. case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED:
  721. errorString = 'Failed';
  722. break;
  723. case SWFUpload.UPLOAD_ERROR.SPECIFIED_FILE_ID_NOT_FOUND:
  724. break;
  725. case SWFUpload.UPLOAD_ERROR.FILE_VALIDATION_FAILED:
  726. errorString = 'Validation Error';
  727. break;
  728. case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
  729. errorString = 'Cancelled';
  730. this.queueData.queueSize -= file.size;
  731. this.queueData.queueLength -= 1;
  732. if (file.status == SWFUpload.FILE_STATUS.IN_PROGRESS || $.inArray(file.id, this.queueData.uploadQueue) >= 0) {
  733. this.queueData.uploadSize -= file.size;
  734. }
  735. // Trigger the onCancel event
  736. if (settings.onCancel) settings.onCancel.call(this, file);
  737. delete this.queueData.files[file.id];
  738. break;
  739. case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
  740. errorString = 'Stopped';
  741. break;
  742. }
  743. // Call the default event handler
  744. if ($.inArray('onUploadError', settings.overrideEvents) < 0) {
  745. if (errorCode != SWFUpload.UPLOAD_ERROR.FILE_CANCELLED && errorCode != SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED) {
  746. $('#' + file.id).addClass('uploadify-error');
  747. }
  748. // Reset the progress bar
  749. $('#' + file.id).find('.uploadify-progress-bar').css('width','1px');
  750. // Add the error message to the queue item
  751. if (errorCode != SWFUpload.UPLOAD_ERROR.SPECIFIED_FILE_ID_NOT_FOUND && file.status != SWFUpload.FILE_STATUS.COMPLETE) {
  752. $('#' + file.id).find('.data').html(' - ' + errorString);
  753. }
  754. }
  755. var stats = this.getStats();
  756. this.queueData.uploadsErrored = stats.upload_errors;
  757. // Call the user-defined event handler
  758. if (settings.onUploadError) settings.onUploadError.call(this, file, errorCode, errorMsg, errorString);
  759. },
  760. // Triggered periodically during a file upload
  761. onUploadProgress : function(file, fileBytesLoaded, fileTotalBytes) {
  762. // Load the swfupload settings
  763. var settings = this.settings;
  764. // Setup all the variables
  765. var timer = new Date();
  766. var newTime = timer.getTime();
  767. var lapsedTime = newTime - this.timer;
  768. if (lapsedTime > 500) {
  769. this.timer = newTime;
  770. }
  771. var lapsedBytes = fileBytesLoaded - this.bytesLoaded;
  772. this.bytesLoaded = fileBytesLoaded;
  773. var queueBytesLoaded = this.queueData.queueBytesUploaded + fileBytesLoaded;
  774. var percentage = Math.round(fileBytesLoaded / fileTotalBytes * 100);
  775. // Calculate the average speed
  776. var suffix = 'KB/s';
  777. var mbs = 0;
  778. var kbs = (lapsedBytes / 1024) / (lapsedTime / 1000);
  779. kbs = Math.floor(kbs * 10) / 10;
  780. if (this.queueData.averageSpeed > 0) {
  781. this.queueData.averageSpeed = Math.floor((this.queueData.averageSpeed + kbs) / 2);
  782. } else {
  783. this.queueData.averageSpeed = Math.floor(kbs);
  784. }
  785. if (kbs > 1000) {
  786. mbs = (kbs * .001);
  787. this.queueData.averageSpeed = Math.floor(mbs);
  788. suffix = 'MB/s';
  789. }
  790. // Call the default event handler
  791. if ($.inArray('onUploadProgress', settings.overrideEvents) < 0) {
  792. if (settings.progressData == 'percentage') {
  793. $('#' + file.id).find('.data').html(' - ' + percentage + '%');
  794. } else if (settings.progressData == 'speed' && lapsedTime > 500) {
  795. $('#' + file.id).find('.data').html(' - ' + this.queueData.averageSpeed + suffix);
  796. }
  797. $('#' + file.id).find('.uploadify-progress-bar').css('width', percentage + '%');
  798. }
  799. // Call the user-defined event handler
  800. if (settings.onUploadProgress) settings.onUploadProgress.call(this, file, fileBytesLoaded, fileTotalBytes, queueBytesLoaded, this.queueData.uploadSize);
  801. },
  802. // Triggered right before a file is uploaded
  803. onUploadStart : function(file) {
  804. // Load the swfupload settings
  805. var settings = this.settings;
  806. var timer = new Date();
  807. this.timer = timer.getTime();
  808. this.bytesLoaded = 0;
  809. if (this.queueData.uploadQueue.length == 0) {
  810. this.queueData.uploadSize = file.size;
  811. }
  812. if (settings.checkExisting) {
  813. $.ajax({
  814. type : 'POST',
  815. async : false,
  816. url : settings.checkExisting,
  817. data : {filename: file.name},
  818. success : function(data) {
  819. if (data == 1) {
  820. var overwrite = confirm('A file with the name "' + file.name + '" already exists on the server.\nWould you like to replace the existing file?');
  821. if (!overwrite) {
  822. this.cancelUpload(file.id);
  823. $('#' + file.id).remove();
  824. if (this.queueData.uploadQueue.length > 0 && this.queueData.queueLength > 0) {
  825. if (this.queueData.uploadQueue[0] == '*') {
  826. this.startUpload();
  827. } else {
  828. this.startUpload(this.queueData.uploadQueue.shift());
  829. }
  830. }
  831. }
  832. }
  833. }
  834. });
  835. }
  836. // Call the user-defined event handler
  837. if (settings.onUploadStart) settings.onUploadStart.call(this, file);
  838. },
  839. // Triggered when a file upload returns a successful code
  840. onUploadSuccess : function(file, data, response) {
  841. // Load the swfupload settings
  842. var settings = this.settings;
  843. var stats = this.getStats();
  844. this.queueData.uploadsSuccessful = stats.successful_uploads;
  845. this.queueData.queueBytesUploaded += file.size;
  846. // Call the default event handler
  847. if ($.inArray('onUploadSuccess', settings.overrideEvents) < 0) {
  848. $('#' + file.id).find('.data').html(' - Complete');
  849. }
  850. // Call the user-defined event handler
  851. if (settings.onUploadSuccess) settings.onUploadSuccess.call(this, file, data, response);
  852. }
  853. }
  854. $.fn.uploadify = function(method) {
  855. if (methods[method]) {
  856. return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
  857. } else if (typeof method === 'object' || !method) {
  858. return methods.init.apply(this, arguments);
  859. } else {
  860. $.error('The method ' + method + ' does not exist in $.uploadify');
  861. }
  862. }
  863. })($);