All Downloads are FREE. Search and download functionalities are using the official Maven repository.

template.js.plugins.jquery.form.min.js Maven / Gradle / Ivy

There is a newer version: 5.0.4
Show newest version
/*!
 * jQuery Form Plugin
 * version: 2.82 (15-JUN-2011)
 * @requires jQuery v1.3.2 or later
 *
 * Examples and documentation at: http://malsup.com/jquery/form/
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */
(function(b){b.fn.ajaxSubmit=function(d){if(!this.length){a("ajaxSubmit: skipping submit process - no element selected");return this}var c,p,f,g=this;if(typeof d=="function"){d={success:d}}c=this.attr("method");p=this.attr("action");f=(typeof p==="string")?b.trim(p):"";f=f||window.location.href||"";if(f){f=(f.match(/^([^#]+)/)||[])[1]}d=b.extend(true,{url:f,success:b.ajaxSettings.success,type:c||"GET",iframeSrc:/^https/i.test(window.location.href||"")?"javascript:false":"about:blank"},d);var j={};this.trigger("form-pre-serialize",[this,d,j]);if(j.veto){a("ajaxSubmit: submit vetoed via form-pre-serialize trigger");return this}if(d.beforeSerialize&&d.beforeSerialize(this,d)===false){a("ajaxSubmit: submit aborted via beforeSerialize callback");return this}var o,i,w=this.formToArray(d.semantic);if(d.data){d.extraData=d.data;for(o in d.data){if(d.data[o] instanceof Array){for(var r in d.data[o]){w.push({name:o,value:d.data[o][r]})}}else{i=d.data[o];i=b.isFunction(i)?i():i;w.push({name:o,value:i})}}}if(d.beforeSubmit&&d.beforeSubmit(w,this,d)===false){a("ajaxSubmit: submit aborted via beforeSubmit callback");return this}this.trigger("form-submit-validate",[w,this,d,j]);if(j.veto){a("ajaxSubmit: submit vetoed via form-submit-validate trigger");return this}var m=b.param(w);if(d.type.toUpperCase()=="GET"){d.url+=(d.url.indexOf("?")>=0?"&":"?")+m;d.data=null}else{d.data=m}var x=[];if(d.resetForm){x.push(function(){g.resetForm()})}if(d.clearForm){x.push(function(){g.clearForm()})}if(!d.dataType&&d.target){var e=d.success||function(){};x.push(function(n){var k=d.replaceTarget?"replaceWith":"html";b(d.target)[k](n).each(e,arguments)})}else{if(d.success){x.push(d.success)}}d.success=function(y,n,z){var v=d.context||d;for(var q=0,k=x.length;q0;var s="multipart/form-data";var l=(g.attr("enctype")==s||g.attr("encoding")==s);if(d.iframe!==false&&(t||d.iframe||l)){if(d.closeKeepAlive){b.get(d.closeKeepAlive,function(){h(w)})}else{h(w)}}else{if(b.browser.msie&&c=="get"){var u=g[0].getAttribute("method");if(typeof u==="string"){d.type=u}}b.ajax(d)}this.trigger("form-submit-notify",[this,d]);return this;function h(R){var v=g[0],N,H,P,K,z,C,A,B,L,O,F;if(R){for(N=0;N');z.css({position:"absolute",top:"-1000px",left:"-1000px"})}C=z[0];A={aborted:0,responseText:null,responseXML:null,status:0,statusText:"n/a",getAllResponseHeaders:function(){},getResponseHeader:function(){},setRequestHeader:function(){},abort:function(n){var U=(n==="timeout"?"timeout":"aborted");a("aborting upload... "+U);this.aborted=1;z.attr("src",H.iframeSrc);A.error=U;H.error&&H.error.call(H.context,A,U,n);P&&b.event.trigger("ajaxError",[A,H,U]);H.complete&&H.complete.call(H.context,A,U)}};P=H.global;if(P&&!b.active++){b.event.trigger("ajaxStart")}if(P){b.event.trigger("ajaxSend",[A,H])}if(H.beforeSend&&H.beforeSend.call(H.context,A,H)===false){if(H.global){b.active--}return}if(A.aborted){return}B=v.clk;if(B){L=B.name;if(L&&!B.disabled){H.extraData=H.extraData||{};H.extraData[L]=B.value;if(B.type=="image"){H.extraData[L+".x"]=v.clk_x;H.extraData[L+".y"]=v.clk_y}}}var G=1;var D=2;function E(U){var n=U.contentWindow?U.contentWindow.document:U.contentDocument?U.contentDocument:U.document;return n}function M(){var W=g.attr("target"),U=g.attr("action");v.setAttribute("target",K);if(!c){v.setAttribute("method","POST")}if(U!=H.url){v.setAttribute("action",H.url)}if(!H.skipEncodingOverride&&(!c||/post/i.test(c))){g.attr({encoding:"multipart/form-data",enctype:"multipart/form-data"})}if(H.timeout){F=setTimeout(function(){O=true;J(G)},H.timeout)}function X(){try{var n=E(C).readyState;a("state = "+n);if(n.toLowerCase()=="uninitialized"){setTimeout(X,50)}}catch(Z){a("Server abort: ",Z," (",Z.name,")");J(D);F&&clearTimeout(F);F=undefined}}var V=[];try{if(H.extraData){for(var Y in H.extraData){V.push(b('').attr("value",H.extraData[Y]).appendTo(v)[0])}}if(!H.iframeTarget){z.appendTo("body");C.attachEvent?C.attachEvent("onload",J):C.addEventListener("load",J,false)}setTimeout(X,15);v.submit()}finally{v.setAttribute("action",U);if(W){v.setAttribute("target",W)}else{g.removeAttr("target")}b(V).remove()}}if(H.forceSync){M()}else{setTimeout(M,10)}var S,T,Q=50,y;function J(Y){if(A.aborted||y){return}try{T=E(C)}catch(ab){a("cannot access response document: ",ab);Y=D}if(Y===G&&A){A.abort("timeout");return}else{if(Y==D&&A){A.abort("server abort");return}}if(!T||T.location.href==H.iframeSrc){if(!O){return}}C.detachEvent?C.detachEvent("onload",J):C.removeEventListener("load",J,false);var W="success",aa;try{if(O){throw"timeout"}var V=H.dataType=="xml"||T.XMLDocument||b.isXMLDoc(T);a("isXml="+V);if(!V&&window.opera&&(T.body==null||T.body.innerHTML=="")){if(--Q){a("requeing onLoad callback, DOM not available");setTimeout(J,250);return}}var ac=T.body?T.body:T.documentElement;A.responseText=ac?ac.innerHTML:null;A.responseXML=T.XMLDocument?T.XMLDocument:T;if(V){H.dataType="xml"}A.getResponseHeader=function(af){var ae={"content-type":H.dataType};return ae[af]};if(ac){A.status=Number(ac.getAttribute("status"))||A.status;A.statusText=ac.getAttribute("statusText")||A.statusText}var n=H.dataType||"";var Z=/(json|script|text)/.test(n.toLowerCase());if(Z||H.textarea){var X=T.getElementsByTagName("textarea")[0];if(X){A.responseText=X.value;A.status=Number(X.getAttribute("status"))||A.status;A.statusText=X.getAttribute("statusText")||A.statusText}else{if(Z){var U=T.getElementsByTagName("pre")[0];var ad=T.getElementsByTagName("body")[0];if(U){A.responseText=U.textContent?U.textContent:U.innerHTML}else{if(ad){A.responseText=ad.innerHTML}}}}}else{if(H.dataType=="xml"&&!A.responseXML&&A.responseText!=null){A.responseXML=I(A.responseText)}}try{S=k(A,H.dataType,H)}catch(Y){W="parsererror";A.error=aa=(Y||W)}}catch(Y){a("error caught: ",Y);W="error";A.error=aa=(Y||W)}if(A.aborted){a("upload aborted");W=null}if(A.status){W=(A.status>=200&&A.status<300||A.status===304)?"success":"error"}if(W==="success"){H.success&&H.success.call(H.context,S,"success",A);P&&b.event.trigger("ajaxSuccess",[A,H])}else{if(W){if(aa==undefined){aa=A.statusText}H.error&&H.error.call(H.context,A,W,aa);P&&b.event.trigger("ajaxError",[A,H,aa])}}P&&b.event.trigger("ajaxComplete",[A,H]);if(P&&!--b.active){b.event.trigger("ajaxStop")}H.complete&&H.complete.call(H.context,A,W);y=true;if(H.timeout){clearTimeout(F)}setTimeout(function(){if(!H.iframeTarget){z.remove()}A.responseXML=null},100)}var I=b.parseXML||function(n,U){if(window.ActiveXObject){U=new ActiveXObject("Microsoft.XMLDOM");U.async="false";U.loadXML(n)}else{U=(new DOMParser()).parseFromString(n,"text/xml")}return(U&&U.documentElement&&U.documentElement.nodeName!="parsererror")?U:null};var q=b.parseJSON||function(n){return window["eval"]("("+n+")")};var k=function(Y,W,V){var U=Y.getResponseHeader("content-type")||"",n=W==="xml"||!W&&U.indexOf("xml")>=0,X=n?Y.responseXML:Y.responseText;if(n&&X.documentElement.nodeName==="parsererror"){b.error&&b.error("parsererror")}if(V&&V.dataFilter){X=V.dataFilter(X,W)}if(typeof X==="string"){if(W==="json"||!W&&U.indexOf("json")>=0){X=q(X)}else{if(W==="script"||!W&&U.indexOf("javascript")>=0){b.globalEval(X)}}}return X}}};b.fn.ajaxForm=function(c){if(this.length===0){var d={s:this.selector,c:this.context};if(!b.isReady&&d.s){a("DOM not ready, queuing ajaxForm");b(function(){b(d.s,d.c).ajaxForm(c)});return this}a("terminating; zero elements found by selector"+(b.isReady?"":" (DOM not ready)"));return this}return this.ajaxFormUnbind().bind("submit.form-plugin",function(f){if(!f.isDefaultPrevented()){f.preventDefault();b(this).ajaxSubmit(c)}}).bind("click.form-plugin",function(j){var i=j.target;var g=b(i);if(!(g.is(":submit,input:image"))){var f=g.closest(":submit");if(f.length==0){return}i=f[0]}var h=this;h.clk=i;if(i.type=="image"){if(j.offsetX!=undefined){h.clk_x=j.offsetX;h.clk_y=j.offsetY}else{if(typeof b.fn.offset=="function"){var k=g.offset();h.clk_x=j.pageX-k.left;h.clk_y=j.pageY-k.top}else{h.clk_x=j.pageX-i.offsetLeft;h.clk_y=j.pageY-i.offsetTop}}}setTimeout(function(){h.clk=h.clk_x=h.clk_y=null},100)})};b.fn.ajaxFormUnbind=function(){return this.unbind("submit.form-plugin click.form-plugin")};b.fn.formToArray=function(q){var p=[];if(this.length===0){return p}var d=this[0];var g=q?d.getElementsByTagName("*"):d.elements;if(!g){return p}var k,h,f,r,e,m,c;for(k=0,m=g.length;k




© 2015 - 2024 Weber Informatics LLC | Privacy Policy