first commit
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
if(false==class_exists('xajaxPlugin')||false==class_exists('xajaxPluginManager')){$sBaseFolder=dirname(dirname(dirname(__FILE__)));$sXajaxCore=$sBaseFolder.'/xajax_core';if(false==class_exists('xajaxPlugin'))
|
||||
require $sXajaxCore.'/xajaxPlugin.inc.php';if(false==class_exists('xajaxPluginManager'))
|
||||
require $sXajaxCore.'/xajaxPluginManager.inc.php';}
|
||||
class clsSwfUpload
|
||||
extends xajaxResponsePlugin{private $sCallName="SWFUpload";private $sDefer;private $sJavascriptURI;private $bInlineScript;private $SWFupload_FadeTimeOut=1500;private $sRequestedFunction=NULL;private $sXajaxPrefix="xajax_";public function clsSwfUpload(){$this->sDefer='';$this->sJavascriptURI='';$this->bInlineScript=false;}
|
||||
function getName(){return get_class($this);}
|
||||
public function configure($sName,$mValue){switch($sName){case 'scriptDeferral':
|
||||
if(true===$mValue||false===$mValue){if($mValue)
|
||||
$this->sDefer='defer ';else
|
||||
$this->sDefer='';}
|
||||
break;case 'javascript URI':
|
||||
$this->sJavascriptURI=$mValue;break;case 'inlineScript':
|
||||
if(true===$mValue||false===$mValue)
|
||||
$this->bInlineScript=$mValue;break;case 'SWFupload_FadeTimeOut':
|
||||
if(is_numeric($mValue))
|
||||
$this->SWFupload_FadeTimeOut=$mValue;break;}
|
||||
}
|
||||
public function generateClientScript(){echo "\n<script type='text/javascript' ".$this->sDefer."charset='UTF-8'>\n";echo "/* <![CDATA[ */\n";echo "if (undefined == xajax.ext) xajax.ext = {};\n";echo "xajax.ext.SWFupload = {};";echo "xajax.ext.SWFupload.config = {};\n";echo "xajax.ext.SWFupload.config.javascript_URI='".$this->sJavascriptURI."xajax_plugins/response/swfupload/';\n";echo "xajax.ext.SWFupload.config.FadeTimeOut = '".$this->SWFupload_FadeTimeOut."';\n";echo "/* ]]> */\n";echo "</script>\n";if($this->bInlineScript){echo "\n<script type='text/javascript' ".$this->sDefer."charset='UTF-8'>\n";echo "/* <![CDATA[ */\n";include(dirname(__FILE__).'xajax_plugins/response/swfupload/swfupload.js');include(dirname(__FILE__).'xajax_plugins/response/swfupload/swfupload.xajax.js');echo "/* ]]> */\n";echo "</script>\n";}else{echo "\n<script type='text/javascript' src='".$this->sJavascriptURI."xajax_plugins/response/swfupload/swfupload.js' ".$this->sDefer."charset='UTF-8'></script>\n";echo "\n<script type='text/javascript' src='".$this->sJavascriptURI."xajax_plugins/response/swfupload/swfupload.xajax.js' ".$this->sDefer."charset='UTF-8'></script>\n";}
|
||||
}
|
||||
function transForm($id,$config,$multi=false){$command=array
|
||||
(
|
||||
'cmd'=> 'SWFup_tfo',
|
||||
'id'=> $id
|
||||
);$this->addCommand($command,array
|
||||
(
|
||||
"config"=> $config,
|
||||
"multi"=> $multi
|
||||
));}
|
||||
function transField($id,$config,$multi=false){$command=array
|
||||
(
|
||||
'cmd'=> 'SWFup_tfi',
|
||||
'id'=> $id
|
||||
);$this->addCommand($command,array
|
||||
(
|
||||
"config"=> $config,
|
||||
"multi"=> $multi
|
||||
));}
|
||||
function destroyField($id){$command=array
|
||||
(
|
||||
'cmd'=> 'SWFup_dfi',
|
||||
'id'=> $id
|
||||
);$this->addCommand($command,array());}
|
||||
function destroyForm($id){$command=array
|
||||
(
|
||||
'cmd'=> 'SWFup_dfo',
|
||||
'id'=> $id
|
||||
);$this->addCommand($command,array());}
|
||||
}
|
||||
$objPluginManager=&xajaxPluginManager::getInstance();$objPluginManager->registerPlugin(new clsSwfUpload(),100);?>
|
||||
151
resources/xajax/xajax_plugins/response/swfupload/swfupload.js
Normal file
151
resources/xajax/xajax_plugins/response/swfupload/swfupload.js
Normal file
@@ -0,0 +1,151 @@
|
||||
|
||||
var SWFUpload;if(SWFUpload==undefined){SWFUpload=function(settings){this.initSWFUpload(settings);};}
|
||||
SWFUpload.prototype.initSWFUpload=function(settings){try{this.customSettings={};this.settings=settings;this.eventQueue=[];this.movieName="SWFUpload_"+SWFUpload.movieCount++;this.movieElement=null;SWFUpload.instances[this.movieName]=this;this.initSettings();this.loadFlash();this.displayDebugInfo();}catch(ex){delete SWFUpload.instances[this.movieName];throw ex;}
|
||||
};SWFUpload.instances={};SWFUpload.movieCount=0;SWFUpload.version="2.2.0 Beta 3";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.prototype.initSettings=function(){this.ensureDefault=function(settingName,defaultValue){this.settings[settingName]=(this.settings[settingName]==undefined)? defaultValue:this.settings[settingName];};this.ensureDefault("upload_url","");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("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",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+"?swfuploadrnd="+Math.floor(Math.random()*999999999);}
|
||||
delete this.ensureDefault;};SWFUpload.prototype.loadFlash=function(){if(this.settings.button_placeholder_id!==""){this.replaceWithFlash();}else{this.appendFlash();}
|
||||
};SWFUpload.prototype.appendFlash=function(){var targetElement,container;if(document.getElementById(this.movieName)!==null){throw "ID "+this.movieName+" is already in use. The Flash Object could not be added";}
|
||||
targetElement=document.getElementsByTagName("body")[0];if(targetElement==undefined){throw "Could not find the 'body' element.";}
|
||||
container=document.createElement("div");container.style.width="1px";container.style.height="1px";container.style.overflow="hidden";targetElement.appendChild(container);container.innerHTML=this.getFlashHTML();if(window[this.movieName]==undefined){window[this.movieName]=this.getMovieElement();}
|
||||
};SWFUpload.prototype.replaceWithFlash=function(){var targetElement,tempParent;if(document.getElementById(this.movieName)!==null){throw "ID "+this.movieName+" is already in use. The Flash Object could not be added";}
|
||||
targetElement=document.getElementById(this.settings.button_placeholder_id);if(targetElement==undefined){throw "Could not find the placeholder element.";}
|
||||
tempParent=document.createElement("div");tempParent.innerHTML=this.getFlashHTML();targetElement.parentNode.replaceChild(tempParent.firstChild,targetElement);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 paramString=this.buildParamString();var httpSuccessString=this.settings.http_success.join(",");return ["movieName=",encodeURIComponent(this.movieName),
|
||||
"&uploadURL=",encodeURIComponent(this.settings.upload_url),
|
||||
"&useQueryString=",encodeURIComponent(this.settings.use_query_string),
|
||||
"&requeueOnError=",encodeURIComponent(this.settings.requeue_on_error),
|
||||
"&httpSuccess=",encodeURIComponent(httpSuccessString),
|
||||
"&params=",encodeURIComponent(paramString),
|
||||
"&filePostName=",encodeURIComponent(this.settings.file_post_name),
|
||||
"&fileTypes=",encodeURIComponent(this.settings.file_types),
|
||||
"&fileTypesDescription=",encodeURIComponent(this.settings.file_types_description),
|
||||
"&fileSizeLimit=",encodeURIComponent(this.settings.file_size_limit),
|
||||
"&fileUploadLimit=",encodeURIComponent(this.settings.file_upload_limit),
|
||||
"&fileQueueLimit=",encodeURIComponent(this.settings.file_queue_limit),
|
||||
"&debugEnabled=",encodeURIComponent(this.settings.debug_enabled),
|
||||
"&buttonImageURL=",encodeURIComponent(this.settings.button_image_url),
|
||||
"&buttonWidth=",encodeURIComponent(this.settings.button_width),
|
||||
"&buttonHeight=",encodeURIComponent(this.settings.button_height),
|
||||
"&buttonText=",encodeURIComponent(this.settings.button_text),
|
||||
"&buttonTextTopPadding=",encodeURIComponent(this.settings.button_text_top_padding),
|
||||
"&buttonTextLeftPadding=",encodeURIComponent(this.settings.button_text_left_padding),
|
||||
"&buttonTextStyle=",encodeURIComponent(this.settings.button_text_style),
|
||||
"&buttonAction=",encodeURIComponent(this.settings.button_action),
|
||||
"&buttonDisabled=",encodeURIComponent(this.settings.button_disabled),
|
||||
"&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 postParams=this.settings.post_params;var paramStringPairs=[];if(typeof(postParams)==="object"){for(var name in postParams){if(postParams.hasOwnProperty(name)){paramStringPairs.push(encodeURIComponent(name.toString())+"="+encodeURIComponent(postParams[name].toString()));}
|
||||
}
|
||||
}
|
||||
return paramStringPairs.join("&");};SWFUpload.prototype.destroy=function(){try{this.cancelUpload(null,false);;var movieElement=null;movieElement=this.getMovieElement();if(movieElement){for(var i in movieElement){try{if(typeof(movieElement[i])==="function"){movieElement[i]=null;}
|
||||
}catch(ex1){}
|
||||
}
|
||||
try{movieElement.parentNode.removeChild(movieElement);}catch(ex){}
|
||||
}
|
||||
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(ex1){alert(ex);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","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_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(name,value,default_value){if(value==undefined){return(this.settings[name]=default_value);}else{return(this.settings[name]=value);}
|
||||
};SWFUpload.prototype.getSetting=function(name){if(this.settings[name]!=undefined){return this.settings[name];}
|
||||
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(fileID){this.callFlash("StartUpload",[fileID]);};SWFUpload.prototype.cancelUpload=function(fileID,triggerErrorEvent){if(triggerErrorEvent!==false){triggerErrorEvent=true;}
|
||||
this.callFlash("CancelUpload",[fileID,triggerErrorEvent]);};SWFUpload.prototype.stopUpload=function(){this.callFlash("StopUpload");};SWFUpload.prototype.getStats=function(){return this.callFlash("GetStats");};SWFUpload.prototype.setStats=function(statsObject){this.callFlash("SetStats",[statsObject]);};SWFUpload.prototype.getFile=function(fileID){if(typeof(fileID)==="number"){return this.callFlash("GetFileByIndex",[fileID]);}else{return this.callFlash("GetFile",[fileID]);}
|
||||
};SWFUpload.prototype.addFileParam=function(fileID,name,value){return this.callFlash("AddFileParam",[fileID,name,value]);};SWFUpload.prototype.removeFileParam=function(fileID,name){this.callFlash("RemoveFileParam",[fileID,name]);};SWFUpload.prototype.setUploadURL=function(url){this.settings.upload_url=url.toString();this.callFlash("SetUploadURL",[url]);};SWFUpload.prototype.setPostParams=function(paramsObject){this.settings.post_params=paramsObject;this.callFlash("SetPostParams",[paramsObject]);};SWFUpload.prototype.addPostParam=function(name,value){this.settings.post_params[name]=value;this.callFlash("SetPostParams",[this.settings.post_params]);};SWFUpload.prototype.removePostParam=function(name){delete this.settings.post_params[name];this.callFlash("SetPostParams",[this.settings.post_params]);};SWFUpload.prototype.setFileTypes=function(types,description){this.settings.file_types=types;this.settings.file_types_description=description;this.callFlash("SetFileTypes",[types,description]);};SWFUpload.prototype.setFileSizeLimit=function(fileSizeLimit){this.settings.file_size_limit=fileSizeLimit;this.callFlash("SetFileSizeLimit",[fileSizeLimit]);};SWFUpload.prototype.setFileUploadLimit=function(fileUploadLimit){this.settings.file_upload_limit=fileUploadLimit;this.callFlash("SetFileUploadLimit",[fileUploadLimit]);};SWFUpload.prototype.setFileQueueLimit=function(fileQueueLimit){this.settings.file_queue_limit=fileQueueLimit;this.callFlash("SetFileQueueLimit",[fileQueueLimit]);};SWFUpload.prototype.setFilePostName=function(filePostName){this.settings.file_post_name=filePostName;this.callFlash("SetFilePostName",[filePostName]);};SWFUpload.prototype.setUseQueryString=function(useQueryString){this.settings.use_query_string=useQueryString;this.callFlash("SetUseQueryString",[useQueryString]);};SWFUpload.prototype.setRequeueOnError=function(requeueOnError){this.settings.requeue_on_error=requeueOnError;this.callFlash("SetRequeueOnError",[requeueOnError]);};SWFUpload.prototype.setHTTPSuccess=function(http_status_codes){if(typeof http_status_codes==="string"){http_status_codes=http_status_codes.replace(" ","").split(",");}
|
||||
this.settings.http_success=http_status_codes;this.callFlash("SetHTTPSuccess",[http_status_codes]);};SWFUpload.prototype.setDebugEnabled=function(debugEnabled){this.settings.debug_enabled=debugEnabled;this.callFlash("SetDebugEnabled",[debugEnabled]);};SWFUpload.prototype.setButtonImageURL=function(buttonImageURL){if(buttonImageURL==undefined){buttonImageURL="";}
|
||||
this.settings.button_image_url=buttonImageURL;this.callFlash("SetButtonImageURL",[buttonImageURL]);};SWFUpload.prototype.setButtonDimensions=function(width,height){this.settings.button_width=width;this.settings.button_height=height;var movie=this.getMovieElement();if(movie!=undefined){movie.style.width=width+"px";movie.style.height=height+"px";}
|
||||
this.callFlash("SetButtonDimensions",[width,height]);};SWFUpload.prototype.setButtonText=function(html){this.settings.button_text=html;this.callFlash("SetButtonText",[html]);};SWFUpload.prototype.setButtonTextPadding=function(left,top){this.settings.button_text_top_padding=top;this.settings.button_text_left_padding=left;this.callFlash("SetButtonTextPadding",[left,top]);};SWFUpload.prototype.setButtonTextStyle=function(css){this.settings.button_text_style=css;this.callFlash("SetButtonTextStyle",[css]);};SWFUpload.prototype.setButtonDisabled=function(isDisabled){this.settings.button_disabled=isDisabled;this.callFlash("SetButtonDisabled",[isDisabled]);};SWFUpload.prototype.setButtonAction=function(buttonAction){this.settings.button_action=buttonAction;this.callFlash("SetButtonAction",[buttonAction]);};SWFUpload.prototype.setButtonCursor=function(cursor){this.settings.button_cursor=cursor;this.callFlash("SetButtonCursor",[cursor]);};SWFUpload.prototype.queueEvent=function(handlerName,argumentArray){if(argumentArray==undefined){argumentArray=[];}else if(!(argumentArray instanceof Array)){argumentArray=[argumentArray];}
|
||||
var self=this;if(typeof this.settings[handlerName]==="function"){this.eventQueue.push(function(){this.settings[handlerName].apply(this,argumentArray);});setTimeout(function(){self.executeNextEvent();},0);}else if(this.settings[handlerName]!==null){throw "Event handler "+handlerName+" is unknown or is not a function";}
|
||||
};SWFUpload.prototype.executeNextEvent=function(){var f=this.eventQueue ? this.eventQueue.shift():null;if(typeof(f)==="function"){f.apply(this);}
|
||||
};SWFUpload.prototype.unescapeFilePostParams=function(file){var reg=/[$]([0-9a-f]{4})/i;var unescapedPost={};var uk;if(file!=undefined){for(var k in file.post){if(file.post.hasOwnProperty(k)){uk=k;var match;while((match=reg.exec(uk))!==null){uk=uk.replace(match[0],String.fromCharCode(parseInt("0x"+match[1],16)));}
|
||||
unescapedPost[uk]=file.post[k];}
|
||||
}
|
||||
file.post=unescapedPost;}
|
||||
return file;};SWFUpload.prototype.flashReady=function(){var movieElement=this.getMovieElement();if(typeof(movieElement.CallFunction)==="unknown"){this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)");for(var key in movieElement){try{if(typeof(movieElement[key])==="function"){movieElement[key]=null;}
|
||||
}catch(ex){}
|
||||
}
|
||||
}
|
||||
this.queueEvent("swfupload_loaded_handler");};SWFUpload.prototype.fileDialogStart=function(){this.queueEvent("file_dialog_start_handler");};SWFUpload.prototype.fileQueued=function(file){file=this.unescapeFilePostParams(file);this.queueEvent("file_queued_handler",file);};SWFUpload.prototype.fileQueueError=function(file,errorCode,message){file=this.unescapeFilePostParams(file);this.queueEvent("file_queue_error_handler",[file,errorCode,message]);};SWFUpload.prototype.fileDialogComplete=function(numFilesSelected,numFilesQueued){this.queueEvent("file_dialog_complete_handler",[numFilesSelected,numFilesQueued]);};SWFUpload.prototype.uploadStart=function(file){file=this.unescapeFilePostParams(file);this.queueEvent("return_upload_start_handler",file);};SWFUpload.prototype.returnUploadStart=function(file){var returnValue;if(typeof this.settings.upload_start_handler==="function"){file=this.unescapeFilePostParams(file);returnValue=this.settings.upload_start_handler.call(this,file);}else if(this.settings.upload_start_handler!=undefined){throw "upload_start_handler must be a function";}
|
||||
if(returnValue===undefined){returnValue=true;}
|
||||
returnValue=!!returnValue;this.callFlash("ReturnUploadStart",[returnValue]);};SWFUpload.prototype.uploadProgress=function(file,bytesComplete,bytesTotal){file=this.unescapeFilePostParams(file);this.queueEvent("upload_progress_handler",[file,bytesComplete,bytesTotal]);};SWFUpload.prototype.uploadError=function(file,errorCode,message){file=this.unescapeFilePostParams(file);this.queueEvent("upload_error_handler",[file,errorCode,message]);};SWFUpload.prototype.uploadSuccess=function(file,serverData){file=this.unescapeFilePostParams(file);this.queueEvent("upload_success_handler",[file,serverData]);};SWFUpload.prototype.uploadComplete=function(file){file=this.unescapeFilePostParams(file);this.queueEvent("upload_complete_handler",file);};SWFUpload.prototype.debug=function(message){this.queueEvent("debug_handler",message);};SWFUpload.prototype.debugMessage=function(message){if(this.settings.debug){var exceptionMessage,exceptionValues=[];if(typeof message==="object"&&typeof message.name==="string"&&typeof message.message==="string"){for(var key in message){if(message.hasOwnProperty(key)){exceptionValues.push(key+": "+message[key]);}
|
||||
}
|
||||
exceptionMessage=exceptionValues.join("\n")||"";exceptionValues=exceptionMessage.split("\n");exceptionMessage="EXCEPTION: "+exceptionValues.join("\nEXCEPTION: ");SWFUpload.Console.writeLine(exceptionMessage);}else{SWFUpload.Console.writeLine(message);}
|
||||
}
|
||||
};SWFUpload.Console={};SWFUpload.Console.writeLine=function(message){var console,documentForm;try{console=document.getElementById("SWFUpload_Console");if(!console){documentForm=document.createElement("form");document.getElementsByTagName("body")[0].appendChild(documentForm);console=document.createElement("textarea");console.id="SWFUpload_Console";console.style.fontFamily="monospace";console.setAttribute("wrap","off");console.wrap="off";console.style.overflow="auto";console.style.width="700px";console.style.height="350px";console.style.margin="5px";documentForm.appendChild(console);}
|
||||
console.value+=message+"\n";console.scrollTop=console.scrollHeight-console.clientHeight;}catch(ex){alert("Exception: "+ex.name+" Message: "+ex.message);}
|
||||
};
|
||||
BIN
resources/xajax/xajax_plugins/response/swfupload/swfupload.swf
Normal file
BIN
resources/xajax/xajax_plugins/response/swfupload/swfupload.swf
Normal file
Binary file not shown.
@@ -0,0 +1,112 @@
|
||||
|
||||
xajax.ext.SWFupload.swf=null;xajax.ext.SWFupload.forms={};xajax.ext.SWFupload.fields={};xajax.ext.SWFupload.queues={};xajax.ext.SWFupload.tools={};xajax.ext.SWFupload.settings={flash_url:xajax.ext.SWFupload.config.javascript_URI+"swfupload.swf",
|
||||
file_size_limit:"0",
|
||||
file_types:"*.*",
|
||||
file_types_description:"All Files",
|
||||
file_upload_limit:0,
|
||||
file_queue_limit:0,
|
||||
file_queue_error_handler:xajax.ext.SWFupload.tools.fileQueueError,
|
||||
debug:false,
|
||||
button_image_url:"img/button_500x22.gif",
|
||||
button_width:270,
|
||||
button_height:22,
|
||||
button_action:SWFUpload.BUTTON_ACTION.SELECT_FILES,
|
||||
button_window_mode:SWFUpload.WINDOW_MODE.TRANSPARENT,
|
||||
button_placeholder_id:'',
|
||||
button_text:'<span class="btnText">Select Files...</span>',
|
||||
button_text_style:".btnText { font-size: 10; font-weight: bold; font-family: MS Shell Dlg; }",
|
||||
button_text_top_padding:3,
|
||||
button_text_left_padding:100,
|
||||
post_params:{}
|
||||
}
|
||||
if('undefined'==typeof xajax.ext.SWFupload.lang){xajax.ext.SWFupload.lang={};xajax.ext.SWFupload.lang.browseFiles='Browse Files';xajax.ext.SWFupload.lang.browseFile='Browse File';}
|
||||
xajax.ext.SWFupload.configure=function(config){if("object"==typeof config)return xajax.ext.SWFupload.tools.mergeObj(this.settings,config);return this.settings;}
|
||||
xajax.ext.SWFupload.addQueue=function(child,parent,config,multiple){var id=xajax.ext.SWFupload.tools.getId();this.queues[id]=new xajax.ext.SWFupload.tools.fileQueue(id,child,parent,config,multiple);return id;}
|
||||
xajax.ext.SWFupload.applyConfig=function(oQueue){var conf=oQueue.getConfig();var swf=xajax.ext.SWFupload.getInstance();if('undefined'!=typeof conf.file_types)
|
||||
swf.setFileTypes(conf.file_types,conf.file_types_description);if('undefined'!=typeof conf.file_size_limit)
|
||||
swf.setFileSizeLimit(conf.file_size_limit);if('object'==typeof conf.post_params){for(a in conf.post_params)
|
||||
swf.addPostParam(a,conf.post_params[a]);}
|
||||
swf.settings.file_queued_handler=function(oFile){oQueue.addFile(oFile)};;swf.settings.file_queue_error_handler=oQueue.fileQueueError;}
|
||||
xajax.ext.SWFupload.selectFile=function(oQueue){this.applyConfig(oQueue);if(oQueue.getConfig().file_queue_limit > 0&&oQueue.getConfig().file_queue_limit <=oQueue.queued)return;xajax.ext.SWFupload.getInstance().selectFile();}
|
||||
xajax.ext.SWFupload.selectFiles=function(oQueue){this.applyConfig(oQueue);if(oQueue.getConfig().file_queue_limit > 0&&oQueue.getConfig().file_queue_limit <=oQueue.queued)return;xajax.ext.SWFupload.getInstance().selectFiles();}
|
||||
xajax.ext.SWFupload.getInstance=function(){if(null==this.swf)this.swf=new SWFUpload(this.settings);return this.swf;}
|
||||
xajax.ext.SWFupload.removeFile=function(QueueId,FileId,finished){this.queues[QueueId].removeFile(FileId,finished);}
|
||||
xajax.ext.SWFupload.request={};xajax.ext.SWFupload.request.getFileFromQueue=function(oRequest){var instances={};var queued=0;if("string"==typeof oRequest.SWFform){if('object'!=typeof xajax.ext.SWFupload.forms[oRequest.SWFform]){return false;}
|
||||
for(a in xajax.ext.SWFupload.forms[oRequest.SWFform]){var field=xajax.ext.SWFupload.forms[oRequest.SWFform][a];if(0 < xajax.ext.SWFupload.queues[field].queued){oRequest.currentFile=xajax.ext.SWFupload.queues[field].getFile();oRequest.swf=xajax.ext.SWFupload.queues[field].getSWF();return true;};}
|
||||
}else if("string"==typeof oRequest.SWFfield){if('string'!=typeof xajax.ext.SWFupload.fields[oRequest.SWFfield]){return false;}
|
||||
var qId=xajax.ext.SWFupload.fields[oRequest.SWFfield];if(0 < xajax.ext.SWFupload.queues[qId].queued){oRequest.currentFile=xajax.ext.SWFupload.queues[qId].getFile();oRequest.swf=xajax.ext.SWFupload.queues[qId].getSWF();return true;};}else{for(var a in xajax.ext.SWFupload.queues){if(0 < xajax.ext.SWFupload.queues[a].queued){oRequest.currentFile=xajax.ext.SWFupload.queues[a].getFile();oRequest.swf=xajax.ext.SWFupload.queues[a].getSWF();return true;};}
|
||||
}
|
||||
return false;}
|
||||
xajax.ext.SWFupload.request.processParameters=function(oRequest){if("SWFupload"==oRequest.mode){oRequest.currentFile=false;xajax.ext.SWFupload.request.getFileFromQueue(oRequest);if(oRequest.currentFile)oRequest.method='GET';}
|
||||
return xajax.ext.SWFupload.bak.processParameters(oRequest);}
|
||||
xajax.ext.SWFupload.request.prepareRequest=function(oRequest){if("SWFupload"==oRequest.mode&&false!=oRequest.currentFile)return;return xajax.ext.SWFupload.bak.prepareRequest(oRequest);}
|
||||
xajax.ext.SWFupload.request.submitRequest=function(oRequest){if("SWFupload"==oRequest.mode&&false!=oRequest.currentFile){if(oRequest.requestURI){oRequest.bak_requestURI=oRequest.requestURI;}else if(oRequest.bak_requestURI){oRequest.requestURI=oRequest.bak_requestURI;}
|
||||
var swf=oRequest.swf;var fileQueue=xajax.ext.SWFupload.queues[oRequest.currentFile.QueueId];swf.customSettings.currentFile=oRequest.currentFile;swf.setFilePostName(swf.customSettings.currentFile.name);swf.customSettings.oRequest=oRequest;swf.setUploadURL(oRequest.requestURI);swf.settings.upload_success_handler=function(oFile,response){var xx=xajax;var xt=xx.tools;var xcb=xx.callback;var gcb=xcb.global;var lcb=oRequest.callback;var oRet=oRequest.returnValue;var FileId=swf.customSettings.currentFile;if('function'==typeof this.old_upload_success_handler)this.old_upload_success_handler(oFile);xcb.execute([gcb,lcb],'onSuccess',oRequest);var seq=0;if(response){var responseXML=(new DOMParser()).parseFromString(response,"text/xml");if(responseXML.documentElement){oRequest.status.onProcessing();var child=responseXML.documentElement.firstChild;oRet=xt.xml.processFragment(child,seq,oRet,oRequest);}
|
||||
}
|
||||
var obj={};obj.fullName='Response Complete';obj.sequence=seq;obj.request=oRequest;obj.context=oRequest.context;obj.cmd='rcmplt';xt.queue.push(xx.response,obj);if(null==xx.response.timeout)
|
||||
xt.queue.process(xx.response);}
|
||||
swf.settings.upload_complete_handler=function(oFile){var qFile=this.customSettings.currentFile;xajax.ext.SWFupload.removeFile(qFile.QueueId,qFile.id,true);if(!xajax.ext.SWFupload.request.getFileFromQueue(oRequest)){if('function'==typeof oRequest.onUploadComplete)oRequest.onUploadComplete();return;}
|
||||
xajax.ext.SWFupload.request.submitRequest(oRequest);}
|
||||
swf.settings.upload_start_handler=function(oFile){if('function'==typeof this.old_upload_start_handler)this.old_upload_start_handler(oFile);oRequest.startTime=new Date();}
|
||||
swf.settings.upload_progress_handler=function(oFile,bytesLoaded,bytesTotal){upload={};upload.received=bytesLoaded;upload.total=bytesTotal;upload.state="uploading";var reqTime=new Date();upload.lastbytes=oRequest.lastbytes;upload.now=reqTime.getTime()/1000;upload.start=oRequest.startTime.getTime()/1000;var step=upload.received/(upload.total/100);var progressbar=xajax.$('SWFup_progress_'+oFile.id);var w=Math.round(220*step/100);progressbar.style.width=w+'px';var progress=xajax.$("swf_queued_filesize_"+oFile.id);var elapsed=upload.now-upload.start;var rate=xajax.ext.SWFupload.tools.formatBytes(upload.received/elapsed).toString()+'/s';progress.innerHTML="<i>"+rate+"</i> "+xajax.ext.SWFupload.tools.formatBytes(upload.received)+"/"+xajax.ext.SWFupload.tools.formatBytes(upload.total);oRequest.lastbytes=upload.received;}
|
||||
swf.settings.upload_error_handler=function(file,errorCode,message){if(-280==errorCode)return;if(file==null){fileName='';}else{fileName=file.name;}
|
||||
alert("Error Code: "+errorCode+", File name: "+fileName+", Message: "+message);};swf.startUpload(swf.customSettings.currentFile.id);return;}
|
||||
return xajax.ext.SWFupload.bak.submitRequest(oRequest);}
|
||||
xajax.ext.SWFupload.tools.queueFile=function(oFile,name,QueueId,QueueContainer){this.id=oFile.id;this.name=name;this.QueueId=QueueId;var container=document.createElement('div');container.id="SWFup_"+this.id;container.className="swf_queued_file";this.elm=container;var remove=document.createElement('div');remove.className="swf_queued_file_remove";remove.innerHTML=" ";var id=this.id;var QueueId=this.QueueId;remove.onclick=function(){xajax.ext.SWFupload.removeFile(QueueId,id);}
|
||||
container.appendChild(remove);var label=document.createElement('div');label.className="swf_queued_filename";label.innerHTML=oFile.name;container.appendChild(label);var progress_container=document.createElement('div');progress_container.className="swf_queued_file_progress_container";container.appendChild(progress_container);var progress=document.createElement('div');progress.className="swf_queued_file_progress_bar";progress.style.width='1px';progress.id='SWFup_progress_'+oFile.id;progress_container.appendChild(progress);var fSize=document.createElement('div');fSize.className="swf_queued_filesize";fSize.id="swf_queued_filesize_"+this.id;fSize.innerHTML=xajax.ext.SWFupload.tools.formatBytes(oFile.size);container.appendChild(fSize);var fClear=document.createElement('div');fClear.style.clear='both';container.appendChild(fClear);QueueContainer.appendChild(container);this.container=container;this.oFile=oFile;this.destroy=function(){QueueContainer.removeChild(container);}
|
||||
return;}
|
||||
xajax.ext.SWFupload.tools.fileQueue=function(id,child,parent,config,multiple){this.id=id;var config='object'==typeof config ? xajax.ext.SWFupload.tools.mergeObj(xajax.ext.SWFupload.settings,config):xajax.ext.SWFupload.settings;this.queued=0;this.files={};this.queue=null;this.getConfig=function(){return config;}
|
||||
var tmpName=child.name;var container=document.createElement('div');container.id='SWFbuttonContainer_'+tmpName;container.className='swf_browse_button';parent.appendChild(container);var container2=document.createElement('div');container2.id='SWFbutton_'+tmpName;container.appendChild(container2);parent.removeChild(child);var oQueue=this;if(true===multiple){config.button_action=SWFUpload.BUTTON_ACTION.SELECT_FILES;}else{config.button_action=SWFUpload.BUTTON_ACTION.SELECT_FILE;}
|
||||
var QueueContainer=document.createElement('div');QueueContainer.id='SWFqueue_'+this.id;QueueContainer.className='swf_queue_container';parent.appendChild(QueueContainer);config.button_placeholder_id=container2.id;var foo=this;var fieldname=child.name;this.addFile=function(oFile){foo.files[oFile.id]=new xajax.ext.SWFupload.tools.queueFile(oFile,fieldname,foo.id,QueueContainer);foo.queued++;if(foo.queued==config.file_queue_limit)foo.swf.setButtonDisabled(true);}
|
||||
this.getFile=function(FileId){if("undefined"!=typeof FileId)return foo.files[FileId];for(a in foo.files)return foo.files[a];return false;}
|
||||
this.purge=function(d){var a=d.attributes,i,l,n;if(a){l=a.length;for(i=0;i < l;i+=1){n=a[i].name;if(typeof d[n]==='function'){d[n]=null;}
|
||||
}
|
||||
}
|
||||
a=d.childNodes;if(a){l=a.length;for(i=0;i < l;i+=1){this.purge(d.childNodes[i]);}
|
||||
}
|
||||
}
|
||||
this.removeFile=function(FileId,finished){foo.swf.cancelUpload(FileId);foo.queued--;if(foo.queued <=config.file_queue_limit)foo.swf.setButtonDisabled(false);var filediv=xajax.$("SWFup_"+foo.files[FileId].id);filediv.className=true===finished ? 'swf_queued_file_finished':'swf_queued_file_removed';setTimeout(function(){xajax.ext.SWFupload.tools.FadeOut(filediv,100);},xajax.ext.SWFupload.config.FadeTimeOut);foo.files[FileId]=null;delete foo.files[FileId];}
|
||||
this.destroy=function(){this.swf.destroy();delete(this.swf);for(a in foo.files){foo.files[a].destroy();delete(foo.files[a]);}
|
||||
foo.queued=0;delete(foo);}
|
||||
this.fileQueueError=function(swf,code,msg){if(-110==code){msg="Die gewählte Datei ist zu groß!";alert(msg);}
|
||||
}
|
||||
this.getSWF=function(){return this.swf;}
|
||||
config.file_queued_handler=this.addFile;config.file_queue_error_handler=this.fileQueueError;this.swf=new SWFUpload(config);}
|
||||
xajax.ext.SWFupload.tools._parseFields=function(children,parent,config,multiple){var result={};var iLen=children.length;for(var i=0;i < iLen;++i){var child=children[i];if('undefined'!=typeof child.childNodes)
|
||||
var res2=xajax.ext.SWFupload.tools._parseFields(child.childNodes,child,config,multiple);result=xajax.ext.SWFupload.tools.mergeObj(result,res2);if(child.name){if('file'==child.type){result[child.name]=xajax.ext.SWFupload.addQueue(child,parent,config,multiple);}
|
||||
}
|
||||
}
|
||||
return result;}
|
||||
xajax.ext.SWFupload.tools.transForm=function(form_id,config,multiple){var oForm=xajax.$(form_id);if(oForm)
|
||||
if(oForm.childNodes){var fields=xajax.ext.SWFupload.tools._parseFields(oForm.childNodes,oForm,config,multiple);xajax.ext.SWFupload.forms[form_id]=fields;}
|
||||
return;}
|
||||
xajax.ext.SWFupload.tools.transField=function(field_id,config,multiple){try{var oField=xajax.$(field_id);if('undefined'!=typeof oField)return xajax.ext.SWFupload.fields[field_id]=xajax.ext.SWFupload.addQueue(oField,oField.parentNode,config,multiple);}catch(ex){}
|
||||
return;}
|
||||
xajax.ext.SWFupload.tools.destroyForm=function(form_id){if("undefined"==typeof xajax.ext.SWFupload.forms[form_id])return;for(a in xajax.ext.SWFupload.forms[form_id]){var key=xajax.ext.SWFupload.forms[form_id][a];xajax.ext.SWFupload.queues[key].destroy();delete xajax.ext.SWFupload.queues[key];}
|
||||
delete xajax.ext.SWFupload.forms[form_id];return;}
|
||||
xajax.ext.SWFupload.tools.destroyField=function(field_id){if("undefined"==typeof xajax.ext.SWFupload.fields[field_id])return;var key=xajax.ext.SWFupload.fields[field_id];xajax.ext.SWFupload.queues[key].destroy();delete(xajax.ext.SWFupload.queues[key]);delete xajax.ext.SWFupload.fields[field_id];return true;}
|
||||
xajax.ext.SWFupload.tools.FadeOut=function(elm,opacity){var reduceOpacityBy=15;var rate=40;if(opacity > 0){opacity-=reduceOpacityBy;if(opacity < 0){opacity=0;}
|
||||
if(elm.filters){try{elm.filters.item("DXImageTransform.Microsoft.Alpha").opacity=opacity;}catch(e){elm.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity="+opacity+")";}
|
||||
}else{elm.style.opacity=opacity/100;}
|
||||
}
|
||||
if(opacity > 0){var oSelf=this;setTimeout(function(){xajax.ext.SWFupload.tools.FadeOut(elm,opacity);},rate);}else{var parent=elm.parentNode;parent.removeChild(elm);}
|
||||
}
|
||||
xajax.ext.SWFupload.tools.formatBytes=function(bytes){var ret={};if(bytes/1204 < 1024){return(Math.round(bytes/1024*100)/100).toString()+" kB";}else{return(Math.round(bytes/1024/1024*100)/100).toString()+" MB";}
|
||||
return ret;}
|
||||
xajax.ext.SWFupload.tools.mergeObj=function(){if('object'!=typeof arguments)return;var res={};var len=arguments.length;for(var i=0;i<len;i++){var obj=arguments[i];for(a in obj){res[a]=obj[a];}
|
||||
}
|
||||
return res;}
|
||||
xajax.ext.SWFupload.tools.getId=function(){var pid_str="";for(i=0;i<=3;i++){var pid=0;pid=Math.random();while(Math.ceil(pid).toString().length<8){pid*=10;}
|
||||
pid=Math.ceil(pid).toString();pid_str=pid_str+pid.toString();}
|
||||
return pid_str;}
|
||||
xajax.command.handler.register('SWFup_dfi',function(args){args.cmdFullName='ext.SWFupload.tools.destroyField';xajax.ext.SWFupload.tools.destroyField(args.id);return true;});xajax.command.handler.register('SWFup_dfo',function(args){args.cmdFullName='ext.SWFupload.tools.destroyForm';xajax.ext.SWFupload.tools.destroyForm(args.id);return true;});xajax.command.handler.register('SWFup_tfi',function(args){args.cmdFullName='ext.SWFupload.tools.transField';if("string"==typeof args.data.config.upload_success_handler){try{eval("var foo = "+args.data.config.upload_success_handler);args.data.config.upload_success_handler=foo;}catch(ex){delete(args.data.config.upload_success_handler);}
|
||||
}
|
||||
xajax.ext.SWFupload.tools.transField(args.id,args.data.config,args.data.multi);return true;});xajax.command.handler.register('SWFup_tfo',function(args){try{args.cmdFullName='ext.SWFupload.tools.transForm';if("string"==typeof args.data.config.upload_success_handler){try{eval("var foo = "+args.data.config.upload_success_handler);args.data.config.upload_success_handler=foo;}catch(ex){delete(args.data.config.upload_success_handler);}
|
||||
}
|
||||
xajax.ext.SWFupload.tools.transForm(args.id,args.data.config,args.data.multi);}catch(ex){}
|
||||
return true;});xajax.ext.SWFupload.bak={};xajax.ext.SWFupload.bak.prepareRequest=xajax.prepareRequest;xajax.ext.SWFupload.bak.submitRequest=xajax.submitRequest;xajax.ext.SWFupload.bak.responseProcessor=xajax.responseProcessor;xajax.ext.SWFupload.bak.processParameters=xajax.processParameters;xajax.prepareRequest=xajax.ext.SWFupload.request.prepareRequest;xajax.submitRequest=xajax.ext.SWFupload.request.submitRequest;xajax.processParameters=xajax.ext.SWFupload.request.processParameters;if(typeof DOMParser=="undefined"){DOMParser=function(){}
|
||||
DOMParser.prototype.parseFromString=function(str,contentType){if(typeof ActiveXObject!="undefined"){var d=new ActiveXObject("Microsoft.XMLDOM");d.loadXML(str);return d;}else if(typeof XMLHttpRequest!="undefined"){var req=new XMLHttpRequest;req.open("GET","data:"+(contentType||"application/xml")+
|
||||
";charset=utf-8,"+encodeURIComponent(str),false);if(req.overrideMimeType){req.overrideMimeType(contentType);}
|
||||
req.send(null);return req.responseXML;}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,972 @@
|
||||
|
||||
//xjxSWFup = xajax.ext.SWFupload;
|
||||
|
||||
xajax.ext.SWFupload.swf = null;
|
||||
|
||||
xajax.ext.SWFupload.forms = {};
|
||||
xajax.ext.SWFupload.fields = {};
|
||||
xajax.ext.SWFupload.queues = {};
|
||||
xajax.ext.SWFupload.tools = {};
|
||||
|
||||
/* default upload settings */
|
||||
xajax.ext.SWFupload.settings = {
|
||||
flash_url : xajax.ext.SWFupload.config.javascript_URI+"swfupload.swf",
|
||||
file_size_limit : "0",
|
||||
file_types : "*.*",
|
||||
file_types_description : "All Files",
|
||||
file_upload_limit : 0,
|
||||
file_queue_limit : 0,
|
||||
file_queue_error_handler : xajax.ext.SWFupload.tools.fileQueueError,
|
||||
debug: false,
|
||||
button_image_url : "img/button_500x22.gif",
|
||||
button_width : 270,
|
||||
button_height : 22,
|
||||
button_action : SWFUpload.BUTTON_ACTION.SELECT_FILES,
|
||||
button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
|
||||
button_placeholder_id :'' ,
|
||||
button_text : '<span class="btnText">Select Files...</span>',
|
||||
button_text_style : ".btnText { font-size: 10; font-weight: bold; font-family: MS Shell Dlg; }",
|
||||
button_text_top_padding : 3,
|
||||
button_text_left_padding : 100,
|
||||
post_params : {}
|
||||
}
|
||||
|
||||
if ('undefined' == typeof xajax.ext.SWFupload.lang)
|
||||
{
|
||||
xajax.ext.SWFupload.lang = {};
|
||||
xajax.ext.SWFupload.lang.browseFiles = 'Browse Files';
|
||||
xajax.ext.SWFupload.lang.browseFile = 'Browse File';
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.ext.SWFupload.init
|
||||
arguments: config [object]
|
||||
|
||||
Creates the SWFupload instance
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.configure = function (config)
|
||||
{
|
||||
if ("object" == typeof config) return xajax.ext.SWFupload.tools.mergeObj(this.settings,config);
|
||||
|
||||
return this.settings;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.ext.SWFupload.addQueue
|
||||
arguments: child [object], parent [object], config [objeect ,multiple [bool]
|
||||
|
||||
Creates a new a new file queue and stores the reference in this.queues
|
||||
*/
|
||||
xajax.ext.SWFupload.addQueue = function (child,parent,config,multiple)
|
||||
{
|
||||
var id = xajax.ext.SWFupload.tools.getId();
|
||||
this.queues[id] = new xajax.ext.SWFupload.tools.fileQueue(id,child,parent,config,multiple);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.ext.SWFupload.applyConfig
|
||||
arguments: oQueue [object]
|
||||
|
||||
Applies the queue's config on the SWFupload instance
|
||||
*/
|
||||
xajax.ext.SWFupload.applyConfig = function(oQueue)
|
||||
{
|
||||
|
||||
var conf = oQueue.getConfig();
|
||||
var swf = xajax.ext.SWFupload.getInstance();
|
||||
|
||||
if ( 'undefined' != typeof conf.file_types )
|
||||
swf.setFileTypes(conf.file_types, conf.file_types_description);
|
||||
|
||||
if ( 'undefined' != typeof conf.file_size_limit )
|
||||
swf.setFileSizeLimit(conf.file_size_limit);
|
||||
|
||||
if ( 'object' == typeof conf.post_params)
|
||||
{
|
||||
for (a in conf.post_params)
|
||||
swf.addPostParam(a,conf.post_params[a]);
|
||||
}
|
||||
|
||||
swf.settings.file_queued_handler = function(oFile) {oQueue.addFile(oFile)};;
|
||||
swf.settings.file_queue_error_handler = oQueue.fileQueueError;
|
||||
}
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.ext.SWFupload.selectFile
|
||||
arguments: oQueue [object]
|
||||
|
||||
Onclick handler for selecting file
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.selectFile = function(oQueue)
|
||||
{
|
||||
this.applyConfig(oQueue);
|
||||
|
||||
if (oQueue.getConfig().file_queue_limit > 0 && oQueue.getConfig().file_queue_limit <= oQueue.queued) return;
|
||||
|
||||
xajax.ext.SWFupload.getInstance().selectFile();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.ext.SWFupload.selectFiles
|
||||
arguments: oQueue [object]
|
||||
|
||||
Onclick handler for selecting files
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.selectFiles = function(oQueue)
|
||||
{
|
||||
this.applyConfig(oQueue);
|
||||
if (oQueue.getConfig().file_queue_limit > 0 && oQueue.getConfig().file_queue_limit <= oQueue.queued) return;
|
||||
xajax.ext.SWFupload.getInstance().selectFiles();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.ext.SWFupload.getInstance
|
||||
arguments:
|
||||
|
||||
Return the SWFupload instance. If there's no instance available it creates a new one with default settings.
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.getInstance = function()
|
||||
{
|
||||
if (null == this.swf) this.swf = new SWFUpload(this.settings);
|
||||
|
||||
return this.swf;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.ext.SWFupload.removeFile
|
||||
arguments: QueueId [integer] , FileId [integer]
|
||||
|
||||
Removes the file (FileID) from queue (QueueId)
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.removeFile = function(QueueId,FileId,finished)
|
||||
{
|
||||
this.queues[QueueId].removeFile(FileId,finished);
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
|
||||
xajax.ext.SWFupload.request = {};
|
||||
|
||||
|
||||
/*
|
||||
function: xajax.ext.SWFupload.request.getFileFromQueue
|
||||
arguments: oRequest [object]
|
||||
|
||||
Returns the first file from first available queue.
|
||||
Returns false if no files were selected
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.request.getFileFromQueue = function(oRequest)
|
||||
{
|
||||
|
||||
|
||||
var instances = {};
|
||||
var queued = 0;
|
||||
if ("string" == typeof oRequest.SWFform)
|
||||
{
|
||||
|
||||
|
||||
if ('object' != typeof xajax.ext.SWFupload.forms[oRequest.SWFform])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (a in xajax.ext.SWFupload.forms[oRequest.SWFform])
|
||||
{
|
||||
var field = xajax.ext.SWFupload.forms[oRequest.SWFform][a];
|
||||
if (0 < xajax.ext.SWFupload.queues[field].queued) {
|
||||
oRequest.currentFile = xajax.ext.SWFupload.queues[field].getFile();
|
||||
oRequest.swf = xajax.ext.SWFupload.queues[field].getSWF();
|
||||
return true ;
|
||||
};
|
||||
}
|
||||
} else if ("string" == typeof oRequest.SWFfield)
|
||||
{
|
||||
if ('string' != typeof xajax.ext.SWFupload.fields[oRequest.SWFfield])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var qId = xajax.ext.SWFupload.fields[oRequest.SWFfield];
|
||||
if (0 < xajax.ext.SWFupload.queues[qId].queued) {
|
||||
oRequest.currentFile = xajax.ext.SWFupload.queues[qId].getFile();
|
||||
oRequest.swf = xajax.ext.SWFupload.queues[qId].getSWF();
|
||||
return true ;
|
||||
};
|
||||
} else
|
||||
{
|
||||
|
||||
for (var a in xajax.ext.SWFupload.queues)
|
||||
{
|
||||
if (0 < xajax.ext.SWFupload.queues[a].queued) {
|
||||
oRequest.currentFile = xajax.ext.SWFupload.queues[a].getFile();
|
||||
oRequest.swf = xajax.ext.SWFupload.queues[a].getSWF();
|
||||
return true;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.ext.SWFupload.request. xajax.ext.SWFupload.request.processParameters = function(oRequest)
|
||||
|
||||
arguments: oRequest [object]
|
||||
|
||||
Processes the parameters
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.request.processParameters = function(oRequest)
|
||||
{
|
||||
if ("SWFupload" == oRequest.mode)
|
||||
{
|
||||
oRequest.currentFile = false;
|
||||
xajax.ext.SWFupload.request.getFileFromQueue(oRequest);
|
||||
if (oRequest.currentFile) oRequest.method='GET';
|
||||
}
|
||||
return xajax.ext.SWFupload.bak.processParameters(oRequest);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.ext.SWFupload.request. xajax.ext.SWFupload.request.prepareRequest = function(oRequest)
|
||||
|
||||
arguments: oRequest [object]
|
||||
|
||||
doesn't to anything at all when there's a file selected for upload
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.request.prepareRequest = function (oRequest)
|
||||
{
|
||||
if ("SWFupload" == oRequest.mode && false != oRequest.currentFile) return;
|
||||
return xajax.ext.SWFupload.bak.prepareRequest(oRequest);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.ext.SWFupload.request. xajax.ext.SWFupload.request.submitRequest = function(oRequest)
|
||||
|
||||
arguments: oRequest [object]
|
||||
|
||||
Submits the request either via SWFupload or XHR
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.request.submitRequest = function(oRequest)
|
||||
{
|
||||
if ( "SWFupload" == oRequest.mode && false != oRequest.currentFile )
|
||||
{
|
||||
|
||||
if (oRequest.requestURI) {
|
||||
//backup requestURI, otherwise xajax.responseReceived() is going to delete our url
|
||||
oRequest.bak_requestURI = oRequest.requestURI;
|
||||
} else if (oRequest.bak_requestURI) {
|
||||
oRequest.requestURI = oRequest.bak_requestURI;
|
||||
}
|
||||
|
||||
var swf = oRequest.swf;
|
||||
|
||||
var fileQueue = xajax.ext.SWFupload.queues[oRequest.currentFile.QueueId];
|
||||
|
||||
swf.customSettings.currentFile = oRequest.currentFile;
|
||||
swf.setFilePostName(swf.customSettings.currentFile.name);
|
||||
|
||||
swf.customSettings.oRequest = oRequest;
|
||||
swf.setUploadURL(oRequest.requestURI);
|
||||
|
||||
swf.settings.upload_success_handler = function ( oFile, response )
|
||||
{
|
||||
var xx = xajax;
|
||||
var xt = xx.tools;
|
||||
var xcb = xx.callback;
|
||||
var gcb = xcb.global;
|
||||
var lcb = oRequest.callback;
|
||||
|
||||
var oRet = oRequest.returnValue;
|
||||
|
||||
var FileId = swf.customSettings.currentFile;
|
||||
if ( 'function' == typeof this.old_upload_success_handler ) this.old_upload_success_handler( oFile );
|
||||
xcb.execute([gcb, lcb], 'onSuccess', oRequest);
|
||||
var seq = 0;
|
||||
if (response) {
|
||||
var responseXML = (new DOMParser()).parseFromString(response, "text/xml");
|
||||
if (responseXML.documentElement) {
|
||||
oRequest.status.onProcessing();
|
||||
|
||||
var child = responseXML.documentElement.firstChild;
|
||||
oRet = xt.xml.processFragment(child, seq, oRet, oRequest);
|
||||
}
|
||||
}
|
||||
var obj = {};
|
||||
obj.fullName = 'Response Complete';
|
||||
obj.sequence = seq;
|
||||
obj.request = oRequest;
|
||||
obj.context = oRequest.context;
|
||||
obj.cmd = 'rcmplt';
|
||||
xt.queue.push(xx.response, obj);
|
||||
|
||||
// do not re-start the queue if a timeout is set
|
||||
if (null == xx.response.timeout)
|
||||
xt.queue.process(xx.response);
|
||||
}
|
||||
|
||||
swf.settings.upload_complete_handler = function(oFile)
|
||||
{
|
||||
|
||||
var qFile = this.customSettings.currentFile;
|
||||
xajax.ext.SWFupload.removeFile(qFile.QueueId,qFile.id,true);
|
||||
|
||||
if ( !xajax.ext.SWFupload.request.getFileFromQueue(oRequest) )
|
||||
{
|
||||
if ('function' == typeof oRequest.onUploadComplete) oRequest.onUploadComplete();
|
||||
return;
|
||||
}
|
||||
|
||||
xajax.ext.SWFupload.request.submitRequest(oRequest);
|
||||
}
|
||||
|
||||
|
||||
swf.settings.upload_start_handler = function(oFile)
|
||||
{
|
||||
if ('function' == typeof this.old_upload_start_handler) this.old_upload_start_handler(oFile);
|
||||
oRequest.startTime = new Date();
|
||||
|
||||
}
|
||||
swf.settings.upload_progress_handler = function (oFile, bytesLoaded, bytesTotal)
|
||||
{
|
||||
|
||||
upload = {};
|
||||
upload.received=bytesLoaded;
|
||||
upload.total=bytesTotal;
|
||||
upload.state="uploading";
|
||||
var reqTime = new Date();
|
||||
|
||||
upload.lastbytes = oRequest.lastbytes;
|
||||
upload.now = reqTime.getTime() / 1000;
|
||||
upload.start = oRequest.startTime.getTime()/ 1000;
|
||||
|
||||
var step = upload.received / (upload.total / 100);
|
||||
var progressbar = xajax.$('SWFup_progress_'+oFile.id);
|
||||
var w = Math.round(220 * step / 100);
|
||||
progressbar.style.width=w+'px';
|
||||
|
||||
var progress = xajax.$("swf_queued_filesize_"+oFile.id);
|
||||
var elapsed = upload.now-upload.start;
|
||||
var rate = xajax.ext.SWFupload.tools.formatBytes(upload.received/ elapsed).toString() + '/s';
|
||||
progress.innerHTML = "<i>"+rate + "</i> "+xajax.ext.SWFupload.tools.formatBytes(upload.received)+"/"+xajax.ext.SWFupload.tools.formatBytes(upload.total);
|
||||
oRequest.lastbytes = upload.received;
|
||||
|
||||
}
|
||||
|
||||
swf.settings.upload_error_handler = function(file, errorCode, message)
|
||||
{
|
||||
// Skipe error when a file is removed from queue (abort)
|
||||
if (-280 == errorCode) return;
|
||||
if (file == null) {fileName = '';} else {
|
||||
fileName = file.name;
|
||||
}
|
||||
|
||||
alert("Error Code: "+errorCode+", File name: " + fileName + ", Message: " + message);
|
||||
};
|
||||
swf.startUpload(swf.customSettings.currentFile.id);
|
||||
return;
|
||||
}
|
||||
return xajax.ext.SWFupload.bak.submitRequest(oRequest);
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.ext.SWFupload.tools.queueFile
|
||||
arguments: oFile,QueueId,QueueContainer
|
||||
|
||||
*/
|
||||
xajax.ext.SWFupload.tools.queueFile = function(oFile,name,QueueId,QueueContainer) {
|
||||
|
||||
this.id = oFile.id;
|
||||
this.name = name;
|
||||
this.QueueId = QueueId;
|
||||
|
||||
var container = document.createElement('div');
|
||||
container.id = "SWFup_"+this.id;
|
||||
container.className="swf_queued_file";
|
||||
|
||||
this.elm = container;
|
||||
|
||||
var remove = document.createElement('div');
|
||||
remove.className="swf_queued_file_remove";
|
||||
remove.innerHTML=" ";
|
||||
|
||||
var id = this.id;
|
||||
var QueueId = this.QueueId;
|
||||
remove.onclick= function () {
|
||||
xajax.ext.SWFupload.removeFile(QueueId,id);
|
||||
}
|
||||
container.appendChild(remove);
|
||||
|
||||
var label = document.createElement('div');
|
||||
label.className="swf_queued_filename";
|
||||
label.innerHTML = oFile.name;
|
||||
container.appendChild(label);
|
||||
|
||||
var progress_container = document.createElement('div');
|
||||
progress_container.className="swf_queued_file_progress_container";
|
||||
container.appendChild(progress_container);
|
||||
|
||||
|
||||
var progress = document.createElement('div');
|
||||
progress.className="swf_queued_file_progress_bar";
|
||||
progress.style.width='1px';
|
||||
progress.id='SWFup_progress_'+oFile.id;
|
||||
progress_container.appendChild(progress);
|
||||
|
||||
|
||||
var fSize = document.createElement('div');
|
||||
fSize.className="swf_queued_filesize";
|
||||
fSize.id="swf_queued_filesize_"+this.id;
|
||||
fSize.innerHTML = xajax.ext.SWFupload.tools.formatBytes(oFile.size);
|
||||
container.appendChild(fSize);
|
||||
|
||||
var fClear= document.createElement('div');
|
||||
fClear.style.clear='both';
|
||||
container.appendChild(fClear);
|
||||
QueueContainer.appendChild(container);
|
||||
|
||||
this.container = container;
|
||||
this.oFile = oFile;
|
||||
|
||||
this.destroy = function()
|
||||
{
|
||||
QueueContainer.removeChild(container);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.ext.SWFupload.tools.fileQueue
|
||||
arguments: id [integer],child [object], parent [object], multiple [bool]
|
||||
|
||||
parses the form for fields
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.tools.fileQueue = function (id,child,parent,config,multiple)
|
||||
{
|
||||
|
||||
|
||||
this.id = id;
|
||||
var config = 'object' == typeof config ? xajax.ext.SWFupload.tools.mergeObj(xajax.ext.SWFupload.settings,config) : xajax.ext.SWFupload.settings;
|
||||
this.queued = 0;
|
||||
this.files = {};
|
||||
this.queue = null;
|
||||
|
||||
this.getConfig = function() {return config;}
|
||||
|
||||
var tmpName = child.name;
|
||||
var container = document.createElement('div');
|
||||
container.id = 'SWFbuttonContainer_'+tmpName;
|
||||
container.className='swf_browse_button';
|
||||
parent.appendChild(container);
|
||||
|
||||
|
||||
var container2 = document.createElement('div');
|
||||
container2.id = 'SWFbutton_'+tmpName;
|
||||
container.appendChild(container2);
|
||||
|
||||
parent.removeChild(child);
|
||||
|
||||
var oQueue = this;
|
||||
if (true === multiple)
|
||||
{
|
||||
config.button_action = SWFUpload.BUTTON_ACTION.SELECT_FILES;
|
||||
} else {
|
||||
config.button_action = SWFUpload.BUTTON_ACTION.SELECT_FILE;
|
||||
|
||||
}
|
||||
|
||||
var QueueContainer = document.createElement('div');
|
||||
QueueContainer.id = 'SWFqueue_'+ this.id;
|
||||
QueueContainer.className = 'swf_queue_container';
|
||||
parent.appendChild(QueueContainer);
|
||||
|
||||
config.button_placeholder_id=container2.id;
|
||||
|
||||
var foo = this;
|
||||
|
||||
var fieldname = child.name;
|
||||
this.addFile = function (oFile)
|
||||
{
|
||||
foo.files[oFile.id] = new xajax.ext.SWFupload.tools.queueFile(oFile,fieldname,foo.id,QueueContainer);
|
||||
foo.queued++;
|
||||
if (foo.queued == config.file_queue_limit) foo.swf.setButtonDisabled(true);
|
||||
}
|
||||
|
||||
this.getFile = function (FileId)
|
||||
{
|
||||
if ("undefined" != typeof FileId) return foo.files[FileId];
|
||||
for (a in foo.files) return foo.files[a];
|
||||
return false;
|
||||
}
|
||||
|
||||
this.purge = function (d) {
|
||||
var a = d.attributes, i, l, n;
|
||||
if (a) {
|
||||
l = a.length;
|
||||
for (i = 0; i < l; i += 1) {
|
||||
n = a[i].name;
|
||||
if (typeof d[n] === 'function') {
|
||||
d[n] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
a = d.childNodes;
|
||||
if (a) {
|
||||
l = a.length;
|
||||
for (i = 0; i < l; i += 1) {
|
||||
this.purge(d.childNodes[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.removeFile = function(FileId,finished)
|
||||
{
|
||||
|
||||
foo.swf.cancelUpload(FileId);
|
||||
|
||||
foo.queued--;
|
||||
if (foo.queued <= config.file_queue_limit) foo.swf.setButtonDisabled(false);
|
||||
var filediv = xajax.$("SWFup_"+foo.files[FileId].id);
|
||||
filediv.className = true === finished ? 'swf_queued_file_finished' : 'swf_queued_file_removed';
|
||||
setTimeout(function ()
|
||||
{
|
||||
xajax.ext.SWFupload.tools.FadeOut(filediv,100);
|
||||
}, xajax.ext.SWFupload.config.FadeTimeOut);
|
||||
|
||||
foo.files[FileId] = null;
|
||||
delete foo.files[FileId];
|
||||
}
|
||||
this.destroy = function() {
|
||||
|
||||
this.swf.destroy();
|
||||
delete(this.swf);
|
||||
for (a in foo.files) {
|
||||
foo.files[a].destroy();
|
||||
delete (foo.files[a]);
|
||||
}
|
||||
foo.queued=0;
|
||||
delete(foo);
|
||||
}
|
||||
this.fileQueueError = function(swf,code,msg) {
|
||||
if (-110 == code) {
|
||||
msg = "Die gewählte Datei ist zu groß!";
|
||||
alert(msg);
|
||||
}
|
||||
}
|
||||
|
||||
this.getSWF = function() {
|
||||
return this.swf;
|
||||
|
||||
}
|
||||
|
||||
config.file_queued_handler=this.addFile;
|
||||
config.file_queue_error_handler=this.fileQueueError;
|
||||
|
||||
this.swf = new SWFUpload(config);
|
||||
|
||||
}
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.ext.SWFupload.tools._parseFields
|
||||
arguments: children [array],parent [object], config [object], multiple [bool]
|
||||
|
||||
parses the form for fields
|
||||
*/
|
||||
|
||||
|
||||
xajax.ext.SWFupload.tools._parseFields = function(children,parent,config,multiple)
|
||||
{
|
||||
var result={};
|
||||
var iLen = children.length;
|
||||
for (var i = 0; i < iLen; ++i)
|
||||
{
|
||||
var child = children[i];
|
||||
if ('undefined' != typeof child.childNodes)
|
||||
var res2 = xajax.ext.SWFupload.tools._parseFields(child.childNodes,child,config,multiple);
|
||||
result = xajax.ext.SWFupload.tools.mergeObj(result,res2);
|
||||
if (child.name)
|
||||
{
|
||||
if ('file' == child.type)
|
||||
{
|
||||
result[child.name] = xajax.ext.SWFupload.addQueue(child,parent,config,multiple);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.ext.SWFupload.tools.transForm
|
||||
arguments: form_id [integer] ,config [object] ,multiple [bool]
|
||||
|
||||
transforms the all fields of the given form into fileQueue instances
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.tools.transForm = function(form_id,config,multiple)
|
||||
{
|
||||
var oForm = xajax.$(form_id);
|
||||
if (oForm)
|
||||
if (oForm.childNodes) {
|
||||
var fields = xajax.ext.SWFupload.tools._parseFields(oForm.childNodes,oForm,config,multiple);
|
||||
xajax.ext.SWFupload.forms[form_id] = fields;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
|
||||
/*
|
||||
function: xajax.ext.SWFupload.tools.transField
|
||||
arguments: field_id [integer] ,config [object] ,multiple [bool]
|
||||
|
||||
transforms the given field into a fileQueue instance
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.tools.transField = function(field_id,config,multiple)
|
||||
{
|
||||
try {
|
||||
var oField = xajax.$(field_id);
|
||||
if ('undefined' != typeof oField) return xajax.ext.SWFupload.fields[field_id] = xajax.ext.SWFupload.addQueue(oField,oField.parentNode,config,multiple);
|
||||
|
||||
}catch(ex) {}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.ext.SWFupload.tools.destroyForm
|
||||
arguments: form_id [integer]
|
||||
|
||||
destroys the given form
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.tools.destroyForm = function(form_id)
|
||||
{
|
||||
if ("undefined" == typeof xajax.ext.SWFupload.forms[form_id]) return;
|
||||
for (a in xajax.ext.SWFupload.forms[form_id])
|
||||
{
|
||||
var key = xajax.ext.SWFupload.forms[form_id][a];
|
||||
xajax.ext.SWFupload.queues[key].destroy();
|
||||
delete xajax.ext.SWFupload.queues[key];
|
||||
}
|
||||
delete xajax.ext.SWFupload.forms[form_id];
|
||||
return;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.ext.SWFupload.tools.destroyField
|
||||
arguments: field_id [integer]
|
||||
|
||||
destroys the given field
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.tools.destroyField = function(field_id)
|
||||
{
|
||||
if ("undefined" == typeof xajax.ext.SWFupload.fields[field_id]) return;
|
||||
var key = xajax.ext.SWFupload.fields[field_id];
|
||||
xajax.ext.SWFupload.queues[key].destroy();
|
||||
delete(xajax.ext.SWFupload.queues[key]);
|
||||
delete xajax.ext.SWFupload.fields[field_id];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
|
||||
/*
|
||||
function: xajax.ext.SWFupload.tools.FadeOut
|
||||
arguments: elm [object], opacity [integer]
|
||||
|
||||
fades a div
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.tools.FadeOut = function(elm,opacity)
|
||||
{
|
||||
var reduceOpacityBy = 15;
|
||||
var rate = 40;
|
||||
if (opacity > 0)
|
||||
{
|
||||
opacity -= reduceOpacityBy;
|
||||
if (opacity < 0)
|
||||
{
|
||||
opacity = 0;
|
||||
}
|
||||
|
||||
if (elm.filters)
|
||||
{
|
||||
try
|
||||
{
|
||||
elm.filters.item("DXImageTransform.Microsoft.Alpha").opacity = opacity;
|
||||
} catch (e) {
|
||||
// If it is not set initially, the browser will throw an error. This will set it if it is not set yet.
|
||||
elm.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + opacity + ")";
|
||||
}
|
||||
} else {
|
||||
elm.style.opacity = opacity / 100;
|
||||
}
|
||||
}
|
||||
|
||||
if ( opacity > 0)
|
||||
{
|
||||
var oSelf = this;
|
||||
setTimeout(function ()
|
||||
{
|
||||
xajax.ext.SWFupload.tools.FadeOut(elm,opacity);
|
||||
}, rate);
|
||||
} else {
|
||||
var parent = elm.parentNode;
|
||||
parent.removeChild(elm);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
|
||||
/*
|
||||
function: xajax.ext.SWFupload.tools.formatBytes
|
||||
arguments: bytes [integer]
|
||||
|
||||
returns string with formatted size (kB / MB)
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.tools.formatBytes = function(bytes)
|
||||
{
|
||||
|
||||
var ret = {};
|
||||
if (bytes / 1204 < 1024)
|
||||
{
|
||||
return (Math.round(bytes / 1024 * 100)/100).toString()+ " kB";
|
||||
} else {
|
||||
return (Math.round(bytes / 1024 / 1024 * 100)/100).toString()+ " MB";
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
|
||||
/*
|
||||
function: xajax.ext.SWFupload.tools.mergeObj
|
||||
arguments: n objects
|
||||
|
||||
Merges all objects and returns a single object.
|
||||
Newrt keys override existing keys.
|
||||
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.tools.mergeObj = function()
|
||||
{
|
||||
if ('object' != typeof arguments) return;
|
||||
|
||||
var res = {};
|
||||
var len = arguments.length;
|
||||
for (var i=0;i<len;i++)
|
||||
{
|
||||
var obj = arguments[i];
|
||||
for (a in obj)
|
||||
{
|
||||
res[a] = obj[a];
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.ext.SWFupload.tools.getId
|
||||
arguments:
|
||||
|
||||
returns a 'unique' (rand) id
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.tools.getId = function()
|
||||
{
|
||||
var pid_str = "";
|
||||
for (i=0;i<=3;i++) {
|
||||
var pid = 0;
|
||||
pid = Math.random();
|
||||
while( Math.ceil(pid).toString().length<8)
|
||||
{
|
||||
pid *= 10;
|
||||
}
|
||||
pid = Math.ceil(pid).toString();
|
||||
pid_str = pid_str+pid.toString();
|
||||
}
|
||||
return pid_str;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.command.handler.register('SWFup_dfi')
|
||||
arguments: object
|
||||
|
||||
xajax response command for ext.SWFupload.tools.destroyField
|
||||
*/
|
||||
xajax.command.handler.register('SWFup_dfi', function(args)
|
||||
{
|
||||
args.cmdFullName = 'ext.SWFupload.tools.destroyField';
|
||||
xajax.ext.SWFupload.tools.destroyField(args.id);
|
||||
return true;
|
||||
});
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.command.handler.register('SWFup_dfo')
|
||||
arguments: object
|
||||
|
||||
xajax response command for ext.SWFupload.tools.destroyForm
|
||||
*/
|
||||
|
||||
xajax.command.handler.register('SWFup_dfo', function(args)
|
||||
{
|
||||
args.cmdFullName = 'ext.SWFupload.tools.destroyForm';
|
||||
xajax.ext.SWFupload.tools.destroyForm(args.id);
|
||||
return true;
|
||||
});
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.command.handler.register('SWFup_tfi'I
|
||||
arguments: object
|
||||
|
||||
xajax response command for ext.SWFupload.tools.transField
|
||||
*/
|
||||
|
||||
xajax.command.handler.register('SWFup_tfi', function(args)
|
||||
{
|
||||
args.cmdFullName = 'ext.SWFupload.tools.transField';
|
||||
|
||||
// if ("string" == typeof args.data.config.upload_complete_handler) {
|
||||
// try {
|
||||
// eval("var foo = "+args.data.config.upload_complete_handler);
|
||||
// args.data.config.upload_complete_handler = foo;
|
||||
// } catch(ex) {delete(args.data.config.upload_complete_handler);}
|
||||
// }
|
||||
|
||||
if ("string" == typeof args.data.config.upload_success_handler) {
|
||||
try {
|
||||
eval("var foo = "+args.data.config.upload_success_handler);
|
||||
args.data.config.upload_success_handler = foo;
|
||||
} catch(ex) {delete(args.data.config.upload_success_handler);}
|
||||
}
|
||||
|
||||
xajax.ext.SWFupload.tools.transField(args.id, args.data.config,args.data.multi);
|
||||
return true;
|
||||
});
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.command.handler.register('SWFup_tfo']
|
||||
arguments: object
|
||||
|
||||
xajax response command for ext.SWFupload.tools.transForm
|
||||
*/
|
||||
xajax.command.handler.register('SWFup_tfo',function(args)
|
||||
{
|
||||
try {
|
||||
args.cmdFullName = 'ext.SWFupload.tools.transForm';
|
||||
// if ("string" == typeof args.data.config.upload_complete_handler)
|
||||
// {
|
||||
// try {
|
||||
// eval("var foo = "+args.data.config.upload_complete_handler);
|
||||
// args.data.config.upload_complete_handler = foo;
|
||||
// } catch(ex) {delete(args.data.config.upload_complete_handler);}
|
||||
// }
|
||||
|
||||
if ("string" == typeof args.data.config.upload_success_handler)
|
||||
{
|
||||
try
|
||||
{
|
||||
eval("var foo = "+args.data.config.upload_success_handler);
|
||||
args.data.config.upload_success_handler = foo;
|
||||
} catch(ex)
|
||||
{
|
||||
delete(args.data.config.upload_success_handler);
|
||||
}
|
||||
}
|
||||
xajax.ext.SWFupload.tools.transForm(args.id, args.data.config,args.data.multi);
|
||||
|
||||
} catch(ex)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
});
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
|
||||
|
||||
xajax.ext.SWFupload.bak = {};
|
||||
xajax.ext.SWFupload.bak.prepareRequest = xajax.prepareRequest;
|
||||
xajax.ext.SWFupload.bak.submitRequest = xajax.submitRequest;
|
||||
xajax.ext.SWFupload.bak.responseProcessor = xajax.responseProcessor;
|
||||
xajax.ext.SWFupload.bak.processParameters = xajax.processParameters;
|
||||
|
||||
xajax.prepareRequest = xajax.ext.SWFupload.request.prepareRequest;
|
||||
xajax.submitRequest = xajax.ext.SWFupload.request.submitRequest;
|
||||
xajax.processParameters = xajax.ext.SWFupload.request.processParameters;
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
|
||||
Function: DOMParser
|
||||
|
||||
Prototype DomParser for IE/Opera
|
||||
|
||||
*/
|
||||
if (typeof DOMParser == "undefined") {
|
||||
DOMParser = function () {}
|
||||
|
||||
DOMParser.prototype.parseFromString = function (str, contentType) {
|
||||
if (typeof ActiveXObject != "undefined") {
|
||||
var d = new ActiveXObject("Microsoft.XMLDOM");
|
||||
d.loadXML(str);
|
||||
return d;
|
||||
} else if (typeof XMLHttpRequest != "undefined") {
|
||||
var req = new XMLHttpRequest;
|
||||
req.open("GET", "data:" + (contentType || "application/xml") +
|
||||
";charset=utf-8," + encodeURIComponent(str), false);
|
||||
if (req.overrideMimeType) {
|
||||
req.overrideMimeType(contentType);
|
||||
}
|
||||
req.send(null);
|
||||
return req.responseXML;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,946 @@
|
||||
/**
|
||||
* SWFUpload: http://www.swfupload.org, http://swfupload.googlecode.com
|
||||
*
|
||||
* mmSWFUpload 1.0: Flash upload dialog - http://profandesign.se/swfupload/, http://www.vinterwebb.se/
|
||||
*
|
||||
* SWFUpload is (c) 2006-2007 Lars Huring, Olov Nilzén and Mammon Media and is released under the MIT License:
|
||||
* http://www.opensource.org/licenses/mit-license.php
|
||||
*
|
||||
* SWFUpload 2 is (c) 2007-2008 Jake Roberts and is released under the MIT License:
|
||||
* http://www.opensource.org/licenses/mit-license.php
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* ******************* */
|
||||
/* Constructor & Init */
|
||||
/* ******************* */
|
||||
var SWFUpload;
|
||||
|
||||
if (SWFUpload == undefined) {
|
||||
SWFUpload = function (settings) {
|
||||
this.initSWFUpload(settings);
|
||||
};
|
||||
}
|
||||
|
||||
SWFUpload.prototype.initSWFUpload = function (settings) {
|
||||
try {
|
||||
this.customSettings = {}; // A container where developers can place their own settings associated with this instance.
|
||||
this.settings = settings;
|
||||
this.eventQueue = [];
|
||||
this.movieName = "SWFUpload_" + SWFUpload.movieCount++;
|
||||
this.movieElement = null;
|
||||
|
||||
|
||||
// Setup global control tracking
|
||||
SWFUpload.instances[this.movieName] = this;
|
||||
|
||||
// Load the settings. Load the Flash movie.
|
||||
this.initSettings();
|
||||
this.loadFlash();
|
||||
this.displayDebugInfo();
|
||||
} catch (ex) {
|
||||
delete SWFUpload.instances[this.movieName];
|
||||
throw ex;
|
||||
}
|
||||
};
|
||||
|
||||
/* *************** */
|
||||
/* Static Members */
|
||||
/* *************** */
|
||||
SWFUpload.instances = {};
|
||||
SWFUpload.movieCount = 0;
|
||||
SWFUpload.version = "2.2.0 Beta 3";
|
||||
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"
|
||||
};
|
||||
|
||||
/* ******************** */
|
||||
/* Instance Members */
|
||||
/* ******************** */
|
||||
|
||||
// Private: initSettings ensures that all the
|
||||
// settings are set, getting a default value if one was not assigned.
|
||||
SWFUpload.prototype.initSettings = function () {
|
||||
this.ensureDefault = function (settingName, defaultValue) {
|
||||
this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
|
||||
};
|
||||
|
||||
// Upload backend settings
|
||||
this.ensureDefault("upload_url", "");
|
||||
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", []);
|
||||
|
||||
// File Settings
|
||||
this.ensureDefault("file_types", "*.*");
|
||||
this.ensureDefault("file_types_description", "All Files");
|
||||
this.ensureDefault("file_size_limit", 0); // Default zero means "unlimited"
|
||||
this.ensureDefault("file_upload_limit", 0);
|
||||
this.ensureDefault("file_queue_limit", 0);
|
||||
|
||||
// Flash Settings
|
||||
this.ensureDefault("flash_url", "swfupload.swf");
|
||||
this.ensureDefault("prevent_swf_caching", true);
|
||||
|
||||
// Button Settings
|
||||
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", null);
|
||||
this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW);
|
||||
this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW);
|
||||
|
||||
// Debug Settings
|
||||
this.ensureDefault("debug", false);
|
||||
this.settings.debug_enabled = this.settings.debug; // Here to maintain v2 API
|
||||
|
||||
// Event Handlers
|
||||
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", {});
|
||||
|
||||
// Other settings
|
||||
this.customSettings = this.settings.custom_settings;
|
||||
|
||||
// Update the flash url if needed
|
||||
if (this.settings.prevent_swf_caching) {
|
||||
this.settings.flash_url = this.settings.flash_url + "?swfuploadrnd=" + Math.floor(Math.random() * 999999999);
|
||||
}
|
||||
|
||||
delete this.ensureDefault;
|
||||
};
|
||||
|
||||
SWFUpload.prototype.loadFlash = function () {
|
||||
if (this.settings.button_placeholder_id !== "") {
|
||||
this.replaceWithFlash();
|
||||
} else {
|
||||
this.appendFlash();
|
||||
}
|
||||
};
|
||||
|
||||
// Private: appendFlash gets the HTML tag for the Flash
|
||||
// It then appends the flash to the body
|
||||
SWFUpload.prototype.appendFlash = function () {
|
||||
var targetElement, container;
|
||||
|
||||
// Make sure an element with the ID we are going to use doesn't already exist
|
||||
if (document.getElementById(this.movieName) !== null) {
|
||||
throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
|
||||
}
|
||||
|
||||
// Get the body tag where we will be adding the flash movie
|
||||
targetElement = document.getElementsByTagName("body")[0];
|
||||
|
||||
if (targetElement == undefined) {
|
||||
throw "Could not find the 'body' element.";
|
||||
}
|
||||
|
||||
// Append the container and load the flash
|
||||
container = document.createElement("div");
|
||||
container.style.width = "1px";
|
||||
container.style.height = "1px";
|
||||
container.style.overflow = "hidden";
|
||||
|
||||
targetElement.appendChild(container);
|
||||
container.innerHTML = this.getFlashHTML(); // Using innerHTML is non-standard but the only sensible way to dynamically add Flash in IE (and maybe other browsers)
|
||||
|
||||
// Fix IE Flash/Form bug
|
||||
if (window[this.movieName] == undefined) {
|
||||
window[this.movieName] = this.getMovieElement();
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
// Private: replaceWithFlash replaces the button_placeholder element with the flash movie.
|
||||
SWFUpload.prototype.replaceWithFlash = function () {
|
||||
var targetElement, tempParent;
|
||||
|
||||
// Make sure an element with the ID we are going to use doesn't already exist
|
||||
if (document.getElementById(this.movieName) !== null) {
|
||||
throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
|
||||
}
|
||||
|
||||
// Get the element where we will be placing the flash movie
|
||||
targetElement = document.getElementById(this.settings.button_placeholder_id);
|
||||
|
||||
if (targetElement == undefined) {
|
||||
throw "Could not find the placeholder element.";
|
||||
}
|
||||
|
||||
// Append the container and load the flash
|
||||
tempParent = document.createElement("div");
|
||||
tempParent.innerHTML = this.getFlashHTML(); // Using innerHTML is non-standard but the only sensible way to dynamically add Flash in IE (and maybe other browsers)
|
||||
targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement);
|
||||
|
||||
// Fix IE Flash/Form bug
|
||||
if (window[this.movieName] == undefined) {
|
||||
window[this.movieName] = this.getMovieElement();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// Private: getFlashHTML generates the object tag needed to embed the flash in to the document
|
||||
SWFUpload.prototype.getFlashHTML = function () {
|
||||
// Flash Satay object syntax: http://www.alistapart.com/articles/flashsatay
|
||||
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("");
|
||||
};
|
||||
|
||||
// Private: getFlashVars builds the parameter string that will be passed
|
||||
// to flash in the flashvars param.
|
||||
SWFUpload.prototype.getFlashVars = function () {
|
||||
// Build a string from the post param object
|
||||
var paramString = this.buildParamString();
|
||||
var httpSuccessString = this.settings.http_success.join(",");
|
||||
|
||||
// Build the parameter string
|
||||
return ["movieName=", encodeURIComponent(this.movieName),
|
||||
"&uploadURL=", encodeURIComponent(this.settings.upload_url),
|
||||
"&useQueryString=", encodeURIComponent(this.settings.use_query_string),
|
||||
"&requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),
|
||||
"&httpSuccess=", encodeURIComponent(httpSuccessString),
|
||||
"&params=", encodeURIComponent(paramString),
|
||||
"&filePostName=", encodeURIComponent(this.settings.file_post_name),
|
||||
"&fileTypes=", encodeURIComponent(this.settings.file_types),
|
||||
"&fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),
|
||||
"&fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),
|
||||
"&fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),
|
||||
"&fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),
|
||||
"&debugEnabled=", encodeURIComponent(this.settings.debug_enabled),
|
||||
"&buttonImageURL=", encodeURIComponent(this.settings.button_image_url),
|
||||
"&buttonWidth=", encodeURIComponent(this.settings.button_width),
|
||||
"&buttonHeight=", encodeURIComponent(this.settings.button_height),
|
||||
"&buttonText=", encodeURIComponent(this.settings.button_text),
|
||||
"&buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding),
|
||||
"&buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding),
|
||||
"&buttonTextStyle=", encodeURIComponent(this.settings.button_text_style),
|
||||
"&buttonAction=", encodeURIComponent(this.settings.button_action),
|
||||
"&buttonDisabled=", encodeURIComponent(this.settings.button_disabled),
|
||||
"&buttonCursor=", encodeURIComponent(this.settings.button_cursor)
|
||||
].join("");
|
||||
};
|
||||
|
||||
// Public: getMovieElement retrieves the DOM reference to the Flash element added by SWFUpload
|
||||
// The element is cached after the first lookup
|
||||
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;
|
||||
};
|
||||
|
||||
// Private: buildParamString takes the name/value pairs in the post_params setting object
|
||||
// and joins them up in to a string formatted "name=value&name=value"
|
||||
SWFUpload.prototype.buildParamString = function () {
|
||||
var postParams = this.settings.post_params;
|
||||
var paramStringPairs = [];
|
||||
|
||||
if (typeof(postParams) === "object") {
|
||||
for (var name in postParams) {
|
||||
if (postParams.hasOwnProperty(name)) {
|
||||
paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return paramStringPairs.join("&");
|
||||
};
|
||||
|
||||
// Public: Used to remove a SWFUpload instance from the page. This method strives to remove
|
||||
// all references to the SWF, and other objects so memory is properly freed.
|
||||
// Returns true if everything was destroyed. Returns a false if a failure occurs leaving SWFUpload in an inconsistant state.
|
||||
// Credits: Major improvements provided by steffen
|
||||
SWFUpload.prototype.destroy = function () {
|
||||
try {
|
||||
// Make sure Flash is done before we try to remove it
|
||||
this.cancelUpload(null, false);
|
||||
;
|
||||
// Remove the SWFUpload DOM nodes
|
||||
var movieElement = null;
|
||||
movieElement = this.getMovieElement();
|
||||
|
||||
if (movieElement) {
|
||||
// Loop through all the movie's properties and remove all function references (DOM/JS IE 6/7 memory leak workaround)
|
||||
for (var i in movieElement) {
|
||||
try {
|
||||
if (typeof(movieElement[i]) === "function") {
|
||||
movieElement[i] = null;
|
||||
}
|
||||
} catch (ex1) {}
|
||||
}
|
||||
|
||||
// Remove the Movie Element from the page
|
||||
try {
|
||||
movieElement.parentNode.removeChild(movieElement);
|
||||
} catch (ex) {}
|
||||
}
|
||||
|
||||
|
||||
// Remove IE form fix reference
|
||||
window[this.movieName] = null;
|
||||
|
||||
// Destroy other references
|
||||
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 (ex1) {
|
||||
alert(ex);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// Public: displayDebugInfo prints out settings and configuration
|
||||
// information about this SWFUpload instance.
|
||||
// This function (and any references to it) can be deleted when placing
|
||||
// SWFUpload in production.
|
||||
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", "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_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("")
|
||||
);
|
||||
};
|
||||
|
||||
/* Note: addSetting and getSetting are no longer used by SWFUpload but are included
|
||||
the maintain v2 API compatibility
|
||||
*/
|
||||
// Public: (Deprecated) addSetting adds a setting value. If the value given is undefined or null then the default_value is used.
|
||||
SWFUpload.prototype.addSetting = function (name, value, default_value) {
|
||||
if (value == undefined) {
|
||||
return (this.settings[name] = default_value);
|
||||
} else {
|
||||
return (this.settings[name] = value);
|
||||
}
|
||||
};
|
||||
|
||||
// Public: (Deprecated) getSetting gets a setting. Returns an empty string if the setting was not found.
|
||||
SWFUpload.prototype.getSetting = function (name) {
|
||||
if (this.settings[name] != undefined) {
|
||||
return this.settings[name];
|
||||
}
|
||||
|
||||
return "";
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Private: callFlash handles function calls made to the Flash element.
|
||||
// Calls are made with a setTimeout for some functions to work around
|
||||
// bugs in the ExternalInterface library.
|
||||
SWFUpload.prototype.callFlash = function (functionName, argumentArray) {
|
||||
argumentArray = argumentArray || [];
|
||||
|
||||
var movieElement = this.getMovieElement();
|
||||
var returnValue, returnString;
|
||||
|
||||
// Flash's method if calling ExternalInterface methods (code adapted from MooTools).
|
||||
try {
|
||||
returnString = movieElement.CallFunction('<invoke name="' + functionName + '" returntype="javascript">' + __flash__argumentsToXML(argumentArray, 0) + '</invoke>');
|
||||
returnValue = eval(returnString);
|
||||
} catch (ex) {
|
||||
throw "Call to " + functionName + " failed";
|
||||
}
|
||||
|
||||
// Unescape file post param values
|
||||
if (returnValue != undefined && typeof returnValue.post === "object") {
|
||||
returnValue = this.unescapeFilePostParams(returnValue);
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
};
|
||||
|
||||
|
||||
/* *****************************
|
||||
-- Flash control methods --
|
||||
Your UI should use these
|
||||
to operate SWFUpload
|
||||
***************************** */
|
||||
|
||||
// WARNING: this function does not work in Flash Player 10
|
||||
// Public: selectFile causes a File Selection Dialog window to appear. This
|
||||
// dialog only allows 1 file to be selected.
|
||||
SWFUpload.prototype.selectFile = function () {
|
||||
this.callFlash("SelectFile");
|
||||
};
|
||||
|
||||
// WARNING: this function does not work in Flash Player 10
|
||||
// Public: selectFiles causes a File Selection Dialog window to appear/ This
|
||||
// dialog allows the user to select any number of files
|
||||
// Flash Bug Warning: Flash limits the number of selectable files based on the combined length of the file names.
|
||||
// If the selection name length is too long the dialog will fail in an unpredictable manner. There is no work-around
|
||||
// for this bug.
|
||||
SWFUpload.prototype.selectFiles = function () {
|
||||
this.callFlash("SelectFiles");
|
||||
};
|
||||
|
||||
|
||||
// Public: startUpload starts uploading the first file in the queue unless
|
||||
// the optional parameter 'fileID' specifies the ID
|
||||
SWFUpload.prototype.startUpload = function (fileID) {
|
||||
this.callFlash("StartUpload", [fileID]);
|
||||
};
|
||||
|
||||
// Public: cancelUpload cancels any queued file. The fileID parameter may be the file ID or index.
|
||||
// If you do not specify a fileID the current uploading file or first file in the queue is cancelled.
|
||||
// If you do not want the uploadError event to trigger you can specify false for the triggerErrorEvent parameter.
|
||||
SWFUpload.prototype.cancelUpload = function (fileID, triggerErrorEvent) {
|
||||
if (triggerErrorEvent !== false) {
|
||||
triggerErrorEvent = true;
|
||||
}
|
||||
this.callFlash("CancelUpload", [fileID, triggerErrorEvent]);
|
||||
};
|
||||
|
||||
// Public: stopUpload stops the current upload and requeues the file at the beginning of the queue.
|
||||
// If nothing is currently uploading then nothing happens.
|
||||
SWFUpload.prototype.stopUpload = function () {
|
||||
this.callFlash("StopUpload");
|
||||
};
|
||||
|
||||
/* ************************
|
||||
* Settings methods
|
||||
* These methods change the SWFUpload settings.
|
||||
* SWFUpload settings should not be changed directly on the settings object
|
||||
* since many of the settings need to be passed to Flash in order to take
|
||||
* effect.
|
||||
* *********************** */
|
||||
|
||||
// Public: getStats gets the file statistics object.
|
||||
SWFUpload.prototype.getStats = function () {
|
||||
return this.callFlash("GetStats");
|
||||
};
|
||||
|
||||
// Public: setStats changes the SWFUpload statistics. You shouldn't need to
|
||||
// change the statistics but you can. Changing the statistics does not
|
||||
// affect SWFUpload accept for the successful_uploads count which is used
|
||||
// by the upload_limit setting to determine how many files the user may upload.
|
||||
SWFUpload.prototype.setStats = function (statsObject) {
|
||||
this.callFlash("SetStats", [statsObject]);
|
||||
};
|
||||
|
||||
// Public: getFile retrieves a File object by ID or Index. If the file is
|
||||
// not found then 'null' is returned.
|
||||
SWFUpload.prototype.getFile = function (fileID) {
|
||||
if (typeof(fileID) === "number") {
|
||||
return this.callFlash("GetFileByIndex", [fileID]);
|
||||
} else {
|
||||
return this.callFlash("GetFile", [fileID]);
|
||||
}
|
||||
};
|
||||
|
||||
// Public: addFileParam sets a name/value pair that will be posted with the
|
||||
// file specified by the Files ID. If the name already exists then the
|
||||
// exiting value will be overwritten.
|
||||
SWFUpload.prototype.addFileParam = function (fileID, name, value) {
|
||||
return this.callFlash("AddFileParam", [fileID, name, value]);
|
||||
};
|
||||
|
||||
// Public: removeFileParam removes a previously set (by addFileParam) name/value
|
||||
// pair from the specified file.
|
||||
SWFUpload.prototype.removeFileParam = function (fileID, name) {
|
||||
this.callFlash("RemoveFileParam", [fileID, name]);
|
||||
};
|
||||
|
||||
// Public: setUploadUrl changes the upload_url setting.
|
||||
SWFUpload.prototype.setUploadURL = function (url) {
|
||||
this.settings.upload_url = url.toString();
|
||||
this.callFlash("SetUploadURL", [url]);
|
||||
};
|
||||
|
||||
// Public: setPostParams changes the post_params setting
|
||||
SWFUpload.prototype.setPostParams = function (paramsObject) {
|
||||
this.settings.post_params = paramsObject;
|
||||
this.callFlash("SetPostParams", [paramsObject]);
|
||||
};
|
||||
|
||||
// Public: addPostParam adds post name/value pair. Each name can have only one value.
|
||||
SWFUpload.prototype.addPostParam = function (name, value) {
|
||||
this.settings.post_params[name] = value;
|
||||
this.callFlash("SetPostParams", [this.settings.post_params]);
|
||||
};
|
||||
|
||||
// Public: removePostParam deletes post name/value pair.
|
||||
SWFUpload.prototype.removePostParam = function (name) {
|
||||
delete this.settings.post_params[name];
|
||||
this.callFlash("SetPostParams", [this.settings.post_params]);
|
||||
};
|
||||
|
||||
// Public: setFileTypes changes the file_types setting and the file_types_description setting
|
||||
SWFUpload.prototype.setFileTypes = function (types, description) {
|
||||
this.settings.file_types = types;
|
||||
this.settings.file_types_description = description;
|
||||
this.callFlash("SetFileTypes", [types, description]);
|
||||
};
|
||||
|
||||
// Public: setFileSizeLimit changes the file_size_limit setting
|
||||
SWFUpload.prototype.setFileSizeLimit = function (fileSizeLimit) {
|
||||
this.settings.file_size_limit = fileSizeLimit;
|
||||
this.callFlash("SetFileSizeLimit", [fileSizeLimit]);
|
||||
};
|
||||
|
||||
// Public: setFileUploadLimit changes the file_upload_limit setting
|
||||
SWFUpload.prototype.setFileUploadLimit = function (fileUploadLimit) {
|
||||
this.settings.file_upload_limit = fileUploadLimit;
|
||||
this.callFlash("SetFileUploadLimit", [fileUploadLimit]);
|
||||
};
|
||||
|
||||
// Public: setFileQueueLimit changes the file_queue_limit setting
|
||||
SWFUpload.prototype.setFileQueueLimit = function (fileQueueLimit) {
|
||||
this.settings.file_queue_limit = fileQueueLimit;
|
||||
this.callFlash("SetFileQueueLimit", [fileQueueLimit]);
|
||||
};
|
||||
|
||||
// Public: setFilePostName changes the file_post_name setting
|
||||
SWFUpload.prototype.setFilePostName = function (filePostName) {
|
||||
this.settings.file_post_name = filePostName;
|
||||
this.callFlash("SetFilePostName", [filePostName]);
|
||||
};
|
||||
|
||||
// Public: setUseQueryString changes the use_query_string setting
|
||||
SWFUpload.prototype.setUseQueryString = function (useQueryString) {
|
||||
this.settings.use_query_string = useQueryString;
|
||||
this.callFlash("SetUseQueryString", [useQueryString]);
|
||||
};
|
||||
|
||||
// Public: setRequeueOnError changes the requeue_on_error setting
|
||||
SWFUpload.prototype.setRequeueOnError = function (requeueOnError) {
|
||||
this.settings.requeue_on_error = requeueOnError;
|
||||
this.callFlash("SetRequeueOnError", [requeueOnError]);
|
||||
};
|
||||
|
||||
// Public: setHTTPSuccess changes the http_success setting
|
||||
SWFUpload.prototype.setHTTPSuccess = function (http_status_codes) {
|
||||
if (typeof http_status_codes === "string") {
|
||||
http_status_codes = http_status_codes.replace(" ", "").split(",");
|
||||
}
|
||||
|
||||
this.settings.http_success = http_status_codes;
|
||||
this.callFlash("SetHTTPSuccess", [http_status_codes]);
|
||||
};
|
||||
|
||||
|
||||
// Public: setDebugEnabled changes the debug_enabled setting
|
||||
SWFUpload.prototype.setDebugEnabled = function (debugEnabled) {
|
||||
this.settings.debug_enabled = debugEnabled;
|
||||
this.callFlash("SetDebugEnabled", [debugEnabled]);
|
||||
};
|
||||
|
||||
// Public: setButtonImageURL loads a button image sprite
|
||||
SWFUpload.prototype.setButtonImageURL = function (buttonImageURL) {
|
||||
if (buttonImageURL == undefined) {
|
||||
buttonImageURL = "";
|
||||
}
|
||||
|
||||
this.settings.button_image_url = buttonImageURL;
|
||||
this.callFlash("SetButtonImageURL", [buttonImageURL]);
|
||||
};
|
||||
|
||||
// Public: setButtonDimensions resizes the Flash Movie and button
|
||||
SWFUpload.prototype.setButtonDimensions = function (width, height) {
|
||||
this.settings.button_width = width;
|
||||
this.settings.button_height = height;
|
||||
|
||||
var movie = this.getMovieElement();
|
||||
if (movie != undefined) {
|
||||
movie.style.width = width + "px";
|
||||
movie.style.height = height + "px";
|
||||
}
|
||||
|
||||
this.callFlash("SetButtonDimensions", [width, height]);
|
||||
};
|
||||
// Public: setButtonText Changes the text overlaid on the button
|
||||
SWFUpload.prototype.setButtonText = function (html) {
|
||||
this.settings.button_text = html;
|
||||
this.callFlash("SetButtonText", [html]);
|
||||
};
|
||||
// Public: setButtonTextPadding changes the top and left padding of the text overlay
|
||||
SWFUpload.prototype.setButtonTextPadding = function (left, top) {
|
||||
this.settings.button_text_top_padding = top;
|
||||
this.settings.button_text_left_padding = left;
|
||||
this.callFlash("SetButtonTextPadding", [left, top]);
|
||||
};
|
||||
|
||||
// Public: setButtonTextStyle changes the CSS used to style the HTML/Text overlaid on the button
|
||||
SWFUpload.prototype.setButtonTextStyle = function (css) {
|
||||
this.settings.button_text_style = css;
|
||||
this.callFlash("SetButtonTextStyle", [css]);
|
||||
};
|
||||
// Public: setButtonDisabled disables/enables the button
|
||||
SWFUpload.prototype.setButtonDisabled = function (isDisabled) {
|
||||
this.settings.button_disabled = isDisabled;
|
||||
this.callFlash("SetButtonDisabled", [isDisabled]);
|
||||
};
|
||||
// Public: setButtonAction sets the action that occurs when the button is clicked
|
||||
SWFUpload.prototype.setButtonAction = function (buttonAction) {
|
||||
this.settings.button_action = buttonAction;
|
||||
this.callFlash("SetButtonAction", [buttonAction]);
|
||||
};
|
||||
|
||||
// Public: setButtonCursor changes the mouse cursor displayed when hovering over the button
|
||||
SWFUpload.prototype.setButtonCursor = function (cursor) {
|
||||
this.settings.button_cursor = cursor;
|
||||
this.callFlash("SetButtonCursor", [cursor]);
|
||||
};
|
||||
|
||||
/* *******************************
|
||||
Flash Event Interfaces
|
||||
These functions are used by Flash to trigger the various
|
||||
events.
|
||||
|
||||
All these functions a Private.
|
||||
|
||||
Because the ExternalInterface library is buggy the event calls
|
||||
are added to a queue and the queue then executed by a setTimeout.
|
||||
This ensures that events are executed in a determinate order and that
|
||||
the ExternalInterface bugs are avoided.
|
||||
******************************* */
|
||||
|
||||
SWFUpload.prototype.queueEvent = function (handlerName, argumentArray) {
|
||||
// Warning: Don't call this.debug inside here or you'll create an infinite loop
|
||||
|
||||
if (argumentArray == undefined) {
|
||||
argumentArray = [];
|
||||
} else if (!(argumentArray instanceof Array)) {
|
||||
argumentArray = [argumentArray];
|
||||
}
|
||||
|
||||
var self = this;
|
||||
if (typeof this.settings[handlerName] === "function") {
|
||||
// Queue the event
|
||||
this.eventQueue.push(function () {
|
||||
this.settings[handlerName].apply(this, argumentArray);
|
||||
});
|
||||
|
||||
// Execute the next queued event
|
||||
setTimeout(function () {
|
||||
self.executeNextEvent();
|
||||
}, 0);
|
||||
|
||||
} else if (this.settings[handlerName] !== null) {
|
||||
throw "Event handler " + handlerName + " is unknown or is not a function";
|
||||
}
|
||||
};
|
||||
|
||||
// Private: Causes the next event in the queue to be executed. Since events are queued using a setTimeout
|
||||
// we must queue them in order to garentee that they are executed in order.
|
||||
SWFUpload.prototype.executeNextEvent = function () {
|
||||
// Warning: Don't call this.debug inside here or you'll create an infinite loop
|
||||
|
||||
var f = this.eventQueue ? this.eventQueue.shift() : null;
|
||||
if (typeof(f) === "function") {
|
||||
f.apply(this);
|
||||
}
|
||||
};
|
||||
|
||||
// Private: unescapeFileParams is part of a workaround for a flash bug where objects passed through ExternalInterface cannot have
|
||||
// properties that contain characters that are not valid for JavaScript identifiers. To work around this
|
||||
// the Flash Component escapes the parameter names and we must unescape again before passing them along.
|
||||
SWFUpload.prototype.unescapeFilePostParams = function (file) {
|
||||
var reg = /[$]([0-9a-f]{4})/i;
|
||||
var unescapedPost = {};
|
||||
var uk;
|
||||
|
||||
if (file != undefined) {
|
||||
for (var k in file.post) {
|
||||
if (file.post.hasOwnProperty(k)) {
|
||||
uk = k;
|
||||
var match;
|
||||
while ((match = reg.exec(uk)) !== null) {
|
||||
uk = uk.replace(match[0], String.fromCharCode(parseInt("0x" + match[1], 16)));
|
||||
}
|
||||
unescapedPost[uk] = file.post[k];
|
||||
}
|
||||
}
|
||||
|
||||
file.post = unescapedPost;
|
||||
}
|
||||
|
||||
return file;
|
||||
};
|
||||
|
||||
SWFUpload.prototype.flashReady = function () {
|
||||
// Check that the movie element is loaded correctly with its ExternalInterface methods defined
|
||||
var movieElement = this.getMovieElement();
|
||||
|
||||
// Pro-actively unhook all the Flash functions
|
||||
if (typeof(movieElement.CallFunction) === "unknown") { // We only want to do this in IE
|
||||
this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)");
|
||||
for (var key in movieElement) {
|
||||
try {
|
||||
if (typeof(movieElement[key]) === "function") {
|
||||
movieElement[key] = null;
|
||||
}
|
||||
} catch (ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.queueEvent("swfupload_loaded_handler");
|
||||
};
|
||||
|
||||
|
||||
/* This is a chance to do something before the browse window opens */
|
||||
SWFUpload.prototype.fileDialogStart = function () {
|
||||
this.queueEvent("file_dialog_start_handler");
|
||||
};
|
||||
|
||||
|
||||
/* Called when a file is successfully added to the queue. */
|
||||
SWFUpload.prototype.fileQueued = function (file) {
|
||||
file = this.unescapeFilePostParams(file);
|
||||
this.queueEvent("file_queued_handler", file);
|
||||
};
|
||||
|
||||
|
||||
/* Handle errors that occur when an attempt to queue a file fails. */
|
||||
SWFUpload.prototype.fileQueueError = function (file, errorCode, message) {
|
||||
file = this.unescapeFilePostParams(file);
|
||||
this.queueEvent("file_queue_error_handler", [file, errorCode, message]);
|
||||
};
|
||||
|
||||
/* Called after the file dialog has closed and the selected files have been queued.
|
||||
You could call startUpload here if you want the queued files to begin uploading immediately. */
|
||||
SWFUpload.prototype.fileDialogComplete = function (numFilesSelected, numFilesQueued) {
|
||||
this.queueEvent("file_dialog_complete_handler", [numFilesSelected, numFilesQueued]);
|
||||
};
|
||||
|
||||
SWFUpload.prototype.uploadStart = function (file) {
|
||||
file = this.unescapeFilePostParams(file);
|
||||
this.queueEvent("return_upload_start_handler", file);
|
||||
};
|
||||
|
||||
SWFUpload.prototype.returnUploadStart = function (file) {
|
||||
var returnValue;
|
||||
if (typeof this.settings.upload_start_handler === "function") {
|
||||
file = this.unescapeFilePostParams(file);
|
||||
returnValue = this.settings.upload_start_handler.call(this, file);
|
||||
} else if (this.settings.upload_start_handler != undefined) {
|
||||
throw "upload_start_handler must be a function";
|
||||
}
|
||||
|
||||
// Convert undefined to true so if nothing is returned from the upload_start_handler it is
|
||||
// interpretted as 'true'.
|
||||
if (returnValue === undefined) {
|
||||
returnValue = true;
|
||||
}
|
||||
|
||||
returnValue = !!returnValue;
|
||||
|
||||
this.callFlash("ReturnUploadStart", [returnValue]);
|
||||
};
|
||||
|
||||
|
||||
|
||||
SWFUpload.prototype.uploadProgress = function (file, bytesComplete, bytesTotal) {
|
||||
file = this.unescapeFilePostParams(file);
|
||||
this.queueEvent("upload_progress_handler", [file, bytesComplete, bytesTotal]);
|
||||
};
|
||||
|
||||
SWFUpload.prototype.uploadError = function (file, errorCode, message) {
|
||||
file = this.unescapeFilePostParams(file);
|
||||
this.queueEvent("upload_error_handler", [file, errorCode, message]);
|
||||
};
|
||||
|
||||
SWFUpload.prototype.uploadSuccess = function (file, serverData) {
|
||||
file = this.unescapeFilePostParams(file);
|
||||
this.queueEvent("upload_success_handler", [file, serverData]);
|
||||
};
|
||||
|
||||
SWFUpload.prototype.uploadComplete = function (file) {
|
||||
file = this.unescapeFilePostParams(file);
|
||||
this.queueEvent("upload_complete_handler", file);
|
||||
};
|
||||
|
||||
/* Called by SWFUpload JavaScript and Flash functions when debug is enabled. By default it writes messages to the
|
||||
internal debug console. You can override this event and have messages written where you want. */
|
||||
SWFUpload.prototype.debug = function (message) {
|
||||
this.queueEvent("debug_handler", message);
|
||||
};
|
||||
|
||||
|
||||
/* **********************************
|
||||
Debug Console
|
||||
The debug console is a self contained, in page location
|
||||
for debug message to be sent. The Debug Console adds
|
||||
itself to the body if necessary.
|
||||
|
||||
The console is automatically scrolled as messages appear.
|
||||
|
||||
If you are using your own debug handler or when you deploy to production and
|
||||
have debug disabled you can remove these functions to reduce the file size
|
||||
and complexity.
|
||||
********************************** */
|
||||
|
||||
// Private: debugMessage is the default debug_handler. If you want to print debug messages
|
||||
// call the debug() function. When overriding the function your own function should
|
||||
// check to see if the debug setting is true before outputting debug information.
|
||||
SWFUpload.prototype.debugMessage = function (message) {
|
||||
if (this.settings.debug) {
|
||||
var exceptionMessage, exceptionValues = [];
|
||||
|
||||
// Check for an exception object and print it nicely
|
||||
if (typeof message === "object" && typeof message.name === "string" && typeof message.message === "string") {
|
||||
for (var key in message) {
|
||||
if (message.hasOwnProperty(key)) {
|
||||
exceptionValues.push(key + ": " + message[key]);
|
||||
}
|
||||
}
|
||||
exceptionMessage = exceptionValues.join("\n") || "";
|
||||
exceptionValues = exceptionMessage.split("\n");
|
||||
exceptionMessage = "EXCEPTION: " + exceptionValues.join("\nEXCEPTION: ");
|
||||
SWFUpload.Console.writeLine(exceptionMessage);
|
||||
} else {
|
||||
SWFUpload.Console.writeLine(message);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
SWFUpload.Console = {};
|
||||
SWFUpload.Console.writeLine = function (message) {
|
||||
var console, documentForm;
|
||||
|
||||
try {
|
||||
console = document.getElementById("SWFUpload_Console");
|
||||
|
||||
if (!console) {
|
||||
documentForm = document.createElement("form");
|
||||
document.getElementsByTagName("body")[0].appendChild(documentForm);
|
||||
|
||||
console = document.createElement("textarea");
|
||||
console.id = "SWFUpload_Console";
|
||||
console.style.fontFamily = "monospace";
|
||||
console.setAttribute("wrap", "off");
|
||||
console.wrap = "off";
|
||||
console.style.overflow = "auto";
|
||||
console.style.width = "700px";
|
||||
console.style.height = "350px";
|
||||
console.style.margin = "5px";
|
||||
documentForm.appendChild(console);
|
||||
}
|
||||
|
||||
console.value += message + "\n";
|
||||
|
||||
console.scrollTop = console.scrollHeight - console.clientHeight;
|
||||
} catch (ex) {
|
||||
alert("Exception: " + ex.name + " Message: " + ex.message);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user