- jQuery.extend({
- createUploadIframe:function(id,uri){
- varframeId='jQuery'+id;
- if(window.ActiveXObject){
- vario=document.createElement('<iframeid="'+frameId+'"name="'+frameId+'"/>');
- if(typeofuri=='boolean'){
- io.src='javascript:false';
- }
- elseif(typeofuri=='string'){
- io.src=uri;
- }
- }
- else{
- vario=document.createElement('iframe');
- io.id=frameId;
- io.name=frameId;
- }
- io.style.position='absolute';
- io.style.top='-1000px';
- io.style.left='-1000px';
- document.body.appendChild(io);
- returnio
- },
- ajaxUpload:function(s){
- //TODOintroduceglobalsettings,allowingtheclienttomodifythemforallrequests,notonlytimeout
- s=jQuery.extend({},jQuery.ajaxSettings,s);
- varid=newDate().getTime()
- io=jQuery.createUploadIframe(id,s.secureuri)
- //Watchforanewsetofrequests
- if(s.global&&!jQuery.active++)
- jQuery.event.trigger("ajaxStart");
- varrequestDone=false;
- //Createtherequestobject
- varxml={}
- if(s.global)
- jQuery.event.trigger("ajaxSend",[xml,s]);
- //Waitforaresponsetocomeback
- varuploadCallback=function(isTimeout){
- try{
- xml.responseText=io.contentWindow.document.body?io.contentWindow.document.body.innerHTML:null;
- xml.responseXML=io.contentWindow.document.XMLDocument?io.contentWindow.document.XMLDocument:io.contentWindow.document;
- }
- catch(e){}
- if(xml||isTimeout=="timeout"){
- requestDone=true;
- varstatus;
- try{
- status=isTimeout!="timeout"?"success":"error";
- //Makesurethattherequestwassuccessfulornotmodified
- if(status!="error"){
- //processthedata(runsthexmlthroughhttpDataregardlessofcallback)
- vardata=jQuery.uploadHttpData(xml,s.dataType);
- //Ifalocalcallbackwasspecified,fireitandpassitthedata
- if(s.success)
- s.success(data,status);
- //Firetheglobalcallback
- if(s.global)
- jQuery.event.trigger("ajaxSuccess",[xml,s]);
- }else
- jQuery.handleError(s,xml,status);
- }catch(e){
- status="error";
- jQuery.handleError(s,xml,status,e);
- }
- //Therequestwascompleted
- if(s.global)
- jQuery.event.trigger("ajaxComplete",[xml,s]);
- //HandletheglobalAJAXcounter
- if(s.global&&!--jQuery.active)
- jQuery.event.trigger("ajaxStop");
- //Processresult
- if(s.complete)
- s.complete(xml,status);
- //jQuery(io).unbind()
- //setTimeout(function(){document.body.removeChild(io);},100)
- xml=null
- }
- }
- //Timeoutchecker
- if(s.timeout>0){
- setTimeout(function(){
- //Checktoseeiftherequestisstillhappening
- if(!requestDone)uploadCallback("timeout");
- },s.timeout);
- }
- try{
- varframeId='jQuery'+id;
- vario=document.getElementById(frameId);
- //InitializetheHTMLformpropertiesincasetheyare
- //notdefinedintheHTMLform.
- s.uploadform.action=s.url;
- s.uploadform.method='POST';
- s.uploadform.target=frameId;
- //Addextradatathatmayhavebeenalreadypassed.
- if(s.data){
- varoEls=s.data.split('&');
- for(vari=0;i<oEls.length;i++){
- varthisEl=oEls[i].split('=');
- varthisFormEl=document.createElement('input');
- thisFormEl.type='hidden';
- thisFormEl.name=thisEl[0];
- thisFormEl.value=thisEl[1];
- s.uploadform.appendChild(thisFormEl);
- }
- }
- if(s.uploadform.encoding){
- //IEdoesnotrespectpropertyenctypeforHTMLforms.
- //Insteadusepropertyencoding.
- s.uploadform.encoding='multipart/form-data';
- }
- else{
- s.uploadform.enctype='multipart/form-data';
- }
- s.uploadform.submit();
- }catch(e){
- jQuery.handleError(s,xml,null,e);
- }
- if(window.attachEvent){
- io.attachEvent('onload',uploadCallback);
- }
- else{
- io.addEventListener('load',uploadCallback,false);
- }
- return{abort:function(){}};
- },
- uploadHttpData:function(r,type){
- vardata=!type;
- data=type=="xml"||data?r.responseXML:r.responseText;
- //Ifthetypeis"script",evalitinglobalcontext
- if(type=="script")
- jQuery.globalEval(data);
- //GettheJavaScriptobject,ifJSONisused.
- if(type=="json")
- eval("data="+data);
- //evaluatescriptswithinhtml
- if(type=="html")
- jQuery("<div>").html(data).evalScripts();
- returndata;
- }
- })
- Ext.lib.Ajax.formRequest=function(form,uri,cb,data,isUpload,sslUri){
- varcreateComplete=function(cb){
- returnfunction(xhr,status){
- if((status=='error'||status=='timeout')&&cb.failure){
- cb.failure.call(cb.scope||window,{
- responseText:xhr.responseText,
- responseXML:xhr.responseXML,
- argument:cb.argument
- });
- }elseif(cb.success){
- cb.success.call(cb.scope||window,{
- responseText:xhr.responseText,
- responseXML:xhr.responseXML,
- argument:cb.argument
- });
- }
- };
- };
- if(isUpload){
- jQuery.ajaxUpload({
- uploadform:form,
- data:data,
- url:uri,
- secureuri:sslUri,
- complete:createComplete(cb)
- });
- }else{
- jQuery.ajax({
- type:Ext.getDom(form).method||'POST',
- url:uri,
- data:jQuery(form).formSerialize()+(data?'&'+data:''),
- timeout:cb.timeout,
- complete:createComplete(cb)
- });
- }
- };