[ 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,h={},X=(h.fileapi=void 0!==O('<input type="file">').get(0).files,h.formdata=void 0!==window.FormData,!!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?(a=r.offset(),n.clk_x=e.pageX-a.left,n.clk_y=e.pageY-a.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 E,L=this,e=("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={}),E=F.method||F.type||this.attr2("method"),t=(t=(t="string"==typeof(e=F.url||this.attr2("action"))?O.trim(e):"")||window.location.href||"")&&(t.match(/^([^#]+)/)||[])[1],r=/(MSIE|Trident)/.test(navigator.userAgent||"")&&/^https/i.test(window.location.href||"")?"javascript:false":"about:blank",F=O.extend(!0,{url:t,success:O.ajaxSettings.success,type:E||O.ajaxSettings.type,iframeSrc:r},F),{});if(this.trigger("form-pre-serialize",[this,F,e]),e.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;var t=F.traditional,M=(void 0===t&&(t=O.ajaxSettings.traditional),[]),a=this.formToArray(F.semantic,M,F.filtering);if(F.data&&(r=O.isFunction(F.data)?F.data(a):F.data,F.extraData=r,c=O.param(r,t)),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,e]),e.veto)return C("ajaxSubmit: submit vetoed via form-submit-validate trigger"),this;var o,n,i,r=O.param(a,t),s=(c&&(r=r?r+"&"+c:c),"GET"===F.type.toUpperCase()?(F.url+=(0<=F.url.indexOf("?")?"&":"?")+r,F.data=null):F.data=r,[]);F.resetForm&&s.push(function(){L.resetForm()}),F.clearForm&&s.push(function(){L.clearForm(F.includeHidden)}),!F.dataType&&F.target?(o=F.success||function(){},s.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(s,F.success):s.push(F.success)),F.success=function(e,t,r){for(var a=F.context||this,n=0,o=s.length;n<o;n++)s[n].apply(a,[e,t,r||L,L])},F.error&&(n=F.error,F.error=function(e,t,r){var a=F.context||this;n.apply(a,[e,t,r,L])}),F.complete&&(i=F.complete,F.complete=function(e,t){var r=F.context||this;i.apply(r,[e,t,L])});var u,e=0<O("input[type=file]:enabled",this).filter(function(){return""!==O(this).val()}).length,t="multipart/form-data",c=L.attr("enctype")===t||L.attr("encoding")===t,r=h.fileapi&&h.formdata;C("fileAPI :"+r),!1!==F.iframe&&(F.iframe||(e||c)&&!r)?F.closeKeepAlive?O.get(F.closeKeepAlive,function(){u=f(a)}):u=f(a):u=(e||c)&&r?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:E||"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),L.removeData("jqxhr").data("jqxhr",u);for(var l=0;l<M.length;l++)M[l]=null;return this.trigger("form-submit-notify",[this,F]),this;function f(e){var t,r,c,l,f,d,p,m,h,o=L[0],g=O.Deferred();if(g.abort=function(e){p.abort(e)},e)for(r=0;r<M.length;r++)t=O(M[r]),X?t.prop("disabled",!1):t.removeAttr("disabled");(c=O.extend(!0,{},O.ajaxSettings,F)).context=c.context||c;var i="jqFormIO"+(new Date).getTime(),s=o.ownerDocument,u=L.closest("body");if(c.iframeTarget?(a=(f=O(c.iframeTarget,s)).attr2("name"))?i=a:f.attr2("name",i):(f=O('<iframe name="'+i+'" src="'+c.iframeSrc+'" />',s)).css({position:"absolute",top:"-1000px",left:"-1000px"}),d=f[0],p={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{d.contentWindow.document.execCommand&&d.contentWindow.document.execCommand("Stop")}catch(e){}f.attr("src",c.iframeSrc),p.error=t,c.error&&c.error.call(c.context,p,t,e),l&&O.event.trigger("ajaxError",[p,c,t]),c.complete&&c.complete.call(c.context,p,t)}},(l=c.global)&&0==O.active++&&O.event.trigger("ajaxStart"),l&&O.event.trigger("ajaxSend",[p,c]),c.beforeSend&&!1===c.beforeSend.call(c.context,p,c))return c.global&&O.active--,g.reject(),g;if(p.aborted)return g.reject(),g;(e=o.clk)&&(a=e.name)&&!e.disabled&&(c.extraData=c.extraData||{},c.extraData[a]=e.value,"image"===e.type&&(c.extraData[a+".x"]=o.clk_x,c.extraData[a+".y"]=o.clk_y));var v=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=L.attr2("target"),t=L.attr2("action"),r=L.attr("enctype")||L.attr("encoding")||"multipart/form-data";o.setAttribute("target",i),E&&!/post/i.test(E)||o.setAttribute("method","POST"),t!==c.url&&o.setAttribute("action",c.url),c.skipEncodingOverride||E&&!/post/i.test(E)||L.attr({encoding:"multipart/form-data",enctype:"multipart/form-data"}),c.timeout&&(h=setTimeout(function(){m=!0,S(v)},c.timeout));var a=[];try{if(c.extraData)for(var n in c.extraData)c.extraData.hasOwnProperty(n)&&(O.isPlainObject(c.extraData[n])&&c.extraData[n].hasOwnProperty("name")&&c.extraData[n].hasOwnProperty("value")?a.push(O('<input type="hidden" name="'+c.extraData[n].name+'">',s).val(c.extraData[n].value).appendTo(o)[0]):a.push(O('<input type="hidden" name="'+n+'">',s).val(c.extraData[n]).appendTo(o)[0]));c.iframeTarget||f.appendTo(u),d.attachEvent?d.attachEvent("onload",S):d.addEventListener("load",S,!1),setTimeout(function e(){try{var t=y(d).readyState;C("state = "+t),t&&"uninitialized"===t.toLowerCase()&&setTimeout(e,50)}catch(e){C("Server abort: ",e," (",e.name,")"),S(x),h&&clearTimeout(h),h=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):L.removeAttr("target"),O(a).remove()}}a&&e&&(c.extraData=c.extraData||{},c.extraData[a]=e),c.forceSync?n():setTimeout(n,10);var b,T,j,w=50;function S(t){if(!p.aborted&&!j){if((T=y(d))||(C("cannot access response document"),t=x),t===v&&p)return p.abort("timeout"),void g.reject(p,"timeout");if(t===x&&p)return p.abort("server abort"),void g.reject(p,"error","server abort");if(T&&T.location.href!==c.iframeSrc||m){d.detachEvent?d.detachEvent("onload",S):d.removeEventListener("load",S,!1);var r,t="success";try{if(m)throw"timeout";var e="xml"===c.dataType||T.XMLDocument||O.isXMLDoc(T);if(C("isXml="+e),!e&&window.opera&&(null===T.body||!T.body.innerHTML)&&--w)return C("requeing onLoad callback, DOM not available"),void setTimeout(S,250);var a,n,o,i=T.body||T.documentElement,s=(p.responseText=i?i.innerHTML:null,p.responseXML=T.XMLDocument||T,e&&(c.dataType="xml"),p.getResponseHeader=function(e){return{"content-type":c.dataType}[e.toLowerCase()]},i&&(p.status=Number(i.getAttribute("status"))||p.status,p.statusText=i.getAttribute("statusText")||p.statusText),(c.dataType||"").toLowerCase()),u=/(json|script|text)/.test(s);u||c.textarea?(a=T.getElementsByTagName("textarea")[0])?(p.responseText=a.value,p.status=Number(a.getAttribute("status"))||p.status,p.statusText=a.getAttribute("statusText")||p.statusText):u&&(n=T.getElementsByTagName("pre")[0],o=T.getElementsByTagName("body")[0],n?p.responseText=n.textContent||n.innerText:o&&(p.responseText=o.textContent||o.innerText)):"xml"===s&&!p.responseXML&&p.responseText&&(p.responseXML=k(p.responseText));try{b=A(p,s,c)}catch(e){t="parsererror",p.error=r=e||t}}catch(e){C("error caught: ",e),t="error",p.error=r=e||t}p.aborted&&(C("upload aborted"),t=null),"success"===(t=p.status?200<=p.status&&p.status<300||304===p.status?"success":"error":t)?(c.success&&c.success.call(c.context,b,"success",p),g.resolve(p.responseText,"success",p),l&&O.event.trigger("ajaxSuccess",[p,c])):t&&(void 0===r&&(r=p.statusText),c.error&&c.error.call(c.context,p,t,r),g.reject(p,"error",r),l&&O.event.trigger("ajaxError",[p,c,r])),l&&O.event.trigger("ajaxComplete",[p,c]),l&&!--O.active&&O.event.trigger("ajaxStop"),c.complete&&c.complete.call(c.context,p,t),j=!0,c.timeout&&clearTimeout(h),setTimeout(function(){c.iframeTarget?f.attr("src",c.iframeSrc):f.remove(),p.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 g}},O.fn.ajaxForm=function(e,t,r,a){var n;return("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?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):(e.beforeFormUnbind&&e.beforeFormUnbind(this,e),this.ajaxFormUnbind().on("submit.form-plugin",e,o).on("click.form-plugin",e,i)):(n={s:this.selector,c:this.context},!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=this[0],d=this.attr("id"),p=(p=e||void 0===f.elements?f.getElementsByTagName("*"):f.elements)&&O.makeArray(p);if(!(p=d&&(e||/(Edge|Trident)\//.test(navigator.userAgent))&&(d=O(':input[form="'+d+'"]').get()).length?(p||[]).concat(d):p)||!p.length)return a;for(n=0,u=(p=O.isFunction(r)?O.map(p,r):p).length;n<u;n++)if((l=(s=p[n]).name)&&!s.disabled)if(e&&f.clk&&"image"===s.type)f.clk===s&&(a.push({name:l,value:O(s).val(),type:s.type}),a.push({name:l+".x",value:f.clk_x},{name:l+".y",value:f.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:l,value:i[o]});else if(h.fileapi&&"file"===s.type){t&&t.push(s);var m=s.files;if(m.length)for(o=0;o<m.length;o++)a.push({name:l,value:m[o],type:s.type});else a.push({name:l,value:"",type:s.type})}else null!=i&&(t&&t.push(s),a.push({name:l,value:i,type:s.type,required:s.required}));return!e&&f.clk&&(l=(r=(d=O(f.clk))[0]).name)&&!r.disabled&&"image"===r.type&&(a.push({name:l,value:d.val()}),a.push({name:l+".x",value:f.clk_x},{name:l+".y",value:f.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");t=e.selectedIndex;if(t<0)return null;for(var o=[],i=e.options,s="select-one"===a,u=s?t+1:i.length,c=s?t: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 r=O(t.attr("for")),a=t.find("input,select,textarea");return r[0]&&a.unshift(r[0]),a.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: Sun Apr 28 01:00:03 2024 Cross-referenced by PHPXref 0.7.1