1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-26 17:47:37 +00:00
transmission/web/javascript/jquery/jquery.form.min.js

1 line
10 KiB
JavaScript
Raw Normal View History

(function(a){function b(){if(a.fn.ajaxSubmit.debug){var b="[jquery.form] "+Array.prototype.join.call(arguments,"");window.console&&window.console.log?window.console.log(b):window.opera&&window.opera.postError&&window.opera.postError(b)}}a.fn.ajaxSubmit=function(c){function r(){function q(){var b=l.attr("target"),c=l.attr("action");d.setAttribute("target",f),d.getAttribute("method")!="POST"&&d.setAttribute("method","POST"),d.getAttribute("action")!=e.url&&d.setAttribute("action",e.url),e.skipEncodingOverride||l.attr({encoding:"multipart/form-data",enctype:"multipart/form-data"}),e.timeout&&(n=setTimeout(function(){m=!0,v(!0)},e.timeout));var g=[];try{if(e.extraData)for(var j in e.extraData)g.push(a('<input type="hidden" name="'+j+'" value="'+e.extraData[j]+'" />').appendTo(d)[0]);h.appendTo("body"),i.attachEvent?i.attachEvent("onload",v):i.addEventListener("load",v,!1),d.submit()}finally{d.setAttribute("action",c),b?d.setAttribute("target",b):l.removeAttr("target"),a(g).remove()}}function v(c){if(j.aborted||u)return;if(c===!0&&j){j.abort("timeout");return}var d=i.contentWindow?i.contentWindow.document:i.contentDocument?i.contentDocument:i.document;if(!d||d.location.href==e.iframeSrc)if(!m)return;i.detachEvent?i.detachEvent("onload",v):i.removeEventListener("load",v,!1);var f=!0;try{if(m)throw"timeout";var g=e.dataType=="xml"||d.XMLDocument||a.isXMLDoc(d);b("isXml="+g);if(!g&&window.opera&&(d.body==null||d.body.innerHTML=="")&&--t){b("requeing onLoad callback, DOM not available"),setTimeout(v,250);return}j.responseText=d.body?d.body.innerHTML:d.documentElement?d.documentElement.innerHTML:null,j.responseXML=d.XMLDocument?d.XMLDocument:d,g&&(e.dataType="xml"),j.getResponseHeader=function(a){var b={"content-type":e.dataType};return b[a]};var l=/(json|script|text)/.test(e.dataType);if(l||e.textarea){var o=d.getElementsByTagName("textarea")[0];if(o)j.responseText=o.value;else if(l){var p=d.getElementsByTagName("pre")[0],q=d.getElementsByTagName("body")[0];p?j.responseText=p.textContent?p.textContent:p.innerHTML:q&&(j.responseText=q.innerHTML)}}else e.dataType=="xml"&&!j.responseXML&&j.responseText!=null&&(j.responseXML=w(j.responseText));r=y(j,e.dataType,e)}catch(c){b("error caught:",c),f=!1,j.error=c,e.error&&e.error.call(e.context,j,"error",c),k&&a.event.trigger("ajaxError",[j,e,c])}j.aborted&&(b("upload aborted"),f=!1),f&&(e.success&&e.success.call(e.context,r,"success",j),k&&a.event.trigger("ajaxSuccess",[j,e])),k&&a.event.trigger("ajaxComplete",[j,e]),k&&!--a.active&&a.event.trigger("ajaxStop"),e.complete&&e.complete.call(e.context,j,f?"success":"error"),u=!0,e.timeout&&clearTimeout(n),setTimeout(function(){h.removeData("form-plugin-onload"),h.remove(),j.responseXML=null},100)}var d=l[0];if(a(":input[name=submit],:input[id=submit]",d).length){alert('Error: Form elements must not have name or id of "submit".');return}var e=a.extend(!0,{},a.ajaxSettings,c);e.context=e.context||e;var f="jqFormIO"+(new Date).getTime(),g="_"+f,h=a('<iframe id="'+f+'" name="'+f+'" src="'+e.iframeSrc+'" />'),i=h[0];h.css({position:"absolute",top:"-1000px",left:"-1000px"});var j={aborted:0,responseText:null,responseXML:null,status:0,statusText:"n/a",getAllResponseHeaders:function(){},getResponseHeader:function(){},setRequestHeader:function(){},abort:function(c){var d=c==="timeout"?"timeout":"aborted";b("aborting upload... "+d),this.aborted=1,h.attr("src",e.iframeSrc),j.error=d,e.error&&e.error.call(e.context,j,d,d),k&&a.event.trigger("ajaxError",[j,e,d]),e.complete&&e.complete.call(e.context,j,d)}},k=e.global;k&&!(a.active++)&&a.event.trigger("ajaxStart"),k&&a.event.trigger("ajaxSend",[j,e]);if(e.beforeSend&&e.beforeSend.call(e.context,j,e)===!1){e.global&&a.active--;return}if(j.aborted)return;var m=0,n,o=d.clk;if(o){var p=o.name;p&&!o.disabled&&(e.extraData=e.extraData||{},e.extraData[p]=o.value,o.type=="image"&&(e.extraData[p+".x"]=d.clk_x,e.extraData[p+".y"]=d.clk_y))}e.forceSync?q():setTimeout(q,10);var r,s,t=50,u,w=a.parseXML||function(a,b){return window.ActiveXObject?(b=new ActiveXObject("Microsoft.XMLDOM"),b.async="false",b.loadXML(a)):b=(