Blame view

backend/file-preview/fileView-server/src/main/resources/static/js/jquery.form.min.js 12.7 KB
8d73e917   陈威   初始化提交
1
(function(e){"use strict";function t(t){var n=t.data;t.isDefaultPrevented()||(t.preventDefault(),e(this).ajaxSubmit(n))}function n(t){var n=t.target,i=e(n);if(!i.is(":submit,input:image")){var r=i.closest(":submit");if(0===r.length)return;n=r[0]}var o=this;if(o.clk=n,"image"==n.type)if(void 0!==t.offsetX)o.clk_x=t.offsetX,o.clk_y=t.offsetY;else if("function"==typeof e.fn.offset){var a=i.offset();o.clk_x=t.pageX-a.left,o.clk_y=t.pageY-a.top}else o.clk_x=t.pageX-n.offsetLeft,o.clk_y=t.pageY-n.offsetTop;setTimeout(function(){o.clk=o.clk_x=o.clk_y=null},100)}function i(){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)}}var r={};r.fileapi=void 0!==e("<input type='file'/>").get(0).files,r.formdata=void 0!==window.FormData,e.fn.ajaxSubmit=function(t){function n(n){for(var i=new FormData,r=0;n.length>r;r++)i.append(n[r].name,n[r].value);if(t.extraData)for(var o in t.extraData)t.extraData.hasOwnProperty(o)&&i.append(o,t.extraData[o]);t.data=null;var a=e.extend(!0,{},e.ajaxSettings,t,{contentType:!1,processData:!1,cache:!1,type:"POST"});t.uploadProgress&&(a.xhr=function(){var e=jQuery.ajaxSettings.xhr();return e.upload&&(e.upload.onprogress=function(e){var n=0,i=e.loaded||e.position,r=e.total;e.lengthComputable&&(n=Math.ceil(100*(i/r))),t.uploadProgress(e,i,r,n)}),e}),a.data=null;var s=a.beforeSend;a.beforeSend=function(e,n){n.data=i,s&&s.call(n,e,t)},e.ajax(a)}function o(n){function r(e){var t=e.contentWindow?e.contentWindow.document:e.contentDocument?e.contentDocument:e.document;return t}function o(){function t(){try{var e=r(m).readyState;i("state = "+e),e&&"uninitialized"==e.toLowerCase()&&setTimeout(t,50)}catch(n){i("Server abort: ",n," (",n.name,")"),s(T),w&&clearTimeout(w),w=void 0}}var n=c.attr("target"),o=c.attr("action");k.setAttribute("target",f),a||k.setAttribute("method","POST"),o!=d.url&&k.setAttribute("action",d.url),d.skipEncodingOverride||a&&!/post/i.test(a)||c.attr({encoding:"multipart/form-data",enctype:"multipart/form-data"}),d.timeout&&(w=setTimeout(function(){x=!0,s(_)},d.timeout));var l=[];try{if(d.extraData)for(var u in d.extraData)d.extraData.hasOwnProperty(u)&&l.push(e('<input type="hidden" name="'+u+'">').attr("value",d.extraData[u]).appendTo(k)[0]);d.iframeTarget||(g.appendTo("body"),m.attachEvent?m.attachEvent("onload",s):m.addEventListener("load",s,!1)),setTimeout(t,15),k.submit()}finally{k.setAttribute("action",o),n?k.setAttribute("target",n):c.removeAttr("target"),e(l).remove()}}function s(t){if(!v.aborted&&!D){try{I=r(m)}catch(n){i("cannot access response document: ",n),t=T}if(t===_&&v)return v.abort("timeout"),void 0;if(t==T&&v)return v.abort("server abort"),void 0;if(I&&I.location.href!=d.iframeSrc||x){m.detachEvent?m.detachEvent("onload",s):m.removeEventListener("load",s,!1);var o,a="success";try{if(x)throw"timeout";var l="xml"==d.dataType||I.XMLDocument||e.isXMLDoc(I);if(i("isXml="+l),!l&&window.opera&&(null===I.body||!I.body.innerHTML)&&--L)return i("requeing onLoad callback, DOM not available"),setTimeout(s,250),void 0;var c=I.body?I.body:I.documentElement;v.responseText=c?c.innerHTML:null,v.responseXML=I.XMLDocument?I.XMLDocument:I,l&&(d.dataType="xml"),v.getResponseHeader=function(e){var t={"content-type":d.dataType};return t[e]},c&&(v.status=Number(c.getAttribute("status"))||v.status,v.statusText=c.getAttribute("statusText")||v.statusText);var u=(d.dataType||"").toLowerCase(),p=/(json|script|text)/.test(u);if(p||d.textarea){var f=I.getElementsByTagName("textarea")[0];if(f)v.responseText=f.value,v.status=Number(f.getAttribute("status"))||v.status,v.statusText=f.getAttribute("statusText")||v.statusText;else if(p){var b=I.getElementsByTagName("pre")[0],y=I.getElementsByTagName("body")[0];b?v.responseText=b.textContent?b.textContent:b.innerText:y&&(v.responseText=y.textContent?y.textContent:y.innerText)}}else"xml"==u&&!v.responseXML&&v.responseText&&(v.responseXML=R(v.responseText));try{A=P(v,u,d)}catch(t){a="parsererror",v.error=o=t||a}}catch(t){i("error caught: ",t),a="error",v.error=o=t||a}v.aborted&&(i("upload aborted"),a=null),v.status&&(a=v.status>=200&&300>v.status||304===v.status?"success":"error"),"success"===a?(d.success&&d.success.call(d.context,A,"success",v),h&&e.event.trigger("ajaxSuccess",[v,d])):a&&(void 0===o&&(o=v.statusText),d.error&&d.error.call(d.context,v,a,o),h&&e.event.trigger("ajaxError",[v,d,o])),h&&e.event.trigger("ajaxComplete",[v,d]),h&&!--e.active&&e.event.trigger("ajaxStop"),d.complete&&d.complete.call(d.context,v,a),D=!0,d.timeout&&clearTimeout(w),setTimeout(function(){d.iframeTarget||g.remove(),v.responseXML=null},100)}}}var l,u,d,h,f,g,m,v,b,y,x,w,k=c[0],C=!!e.fn.prop;if(e(":input[name=submit],:input[id=submit]",k).length)return alert('Error: Form elements must not have name or id of "submit".'),void 0;if(n)for(u=0;p.length>u;u++)l=e(p[u]),C?l.prop("disabled",!1):l.removeAttr("disabled");if(d=e.extend(!0,{},e.ajaxSettings,t),d.context=d.context||d,f="jqFormIO"+(new Date).getTime(),d.iframeTarget?(g=e(d.iframeTarget),y=g.attr("name"),y?f=y:g.attr("name",f)):(g=e('<iframe name="'+f+'" src="'+d.iframeSrc+'" />'),g.css({position:"absolute",top:"-1000px",left:"-1000px"})),m=g[0],v={aborted:0,responseText:null,responseXML:null,status:0,statusText:"n/a",getAllResponseHeaders:function(){},getResponseHeader:function(){},setRequestHeader:function(){},abort:function(t){var n="timeout"===t?"timeout":"aborted";i("aborting upload... "+n),this.aborted=1,g.attr("src",d.iframeSrc),v.error=n,d.error&&d.error.call(d.context,v,n,t),h&&e.event.trigger("ajaxError",[v,d,n]),d.complete&&d.complete.call(d.context,v,n)}},h=d.global,h&&0===e.active++&&e.event.trigger("ajaxStart"),h&&e.event.trigger("ajaxSend",[v,d]),d.beforeSend&&d.beforeSend.call(d.context,v,d)===!1)return d.global&&e.active--,void 0;if(!v.aborted){b=k.clk,b&&(y=b.name,y&&!b.disabled&&(d.extraData=d.extraData||{},d.extraData[y]=b.value,"image"==b.type&&(d.extraData[y+".x"]=k.clk_x,d.extraData[y+".y"]=k.clk_y)));var _=1,T=2,E=e("meta[name=csrf-token]").attr("content"),S=e("meta[name=csrf-param]").attr("content");S&&E&&(d.extraData=d.extraData||{},d.extraData[S]=E),d.forceSync?o():setTimeout(o,10);var A,I,D,L=50,R=e.parseXML||function(e,t){return window.ActiveXObject?(t=new ActiveXObject("Microsoft.XMLDOM"),t.async="false",t.loadXML(e)):t=(new DOMParser).parseFromString(e,"text/xml"),t&&t.documentElement&&"parsererror"!=t.documentElement.nodeName?t:null},O=e.parseJSON||function(e){return window.eval("("+e+")")},P=function(t,n,i){var r=t.getResponseHeader("content-type")||"",o="xml"===n||!n&&r.indexOf("xml")>=0,a=o?t.responseXML:t.responseText;return o&&"parsererror"===a.documentElement.nodeName&&e.error&&e.error("parsererror"),i&&i.dataFilter&&(a=i.dataFilter(a,n)),"string"==typeof a&&("json"===n||!n&&r.indexOf("json")>=0?a=O(a):("script"===n||!n&&r.indexOf("javascript")>=0)&&e.globalEval(a)),a}}}if(!this.length)return i("ajaxSubmit: skipping submit process - no element selected"),this;var a,s,l,c=this;"function"==typeof t&&(t={success:t}),a=this.attr("method"),s=this.attr("action"),l="string"==typeof s?e.trim(s):"",l=l||window.location.href||"",l&&(l=(l.match(/^([^#]+)/)||[])[1]),t=e.extend(!0,{url:l,success:e.ajaxSettings.success,type:a||"GET",iframeSrc:/^https/i.test(window.location.href||"")?"javascript:false":"about:blank"},t);var u={};if(this.trigger("form-pre-serialize",[this,t,u]),u.veto)return i("ajaxSubmit: submit vetoed via form-pre-serialize trigger"),this;if(t.beforeSerialize&&t.beforeSerialize(this,t)===!1)return i("ajaxSubmit: submit aborted via beforeSerialize callback"),this;var d=t.traditional;void 0===d&&(d=e.ajaxSettings.traditional);var h,p=[],f=this.formToArray(t.semantic,p);if(t.data&&(t.extraData=t.data,h=e.param(t.data,d)),t.beforeSubmit&&t.beforeSubmit(f,this,t)===!1)return i("ajaxSubmit: submit aborted via beforeSubmit callback"),this;if(this.trigger("form-submit-validate",[f,this,t,u]),u.veto)return i("ajaxSubmit: submit vetoed via form-submit-validate trigger"),this;var g=e.param(f,d);h&&(g=g?g+"&"+h:h),"GET"==t.type.toUpperCase()?(t.url+=(t.url.indexOf("?")>=0?"&":"?")+g,t.data=null):t.data=g;var m=[];if(t.resetForm&&m.push(function(){c.resetForm()}),t.clearForm&&m.push(function(){c.clearForm(t.includeHidden)}),!t.dataType&&t.target){var v=t.success||function(){};m.push(function(n){var i=t.replaceTarget?"replaceWith":"html";e(t.target)[i](n).each(v,arguments)})}else t.success&&m.push(t.success);t.success=function(e,n,i){for(var r=t.context||t,o=0,a=m.length;a>o;o++)m[o].apply(r,[e,n,i||c,c])};var b=e("input:file:enabled[value]",this),y=b.length>0,x="multipart/form-data",w=c.attr("enctype")==x||c.attr("encoding")==x,k=r.fileapi&&r.formdata;i("fileAPI :"+k);var C=(y||w)&&!k;t.iframe!==!1&&(t.iframe||C)?t.closeKeepAlive?e.get(t.closeKeepAlive,function(){o(f)}):o(f):(y||w)&&k?n(f):e.ajax(t);for(var _=0;p.length>_;_++)p[_]=null;return this.trigger("form-submit-notify",[this,t]),this},e.fn.ajaxForm=function(r){if(r=r||{},r.delegation=r.delegation&&e.isFunction(e.fn.on),!r.delegation&&0===this.length){var o={s:this.selector,c:this.context};return!e.isReady&&o.s?(i("DOM not ready, queuing ajaxForm"),e(function(){e(o.s,o.c).ajaxForm(r)}),this):(i("terminating; zero elements found by selector"+(e.isReady?"":" (DOM not ready)")),this)}return r.delegation?(e(document).off("submit.form-plugin",this.selector,t).off("click.form-plugin",this.selector,n).on("submit.form-plugin",this.selector,r,t).on("click.form-plugin",this.selector,r,n),this):this.ajaxFormUnbind().bind("submit.form-plugin",r,t).bind("click.form-plugin",r,n)},e.fn.ajaxFormUnbind=function(){return this.unbind("submit.form-plugin click.form-plugin")},e.fn.formToArray=function(t,n){var i=[];if(0===this.length)return i;var o=this[0],a=t?o.getElementsByTagName("*"):o.elements;if(!a)return i;var s,l,c,u,d,h,p;for(s=0,h=a.length;h>s;s++)if(d=a[s],c=d.name)if(t&&o.clk&&"image"==d.type)d.disabled||o.clk!=d||(i.push({name:c,value:e(d).val(),type:d.type}),i.push({name:c+".x",value:o.clk_x},{name:c+".y",value:o.clk_y}));else if(u=e.fieldValue(d,!0),u&&u.constructor==Array)for(n&&n.push(d),l=0,p=u.length;p>l;l++)i.push({name:c,value:u[l]});else if(r.fileapi&&"file"==d.type&&!d.disabled){n&&n.push(d);var f=d.files;if(f.length)for(l=0;f.length>l;l++)i.push({name:c,value:f[l],type:d.type});else i.push({name:c,value:"",type:d.type})}else null!==u&&u!==void 0&&(n&&n.push(d),i.push({name:c,value:u,type:d.type,required:d.required}));if(!t&&o.clk){var g=e(o.clk),m=g[0];c=m.name,c&&!m.disabled&&"image"==m.type&&(i.push({name:c,value:g.val()}),i.push({name:c+".x",value:o.clk_x},{name:c+".y",value:o.clk_y}))}return i},e.fn.formSerialize=function(t){return e.param(this.formToArray(t))},e.fn.fieldSerialize=function(t){var n=[];return this.each(function(){var i=this.name;if(i){var r=e.fieldValue(this,t);if(r&&r.constructor==Array)for(var o=0,a=r.length;a>o;o++)n.push({name:i,value:r[o]});else null!==r&&r!==void 0&&n.push({name:this.name,value:r})}}),e.param(n)},e.fn.fieldValue=function(t){for(var n=[],i=0,r=this.length;r>i;i++){var o=this[i],a=e.fieldValue(o,t);null===a||void 0===a||a.constructor==Array&&!a.length||(a.constructor==Array?e.merge(n,a):n.push(a))}return n},e.fieldValue=function(t,n){var i=t.name,r=t.type,o=t.tagName.toLowerCase();if(void 0===n&&(n=!0),n&&(!i||t.disabled||"reset"==r||"button"==r||("checkbox"==r||"radio"==r)&&!t.checked||("submit"==r||"image"==r)&&t.form&&t.form.clk!=t||"select"==o&&-1==t.selectedIndex))return null;if("select"==o){var a=t.selectedIndex;if(0>a)return null;for(var s=[],l=t.options,c="select-one"==r,u=c?a+1:l.length,d=c?a:0;u>d;d++){var h=l[d];if(h.selected){var p=h.value;if(p||(p=h.attributes&&h.attributes.value&&!h.attributes.value.specified?h.text:h.value),c)return p;s.push(p)}}return s}return e(t).val()},e.fn.clearForm=function(t){return this.each(function(){e("input,select,textarea",this).clearFields(t)})},e.fn.clearFields=e.fn.clearInputs=function(t){var n=/^(?:color|date|datetime|email|month|number|password|range|search|tel|text|time|url|week)$/i;return this.each(function(){var i=this.type,r=this.tagName.toLowerCase();n.test(i)||"textarea"==r?this.value="":"checkbox"==i||"radio"==i?this.checked=!1:"select"==r?this.selectedIndex=-1:t&&(t===!0&&/hidden/.test(i)||"string"==typeof t&&e(this).is(t))&&(this.value="")})},e.fn.resetForm=function(){return this.each(function(){("function"==typeof this.reset||"object"==typeof this.reset&&!this.reset.nodeType)&&this.reset()})},e.fn.enable=function(e){return void 0===e&&(e=!0),this.each(function(){this.disabled=!e})},e.fn.selected=function(t){return void 0===t&&(t=!0),this.each(function(){var n=this.type;if("checkbox"==n||"radio"==n)this.checked=t;else if("option"==this.tagName.toLowerCase()){var i=e(this).parent("select");t&&i[0]&&"select-one"==i[0].type&&i.find("option").selected(!1),this.selected=t}})},e.fn.ajaxSubmit.debug=!1})(jQuery);