You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
17 KiB

/*!
* jQuery Form Plugin
* version: 4.3.0
* Requires jQuery v1.7.2 or later
* Project repository: https://github.com/jquery-form/form
* Copyright 2017 Kevin Morris
* Copyright 2006 M. Alsup
* Dual licensed under the LGPL-2.1+ or MIT licenses
* https://github.com/jquery-form/form#license
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*/
!function(e){"function"==typeof define&&define.amd?define(["jquery"],e):"object"==typeof module&&module.exports?module.exports=function(t,r){return void 0===r&&(r="undefined"!=typeof window?require("jquery"):require("jquery")(t)),e(r),r}:e(jQuery)}(function(e){"use strict";var t=/\r?\n/g,r={};r.fileapi=void 0!==e('<input type="file">').get(0).files,r.formdata=void 0!==window.FormData;var a=!!e.fn.prop;function n(t){var r=t.data;t.isDefaultPrevented()||(t.preventDefault(),e(t.target).closest("form").ajaxSubmit(r))}function i(t){var r=t.target,a=e(r);if(!a.is("[type=submit],[type=image]")){var n=a.closest("[type=submit]");if(0===n.length)return;r=n[0]}var i=r.form;if(i.clk=r,"image"===r.type)if(void 0!==t.offsetX)i.clk_x=t.offsetX,i.clk_y=t.offsetY;else if("function"==typeof e.fn.offset){var o=a.offset();i.clk_x=t.pageX-o.left,i.clk_y=t.pageY-o.top}else i.clk_x=t.pageX-r.offsetLeft,i.clk_y=t.pageY-r.offsetTop;setTimeout(function(){i.clk=i.clk_x=i.clk_y=null},100)}function o(){if(e.fn.ajaxSubmit.debug){var t="[jquery.form] "+Array.prototype.join.call(arguments,"");window.console&&window.console.log?window.console.log(t):window.opera&&window.opera.postError&&window.opera.postError(t)}}e.fn.attr2=function(){if(!a)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)},e.fn.ajaxSubmit=function(t,n,i,s){if(!this.length)return o("ajaxSubmit: skipping submit process - no element selected"),this;var u,c,l,f,d=this;"function"==typeof t?t={success:t}:"string"==typeof t||!1===t&&arguments.length>0?(t={url:t,data:n,dataType:i},"function"==typeof s&&(t.success=s)):void 0===t&&(t={}),u=t.method||t.type||this.attr2("method"),(l=(l="string"==typeof(c=t.url||this.attr2("action"))?e.trim(c):"")||window.location.href||"")&&(l=(l.match(/^([^#]+)/)||[])[1]),f=/(MSIE|Trident)/.test(navigator.userAgent||"")&&/^https/i.test(window.location.href||"")?"javascript:false":"about:blank",t=e.extend(!0,{url:l,success:e.ajaxSettings.success,type:u||e.ajaxSettings.type,iframeSrc:f},t);var m={};if(this.trigger("form-pre-serialize",[this,t,m]),m.veto)return o("ajaxSubmit: submit vetoed via form-pre-serialize trigger"),this;if(t.beforeSerialize&&!1===t.beforeSerialize(this,t))return o("ajaxSubmit: submit aborted via beforeSerialize callback"),this;var p=t.traditional;void 0===p&&(p=e.ajaxSettings.traditional);var h,v=[],g=this.formToArray(t.semantic,v,t.filtering);if(t.data){var x=e.isFunction(t.data)?t.data(g):t.data;t.extraData=x,h=e.param(x,p)}if(t.beforeSubmit&&!1===t.beforeSubmit(g,this,t))return o("ajaxSubmit: submit aborted via beforeSubmit callback"),this;if(this.trigger("form-submit-validate",[g,this,t,m]),m.veto)return o("ajaxSubmit: submit vetoed via form-submit-validate trigger"),this;var y=e.param(g,p);h&&(y=y?y+"&"+h:h),"GET"===t.type.toUpperCase()?(t.url+=(t.url.indexOf("?")>=0?"&":"?")+y,t.data=null):t.data=y;var b=[];if(t.resetForm&&b.push(function(){d.resetForm()}),t.clearForm&&b.push(function(){d.clearForm(t.includeHidden)}),!t.dataType&&t.target){var T=t.success||function(){};b.push(function(r,a,n){var i=arguments,o=t.replaceTarget?"replaceWith":"html";"html"==o&&(r=e.parseHTML(e("<div>").text(r).html())),e(t.target)[o](r).each(function(){T.apply(this,i)})})}else t.success&&(e.isArray(t.success)?e.merge(b,t.success):b.push(t.success));if(t.success=function(e,r,a){for(var n=t.context||this,i=0,o=b.length;i<o;i++)b[i].apply(n,[e,r,a||d,d])},t.error){var j=t.error;t.error=function(e,r,a){var n=t.context||this;j.apply(n,[e,r,a,d])}}if(t.complete){var w=t.complete;t.complete=function(e,r){var a=t.context||this;w.apply(a,[e,r,d])}}var S=e("input[type=file]:enabled",this).filter(function(){return""!==e(this).val()}).length>0,k="multipart/form-data",D=d.attr("enctype")===k||d.attr("encoding")===k,A=r.fileapi&&r.formdata;o("fileAPI :"+A);var F,L=(S||D)&&!A;!1!==t.iframe&&(t.iframe||L)?t.closeKeepAlive?e.get(t.closeKeepAlive,function(){F=M(g)}):F=M(g):F=(S||D)&&A?function(r){for(var a=new FormData,n=0;n<r.length;n++)a.append(r[n].name,r[n].value);if(t.ex