UNPKG

dzxstatic

Version:

The static files of Discuz! X

1 lines 3.05 kB
jQuery.extend({createuploadiframe:function(e,t){var r="uploadiframe"+e,o='<iframe id="'+r+'" name="'+r+'"';return window.ActiveXObject&&("boolean"==typeof t?o+=' src="javascript:false"':"string"==typeof t&&(o+=' src="'+t+'"')),o+=" />",jQuery(o).css({position:"absolute",top:"-1200px",left:"-1200px"}).appendTo(document.body),jQuery("#"+r).get(0)},createuploadform:function(e,t,r){var o="uploadform"+e,n="uploadfile"+e,a=jQuery('<form method="post" name="'+o+'" id="'+o+'" enctype="multipart/form-data"></form>');if(r)for(var u in r)jQuery('<input type="hidden" name="'+u+'" value="'+r[u]+'" />').appendTo(a);var c=jQuery("#"+t),d=jQuery(c).clone();return jQuery(c).attr("id",n).before(d).appendTo(a),jQuery(a).css({position:"absolute",top:"-1200px",left:"-1200px"}).appendTo(document.body),a},ajaxfileupload:function(e){e=jQuery.extend({},jQuery.ajaxSettings,e);var t=(new Date).getTime(),r=jQuery.createuploadform(t,e.fileElementId,void 0!==e.data&&e.data),o=(jQuery.createuploadiframe(t,e.secureuri),"uploadiframe"+t),n="uploadform"+t;e.global&&!jQuery.active++&&jQuery.event.trigger("ajaxStart");var a={};e.global&&jQuery.event.trigger("ajaxSend",[a,e]);var u=function(t){var n=document.getElementById(o);try{n.contentWindow?(a.responseText=n.contentWindow.document.body?n.contentWindow.document.body.innerHTML:null,a.responseXML=n.contentWindow.document.XMLDocument?n.contentWindow.document.XMLDocument:n.contentWindow.document):n.contentDocument&&(a.responseText=n.contentDocument.document.body?n.contentDocument.document.body.innerHTML:null,a.responseXML=n.contentDocument.document.XMLDocument?n.contentDocument.document.XMLDocument:n.contentDocument.document)}catch(t){jQuery.handleerror(e,a,null,t)}if(a||"timeout"==t){var u;requestdone=!0;try{if("error"!=(u="timeout"!=t?"success":"error")){var c=jQuery.uploadhttpdata(a,e.dataType);e.success&&e.success(c,u),e.global&&jQuery.event.trigger("ajaxSuccess",[a,e])}else jQuery.handleerror(e,a,u)}catch(t){u="error",jQuery.handleerror(e,a,u,t)}e.global&&jQuery.event.trigger("ajaxComplete",[a,e]),e.global&&!--jQuery.active&&jQuery.event.trigger("ajaxStop"),e.complete&&e.complete(a,u),jQuery(n).off(),setTimeout((function(){try{jQuery(n).remove(),jQuery(r).remove()}catch(t){jQuery.handleerror(e,a,null,t)}}),100),a=null}};e.timeout>0&&setTimeout((function(){requestdone||u("timeout")}),e.timeout);try{r=jQuery("#"+n);jQuery(r).attr("action",e.url).attr("method","post").attr("target",o),r.encoding?jQuery(r).attr("encoding","multipart/form-data"):jQuery(r).attr("enctype","multipart/form-data"),jQuery(r).submit()}catch(t){jQuery.handleerror(e,a,null,t)}return jQuery("#"+o).load(u),{abort:function(){}}},uploadhttpdata:function(r,type){var data=!type;return data="xml"==type||data?r.responseXML:r.responseText,"script"==type&&jQuery.globalEval(data),"json"==type&&eval("data = "+data),"html"==type&&jQuery("<div>").html(data),data},handleerror:function(e,t,r,o){e.error&&e.error.call(e.context||e,t,r,o),e.global&&(e.context?jQuery(e.context):jQuery.event).trigger("ajaxError",[t,e,o])}});