[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/js/jquery/ -> jquery.form.min.js (source)

   1  !function(r){"function"==typeof define&&define.amd?define(["jquery"],r):"object"==typeof module&&module.exports?module.exports=function(e,t){return void 0===t&&(t="undefined"!=typeof window?require("jquery"):require("jquery")(e)),r(t),t}:r(jQuery)}(function(O){"use strict";var d=/\r?\n/g,v={};v.fileapi=void 0!==O('<input type="file">').get(0).files,v.formdata=void 0!==window.FormData;var X=!!O.fn.prop;function o(e){var t=e.data;e.isDefaultPrevented()||(e.preventDefault(),O(e.target).closest("form").ajaxSubmit(t))}function i(e){var t=e.target,r=O(t);if(!r.is("[type=submit],[type=image]")){var a=r.closest("[type=submit]");if(0===a.length)return;t=a[0]}var n=t.form;"image"===(n.clk=t).type&&(void 0!==e.offsetX?(n.clk_x=e.offsetX,n.clk_y=e.offsetY):"function"==typeof O.fn.offset?(r=r.offset(),n.clk_x=e.pageX-r.left,n.clk_y=e.pageY-r.top):(n.clk_x=e.pageX-t.offsetLeft,n.clk_y=e.pageY-t.offsetTop)),setTimeout(function(){n.clk=n.clk_x=n.clk_y=null},100)}function C(){var e;O.fn.ajaxSubmit.debug&&(e="[jquery.form] "+Array.prototype.join.call(arguments,""),window.console&&window.console.log?window.console.log(e):window.opera&&window.opera.postError&&window.opera.postError(e))}O.fn.attr2=function(){if(!X)return this.attr.apply(this,arguments);var e=this.prop.apply(this,arguments);return e&&e.jquery||"string"==typeof e?e:this.attr.apply(this,arguments)},O.fn.ajaxSubmit=function(F,e,t,r){if(!this.length)return C("ajaxSubmit: skipping submit process - no element selected"),this;var L,E=this;"function"==typeof F?F={success:F}:"string"==typeof F||!1===F&&0<arguments.length?(F={url:F,data:e,dataType:t},"function"==typeof r&&(F.success=r)):void 0===F&&(F={}),L=F.method||F.type||this.attr2("method"),r=(r=(r="string"==typeof(t=F.url||this.attr2("action"))?O.trim(t):"")||window.location.href||"")&&(r.match(/^([^#]+)/)||[])[1],F=O.extend(!0,{url:r,success:O.ajaxSettings.success,type:L||O.ajaxSettings.type,iframeSrc:/^https/i.test(window.location.href||"")?"javascript:false":"about:blank"},F);t={};if(this.trigger("form-pre-serialize",[this,F,t]),t.veto)return C("ajaxSubmit: submit vetoed via form-pre-serialize trigger"),this;if(F.beforeSerialize&&!1===F.beforeSerialize(this,F))return C("ajaxSubmit: submit aborted via beforeSerialize callback"),this;r=F.traditional;void 0===r&&(r=O.ajaxSettings.traditional);var M=[],a=this.formToArray(F.semantic,M,F.filtering);if(F.data&&(n=O.isFunction(F.data)?F.data(a):F.data,F.extraData=n,c=O.param(n,r)),F.beforeSubmit&&!1===F.beforeSubmit(a,this,F))return C("ajaxSubmit: submit aborted via beforeSubmit callback"),this;if(this.trigger("form-submit-validate",[a,this,F,t]),t.veto)return C("ajaxSubmit: submit vetoed via form-submit-validate trigger"),this;var n=O.param(a,r);c&&(n=n?n+"&"+c:c),"GET"===F.type.toUpperCase()?(F.url+=(0<=F.url.indexOf("?")?"&":"?")+n,F.data=null):F.data=n;var o,i,s,u=[];F.resetForm&&u.push(function(){E.resetForm()}),F.clearForm&&u.push(function(){E.clearForm(F.includeHidden)}),!F.dataType&&F.target?(o=F.success||function(){},u.push(function(e,t,r){var a=arguments,n=F.replaceTarget?"replaceWith":"html";O(F.target)[n](e).each(function(){o.apply(this,a)})})):F.success&&(O.isArray(F.success)?O.merge(u,F.success):u.push(F.success)),F.success=function(e,t,r){for(var a=F.context||this,n=0,o=u.length;n<o;n++)u[n].apply(a,[e,t,r||E,E])},F.error&&(i=F.error,F.error=function(e,t,r){var a=F.context||this;i.apply(a,[e,t,r,E])}),F.complete&&(s=F.complete,F.complete=function(e,t){var r=F.context||this;s.apply(r,[e,t,E])});var t=0<O("input[type=file]:enabled",this).filter(function(){return""!==O(this).val()}).length,r="multipart/form-data",c=E.attr("enctype")===r||E.attr("encoding")===r,n=v.fileapi&&v.formdata;C("fileAPI :"+n);var l,r=(t||c)&&!n;!1!==F.iframe&&(F.iframe||r)?F.closeKeepAlive?O.get(F.closeKeepAlive,function(){l=d(a)}):l=d(a):l=(t||c)&&n?function(e){for(var r=new FormData,t=0;t<e.length;t++)r.append(e[t].name,e[t].value);if(F.extraData){var a=function(e){var t,r,a=O.param(e,F.traditional).split("&"),n=a.length,o=[];for(t=0;t<n;t++)a[t]=a[t].replace(/\+/g," "),r=a[t].split("="),o.push([decodeURIComponent(r[0]),decodeURIComponent(r[1])]);return o}(F.extraData);for(t=0;t<a.length;t++)a[t]&&r.append(a[t][0],a[t][1])}F.data=null;var n=O.extend(!0,{},O.ajaxSettings,F,{contentType:!1,processData:!1,cache:!1,type:L||"POST"});F.uploadProgress&&(n.xhr=function(){var e=O.ajaxSettings.xhr();return e.upload&&e.upload.addEventListener("progress",function(e){var t=0,r=e.loaded||e.position,a=e.total;e.lengthComputable&&(t=Math.ceil(r/a*100)),F.uploadProgress(e,r,a,t)},!1),e});n.data=null;var o=n.beforeSend;return n.beforeSend=function(e,t){F.formData?t.data=F.formData:t.data=r,o&&o.call(this,e,t)},O.ajax(n)}(a):O.ajax(F),E.removeData("jqxhr").data("jqxhr",l);for(var f=0;f<M.length;f++)M[f]=null;return this.trigger("form-submit-notify",[this,F]),this;function d(e){var t,r,i,s,u,c,l,f,d,o=E[0],p=O.Deferred();if(p.abort=function(e){l.abort(e)},e)for(r=0;r<M.length;r++)t=O(M[r]),X?t.prop("disabled",!1):t.removeAttr("disabled");(i=O.extend(!0,{},O.ajaxSettings,F)).context=i.context||i;var m="jqFormIO"+(new Date).getTime(),h=o.ownerDocument,v=E.closest("body");if(i.iframeTarget?(a=(u=O(i.iframeTarget,h)).attr2("name"))?m=a:u.attr2("name",m):(u=O('<iframe name="'+m+'" src="'+i.iframeSrc+'" />',h)).css({position:"absolute",top:"-1000px",left:"-1000px"}),c=u[0],l={aborted:0,responseText:null,responseXML:null,status:0,statusText:"n/a",getAllResponseHeaders:function(){},getResponseHeader:function(){},setRequestHeader:function(){},abort:function(e){var t="timeout"===e?"timeout":"aborted";C("aborting upload... "+t),this.aborted=1;try{c.contentWindow.document.execCommand&&c.contentWindow.document.execCommand("Stop")}catch(e){}u.attr("src",i.iframeSrc),l.error=t,i.error&&i.error.call(i.context,l,t,e),s&&O.event.trigger("ajaxError",[l,i,t]),i.complete&&i.complete.call(i.context,l,t)}},(s=i.global)&&0==O.active++&&O.event.trigger("ajaxStart"),s&&O.event.trigger("ajaxSend",[l,i]),i.beforeSend&&!1===i.beforeSend.call(i.context,l,i))return i.global&&O.active--,p.reject(),p;if(l.aborted)return p.reject(),p;(e=o.clk)&&(a=e.name)&&!e.disabled&&(i.extraData=i.extraData||{},i.extraData[a]=e.value,"image"===e.type&&(i.extraData[a+".x"]=o.clk_x,i.extraData[a+".y"]=o.clk_y));var g=1,x=2;function y(t){var r=null;try{t.contentWindow&&(r=t.contentWindow.document)}catch(e){C("cannot get iframe.contentWindow document: "+e)}if(r)return r;try{r=t.contentDocument||t.document}catch(e){C("cannot get iframe.contentDocument: "+e),r=t.document}return r}var e=O("meta[name=csrf-token]").attr("content"),a=O("meta[name=csrf-param]").attr("content");function n(){var e=E.attr2("target"),t=E.attr2("action"),r=E.attr("enctype")||E.attr("encoding")||"multipart/form-data";o.setAttribute("target",m),L&&!/post/i.test(L)||o.setAttribute("method","POST"),t!==i.url&&o.setAttribute("action",i.url),i.skipEncodingOverride||L&&!/post/i.test(L)||E.attr({encoding:"multipart/form-data",enctype:"multipart/form-data"}),i.timeout&&(d=setTimeout(function(){f=!0,S(g)},i.timeout));var a=[];try{if(i.extraData)for(var n in i.extraData)i.extraData.hasOwnProperty(n)&&(O.isPlainObject(i.extraData[n])&&i.extraData[n].hasOwnProperty("name")&&i.extraData[n].hasOwnProperty("value")?a.push(O('<input type="hidden" name="'+i.extraData[n].name+'">',h).val(i.extraData[n].value).appendTo(o)[0]):a.push(O('<input type="hidden" name="'+n+'">',h).val(i.extraData[n]).appendTo(o)[0]));i.iframeTarget||u.appendTo(v),c.attachEvent?c.attachEvent("onload",S):c.addEventListener("load",S,!1),setTimeout(function e(){try{var t=y(c).readyState;C("state = "+t),t&&"uninitialized"===t.toLowerCase()&&setTimeout(e,50)}catch(e){C("Server abort: ",e," (",e.name,")"),S(x),d&&clearTimeout(d),d=void 0}},15);try{o.submit()}catch(e){document.createElement("form").submit.apply(o)}}finally{o.setAttribute("action",t),o.setAttribute("enctype",r),e?o.setAttribute("target",e):E.removeAttr("target"),O(a).remove()}}a&&e&&(i.extraData=i.extraData||{},i.extraData[a]=e),i.forceSync?n():setTimeout(n,10);var b,T,j,w=50;function S(e){if(!l.aborted&&!j){if((T=y(c))||(C("cannot access response document"),e=x),e===g&&l)return l.abort("timeout"),void p.reject(l,"timeout");if(e===x&&l)return l.abort("server abort"),void p.reject(l,"error","server abort");if(T&&T.location.href!==i.iframeSrc||f){c.detachEvent?c.detachEvent("onload",S):c.removeEventListener("load",S,!1);var t,r="success";try{if(f)throw"timeout";var a="xml"===i.dataType||T.XMLDocument||O.isXMLDoc(T);if(C("isXml="+a),!a&&window.opera&&(null===T.body||!T.body.innerHTML)&&--w)return C("requeing onLoad callback, DOM not available"),void setTimeout(S,250);var n=T.body||T.documentElement;l.responseText=n?n.innerHTML:null,l.responseXML=T.XMLDocument||T,a&&(i.dataType="xml"),l.getResponseHeader=function(e){return{"content-type":i.dataType}[e.toLowerCase()]},n&&(l.status=Number(n.getAttribute("status"))||l.status,l.statusText=n.getAttribute("statusText")||l.statusText);var o=(i.dataType||"").toLowerCase(),a=/(json|script|text)/.test(o);a||i.textarea?(n=T.getElementsByTagName("textarea")[0])?(l.responseText=n.value,l.status=Number(n.getAttribute("status"))||l.status,l.statusText=n.getAttribute("statusText")||l.statusText):a&&(n=T.getElementsByTagName("pre")[0],a=T.getElementsByTagName("body")[0],n?l.responseText=n.textContent||n.innerText:a&&(l.responseText=a.textContent||a.innerText)):"xml"===o&&!l.responseXML&&l.responseText&&(l.responseXML=k(l.responseText));try{b=A(l,o,i)}catch(e){r="parsererror",l.error=t=e||r}}catch(e){C("error caught: ",e),r="error",l.error=t=e||r}l.aborted&&(C("upload aborted"),r=null),"success"===(r=l.status?200<=l.status&&l.status<300||304===l.status?"success":"error":r)?(i.success&&i.success.call(i.context,b,"success",l),p.resolve(l.responseText,"success",l),s&&O.event.trigger("ajaxSuccess",[l,i])):r&&(void 0===t&&(t=l.statusText),i.error&&i.error.call(i.context,l,r,t),p.reject(l,"error",t),s&&O.event.trigger("ajaxError",[l,i,t])),s&&O.event.trigger("ajaxComplete",[l,i]),s&&!--O.active&&O.event.trigger("ajaxStop"),i.complete&&i.complete.call(i.context,l,r),j=!0,i.timeout&&clearTimeout(d),setTimeout(function(){i.iframeTarget?u.attr("src",i.iframeSrc):u.remove(),l.responseXML=null},100)}}}var k=O.parseXML||function(e,t){return window.ActiveXObject?((t=new ActiveXObject("Microsoft.XMLDOM")).async="false",t.loadXML(e)):t=(new DOMParser).parseFromString(e,"text/xml"),t&&t.documentElement&&"parsererror"!==t.documentElement.nodeName?t:null},D=O.parseJSON||function(e){return window.eval("("+e+")")},A=function(e,t,r){var a=e.getResponseHeader("content-type")||"",n=("xml"===t||!t)&&0<=a.indexOf("xml"),e=n?e.responseXML:e.responseText;return n&&"parsererror"===e.documentElement.nodeName&&O.error&&O.error("parsererror"),"string"==typeof(e=r&&r.dataFilter?r.dataFilter(e,t):e)&&(("json"===t||!t)&&0<=a.indexOf("json")?e=D(e):("script"===t||!t)&&0<=a.indexOf("javascript")&&O.globalEval(e)),e};return p}},O.fn.ajaxForm=function(e,t,r,a){if(("string"==typeof e||!1===e&&0<arguments.length)&&(e={url:e,data:t,dataType:r},"function"==typeof a&&(e.success=a)),(e=e||{}).delegation=e.delegation&&O.isFunction(O.fn.on),e.delegation||0!==this.length)return e.delegation?(O(document).off("submit.form-plugin",this.selector,o).off("click.form-plugin",this.selector,i).on("submit.form-plugin",this.selector,e,o).on("click.form-plugin",this.selector,e,i),this):this.ajaxFormUnbind().on("submit.form-plugin",e,o).on("click.form-plugin",e,i);var n={s:this.selector,c:this.context};return!O.isReady&&n.s?(C("DOM not ready, queuing ajaxForm"),O(function(){O(n.s,n.c).ajaxForm(e)})):C("terminating; zero elements found by selector"+(O.isReady?"":" (DOM not ready)")),this},O.fn.ajaxFormUnbind=function(){return this.off("submit.form-plugin click.form-plugin")},O.fn.formToArray=function(e,t,r){var a=[];if(0===this.length)return a;var n,o,i,s,u,c,l,f,d=this[0],p=this.attr("id"),m=(m=e||void 0===d.elements?d.getElementsByTagName("*"):d.elements)&&O.makeArray(m);if(!(m=p&&(e||/(Edge|Trident)\//.test(navigator.userAgent))&&(l=O(':input[form="'+p+'"]').get()).length?(m||[]).concat(l):m)||!m.length)return a;for(n=0,u=(m=O.isFunction(r)?O.map(m,r):m).length;n<u;n++)if((f=(s=m[n]).name)&&!s.disabled)if(e&&d.clk&&"image"===s.type)d.clk===s&&(a.push({name:f,value:O(s).val(),type:s.type}),a.push({name:f+".x",value:d.clk_x},{name:f+".y",value:d.clk_y}));else if((i=O.fieldValue(s,!0))&&i.constructor===Array)for(t&&t.push(s),o=0,c=i.length;o<c;o++)a.push({name:f,value:i[o]});else if(v.fileapi&&"file"===s.type){t&&t.push(s);var h=s.files;if(h.length)for(o=0;o<h.length;o++)a.push({name:f,value:h[o],type:s.type});else a.push({name:f,value:"",type:s.type})}else null!=i&&(t&&t.push(s),a.push({name:f,value:i,type:s.type,required:s.required}));return e||!d.clk||(f=(r=(l=O(d.clk))[0]).name)&&!r.disabled&&"image"===r.type&&(a.push({name:f,value:l.val()}),a.push({name:f+".x",value:d.clk_x},{name:f+".y",value:d.clk_y})),a},O.fn.formSerialize=function(e){return O.param(this.formToArray(e))},O.fn.fieldSerialize=function(n){var o=[];return this.each(function(){var e=this.name;if(e){var t=O.fieldValue(this,n);if(t&&t.constructor===Array)for(var r=0,a=t.length;r<a;r++)o.push({name:e,value:t[r]});else null!=t&&o.push({name:this.name,value:t})}}),O.param(o)},O.fn.fieldValue=function(e){for(var t=[],r=0,a=this.length;r<a;r++){var n=this[r],n=O.fieldValue(n,e);null==n||n.constructor===Array&&!n.length||(n.constructor===Array?O.merge(t,n):t.push(n))}return t},O.fieldValue=function(e,t){var r=e.name,a=e.type,n=e.tagName.toLowerCase();if((t=void 0===t?!0:t)&&(!r||e.disabled||"reset"===a||"button"===a||("checkbox"===a||"radio"===a)&&!e.checked||("submit"===a||"image"===a)&&e.form&&e.form.clk!==e||"select"===n&&-1===e.selectedIndex))return null;if("select"!==n)return O(e).val().replace(d,"\r\n");n=e.selectedIndex;if(n<0)return null;for(var o=[],i=e.options,s="select-one"===a,u=s?n+1:i.length,c=s?n:0;c<u;c++){var l=i[c];if(l.selected&&!l.disabled){var f=(f=l.value)||(l.attributes&&l.attributes.value&&!l.attributes.value.specified?l.text:l.value);if(s)return f;o.push(f)}}return o},O.fn.clearForm=function(e){return this.each(function(){O("input,select,textarea",this).clearFields(e)})},O.fn.clearFields=O.fn.clearInputs=function(r){var a=/^(?:color|date|datetime|email|month|number|password|range|search|tel|text|time|url|week)$/i;return this.each(function(){var e=this.type,t=this.tagName.toLowerCase();a.test(e)||"textarea"===t?this.value="":"checkbox"===e||"radio"===e?this.checked=!1:"select"===t?this.selectedIndex=-1:"file"===e?/MSIE/.test(navigator.userAgent)?O(this).replaceWith(O(this).clone(!0)):O(this).val(""):r&&(!0===r&&/hidden/.test(e)||"string"==typeof r&&O(this).is(r))&&(this.value="")})},O.fn.resetForm=function(){return this.each(function(){var t=O(this),e=this.tagName.toLowerCase();switch(e){case"input":this.checked=this.defaultChecked;case"textarea":return this.value=this.defaultValue,!0;case"option":case"optgroup":var r=t.parents("select");return r.length&&r[0].multiple?"option"===e?this.selected=this.defaultSelected:t.find("option").resetForm():r.resetForm(),!0;case"select":return t.find("option").each(function(e){if(this.selected=this.defaultSelected,this.defaultSelected&&!t[0].multiple)return t[0].selectedIndex=e,!1}),!0;case"label":var a=O(t.attr("for")),r=t.find("input,select,textarea");return a[0]&&r.unshift(a[0]),r.resetForm(),!0;case"form":return"function"!=typeof this.reset&&("object"!=typeof this.reset||this.reset.nodeType)||this.reset(),!0;default:return t.find("form,input,label,select,textarea").resetForm(),!0}})},O.fn.enable=function(e){return void 0===e&&(e=!0),this.each(function(){this.disabled=!e})},O.fn.selected=function(t){return void 0===t&&(t=!0),this.each(function(){var e=this.type;"checkbox"===e||"radio"===e?this.checked=t:"option"===this.tagName.toLowerCase()&&(e=O(this).parent("select"),t&&e[0]&&"select-one"===e[0].type&&e.find("option").selected(!1),this.selected=t)})},O.fn.ajaxSubmit.debug=!1});


Generated: Mon Mar 8 01:00:04 2021 Cross-referenced by PHPXref 0.7.1