SickGear/gui/slick/js/lib/jquery.form.min.js

42 lines
16 KiB
JavaScript

/*
jQuery Form Plugin
version: 3.51.0-2014.06.20
Requires jQuery v1.5 or later
Copyright (c) 2014 M. Alsup
Examples and documentation at: http://malsup.com/jquery/form/
Project repository: https://github.com/malsup/form
Dual licensed under the MIT and GPL licenses.
https://github.com/malsup/form#copyright-and-license
*/
var $jscomp={scope:{},findInternal:function(b,l,f){b instanceof String&&(b=String(b));for(var p=b.length,r=0;r<p;r++){var v=b[r];if(l.call(f,v,r,b))return{i:r,v:v}}return{i:-1,v:void 0}}};$jscomp.defineProperty="function"==typeof Object.defineProperties?Object.defineProperty:function(b,l,f){if(f.get||f.set)throw new TypeError("ES3 does not support getters and setters.");b!=Array.prototype&&b!=Object.prototype&&(b[l]=f.value)};
$jscomp.getGlobal=function(b){return"undefined"!=typeof window&&window===b?b:"undefined"!=typeof global&&null!=global?global:b};$jscomp.global=$jscomp.getGlobal(this);$jscomp.polyfill=function(b,l,f,p){if(l){f=$jscomp.global;b=b.split(".");for(p=0;p<b.length-1;p++){var r=b[p];r in f||(f[r]={});f=f[r]}b=b[b.length-1];p=f[b];l=l(p);l!=p&&null!=l&&$jscomp.defineProperty(f,b,{configurable:!0,writable:!0,value:l})}};
$jscomp.polyfill("Array.prototype.find",function(b){return b?b:function(b,f){return $jscomp.findInternal(this,b,f).v}},"es6-impl","es3");
(function(b){"function"===typeof define&&define.amd?define(["jquery"],b):b("undefined"!=typeof jQuery?jQuery:window.Zepto)})(function(b){function l(a){var n=a.data;a.isDefaultPrevented()||(a.preventDefault(),b(a.target).ajaxSubmit(n))}function f(a){var n=a.target,d=b(n);if(!d.is("[type=submit],[type=image]")){n=d.closest("[type=submit]");if(0===n.length)return;n=n[0]}var c=this;c.clk=n;"image"==n.type&&(void 0!==a.offsetX?(c.clk_x=a.offsetX,c.clk_y=a.offsetY):"function"==typeof b.fn.offset?(d=d.offset(),
c.clk_x=a.pageX-d.left,c.clk_y=a.pageY-d.top):(c.clk_x=a.pageX-n.offsetLeft,c.clk_y=a.pageY-n.offsetTop));setTimeout(function(){c.clk=c.clk_x=c.clk_y=null},100)}function p(){if(b.fn.ajaxSubmit.debug){var a="[jquery.form] "+Array.prototype.join.call(arguments,"");window.console&&window.console.log?window.console.log(a):window.opera&&window.opera.postError&&window.opera.postError(a)}}var r,v;r=void 0!==b("<input type='file'/>").get(0).files;v=void 0!==window.FormData;var H=!!b.fn.prop;b.fn.attr2=function(){if(!H)return this.attr.apply(this,
arguments);var a=this.prop.apply(this,arguments);return a&&a.jquery||"string"===typeof a?a:this.attr.apply(this,arguments)};b.fn.ajaxSubmit=function(a){function n(c){c=b.param(c,a.traditional).split("&");var g=c.length,n=[],h,d;for(h=0;h<g;h++)c[h]=c[h].replace(/\+/g," "),d=c[h].split("="),n.push([decodeURIComponent(d[0]),decodeURIComponent(d[1])]);return n}function d(c){for(var g=new FormData,d=0;d<c.length;d++)g.append(c[d].name,c[d].value);if(a.extraData)for(c=n(a.extraData),d=0;d<c.length;d++)c[d]&&
g.append(c[d][0],c[d][1]);a.data=null;d=b.extend(!0,{},b.ajaxSettings,a,{contentType:!1,processData:!1,cache:!1,type:h||"POST"});a.uploadProgress&&(d.xhr=function(){var c=b.ajaxSettings.xhr();c.upload&&c.upload.addEventListener("progress",function(b){var e=0,c=b.loaded||b.position,d=b.total;b.lengthComputable&&(e=Math.ceil(c/d*100));a.uploadProgress(b,c,d,e)},!1);return c});d.data=null;var m=d.beforeSend;d.beforeSend=function(b,c){c.data=a.formData?a.formData:g;m&&m.call(this,b,c)};return b.ajax(d)}
function c(c){function d(a){var b=null;try{a.contentWindow&&(b=a.contentWindow.document)}catch(B){p("cannot get iframe.contentWindow document: "+B)}if(b)return b;try{b=a.contentDocument?a.contentDocument:a.document}catch(B){p("cannot get iframe.contentDocument: "+B),b=a.document}return b}function g(){function a(){try{var b=d(w).readyState;p("state = "+b);b&&"uninitialized"==b.toLowerCase()&&setTimeout(a,50)}catch(I){p("Server abort: ",I," (",I.name,")"),n(2),v&&clearTimeout(v),v=void 0}}var c=t.attr2("target"),
g=t.attr2("action"),k=t.attr("enctype")||t.attr("encoding")||"multipart/form-data";m.setAttribute("target",l);h&&!/post/i.test(h)||m.setAttribute("method","POST");g!=e.url&&m.setAttribute("action",e.url);e.skipEncodingOverride||h&&!/post/i.test(h)||t.attr({encoding:"multipart/form-data",enctype:"multipart/form-data"});e.timeout&&(v=setTimeout(function(){D=!0;n(1)},e.timeout));var f=[];try{if(e.extraData)for(var q in e.extraData)e.extraData.hasOwnProperty(q)&&(b.isPlainObject(e.extraData[q])&&e.extraData[q].hasOwnProperty("name")&&
e.extraData[q].hasOwnProperty("value")?f.push(b('<input type="hidden" name="'+e.extraData[q].name+'">').val(e.extraData[q].value).appendTo(m)[0]):f.push(b('<input type="hidden" name="'+q+'">').val(e.extraData[q]).appendTo(m)[0]));e.iframeTarget||r.appendTo("body");w.attachEvent?w.attachEvent("onload",n):w.addEventListener("load",n,!1);setTimeout(a,15);try{m.submit()}catch(L){document.createElement("form").submit.apply(m)}}finally{m.setAttribute("action",g),m.setAttribute("enctype",k),c?m.setAttribute("target",
c):t.removeAttr("target"),b(f).remove()}}function n(a){if(!k.aborted&&!J)if(u=d(w),u||(p("cannot access response document"),a=2),1===a&&k)k.abort("timeout"),x.reject(k,"timeout");else if(2==a&&k)k.abort("server abort"),x.reject(k,"error","server abort");else if(u&&u.location.href!=e.iframeSrc||D){w.detachEvent?w.detachEvent("onload",n):w.removeEventListener("load",n,!1);a="success";var c;try{if(D)throw"timeout";var g="xml"==e.dataType||u.XMLDocument||b.isXMLDoc(u);p("isXml="+g);if(!g&&window.opera&&
(null===u.body||!u.body.innerHTML)&&--K){p("requeing onLoad callback, DOM not available");setTimeout(n,250);return}var h=u.body?u.body:u.documentElement;k.responseText=h?h.innerHTML:null;k.responseXML=u.XMLDocument?u.XMLDocument:u;g&&(e.dataType="xml");k.getResponseHeader=function(a){return{"content-type":e.dataType}[a.toLowerCase()]};h&&(k.status=Number(h.getAttribute("status"))||k.status,k.statusText=h.getAttribute("statusText")||k.statusText);var m=(e.dataType||"").toLowerCase(),f=/(json|script|text)/.test(m);
if(f||e.textarea){var l=u.getElementsByTagName("textarea")[0];if(l)k.responseText=l.value,k.status=Number(l.getAttribute("status"))||k.status,k.statusText=l.getAttribute("statusText")||k.statusText;else if(f){var t=u.getElementsByTagName("pre")[0],A=u.getElementsByTagName("body")[0];t?k.responseText=t.textContent?t.textContent:t.innerText:A&&(k.responseText=A.textContent?A.textContent:A.innerText)}}else"xml"==m&&!k.responseXML&&k.responseText&&(k.responseXML=E(k.responseText));try{y=G(k,m,e)}catch(C){a=
"parsererror",k.error=c=C||a}}catch(C){p("error caught: ",C),a="error",k.error=c=C||a}k.aborted&&(p("upload aborted"),a=null);k.status&&(a=200<=k.status&&300>k.status||304===k.status?"success":"error");"success"===a?(e.success&&e.success.call(e.context,y,"success",k),x.resolve(k.responseText,"success",k),q&&b.event.trigger("ajaxSuccess",[k,e])):a&&(void 0===c&&(c=k.statusText),e.error&&e.error.call(e.context,k,a,c),x.reject(k,"error",c),q&&b.event.trigger("ajaxError",[k,e,c]));q&&b.event.trigger("ajaxComplete",
[k,e]);q&&!--b.active&&b.event.trigger("ajaxStop");e.complete&&e.complete.call(e.context,k,a);J=!0;e.timeout&&clearTimeout(v);setTimeout(function(){e.iframeTarget?r.attr("src",e.iframeSrc):r.remove();k.responseXML=null},100)}}var m=t[0],f,e,q,l,r,w,k,D,v,x=b.Deferred();x.abort=function(a){k.abort(a)};if(c)for(f=0;f<z.length;f++)c=b(z[f]),H?c.prop("disabled",!1):c.removeAttr("disabled");e=b.extend(!0,{},b.ajaxSettings,a);e.context=e.context||e;l="jqFormIO"+(new Date).getTime();e.iframeTarget?(r=b(e.iframeTarget),
(f=r.attr2("name"))?l=f:r.attr2("name",l)):(r=b('<iframe name="'+l+'" src="'+e.iframeSrc+'" />'),r.css({position:"absolute",top:"-1000px",left:"-1000px"}));w=r[0];k={aborted:0,responseText:null,responseXML:null,status:0,statusText:"n/a",getAllResponseHeaders:function(){},getResponseHeader:function(){},setRequestHeader:function(){},abort:function(a){var c="timeout"===a?"timeout":"aborted";p("aborting upload... "+c);this.aborted=1;try{w.contentWindow.document.execCommand&&w.contentWindow.document.execCommand("Stop")}catch(B){}r.attr("src",
e.iframeSrc);k.error=c;e.error&&e.error.call(e.context,k,c,a);q&&b.event.trigger("ajaxError",[k,e,c]);e.complete&&e.complete.call(e.context,k,c)}};(q=e.global)&&0===b.active++&&b.event.trigger("ajaxStart");q&&b.event.trigger("ajaxSend",[k,e]);if(e.beforeSend&&!1===e.beforeSend.call(e.context,k,e))return e.global&&b.active--,x.reject(),x;if(k.aborted)return x.reject(),x;(c=m.clk)&&(f=c.name)&&!c.disabled&&(e.extraData=e.extraData||{},e.extraData[f]=c.value,"image"==c.type&&(e.extraData[f+".x"]=m.clk_x,
e.extraData[f+".y"]=m.clk_y));c=b("meta[name=csrf-token]").attr("content");(f=b("meta[name=csrf-param]").attr("content"))&&c&&(e.extraData=e.extraData||{},e.extraData[f]=c);e.forceSync?g():setTimeout(g,10);var y,u,K=50,J,E=b.parseXML||function(a,b){window.ActiveXObject?(b=new ActiveXObject("Microsoft.XMLDOM"),b.async="false",b.loadXML(a)):b=(new DOMParser).parseFromString(a,"text/xml");return b&&b.documentElement&&"parsererror"!=b.documentElement.nodeName?b:null},F=b.parseJSON||function(a){return window.eval("("+
a+")")},G=function(a,c,e){var d=a.getResponseHeader("content-type")||"",g="xml"===c||!c&&0<=d.indexOf("xml");a=g?a.responseXML:a.responseText;g&&"parsererror"===a.documentElement.nodeName&&b.error&&b.error("parsererror");e&&e.dataFilter&&(a=e.dataFilter(a,c));"string"===typeof a&&("json"===c||!c&&0<=d.indexOf("json")?a=F(a):("script"===c||!c&&0<=d.indexOf("javascript"))&&b.globalEval(a));return a};return x}if(!this.length)return p("ajaxSubmit: skipping submit process - no element selected"),this;
var h,g,t=this;"function"==typeof a?a={success:a}:void 0===a&&(a={});h=a.type||this.attr2("method");g=a.url||this.attr2("action");(g=(g="string"===typeof g?b.trim(g):"")||window.location.href||"")&&(g=(g.match(/^([^#]+)/)||[])[1]);a=b.extend(!0,{url:g,success:b.ajaxSettings.success,type:h||b.ajaxSettings.type,iframeSrc:/^https/i.test(window.location.href||"")?"javascript:false":"about:blank"},a);g={};this.trigger("form-pre-serialize",[this,a,g]);if(g.veto)return p("ajaxSubmit: submit vetoed via form-pre-serialize trigger"),
this;if(a.beforeSerialize&&!1===a.beforeSerialize(this,a))return p("ajaxSubmit: submit aborted via beforeSerialize callback"),this;var q=a.traditional;void 0===q&&(q=b.ajaxSettings.traditional);var z=[],m,f=this.formToArray(a.semantic,z);a.data&&(a.extraData=a.data,m=b.param(a.data,q));if(a.beforeSubmit&&!1===a.beforeSubmit(f,this,a))return p("ajaxSubmit: submit aborted via beforeSubmit callback"),this;this.trigger("form-submit-validate",[f,this,a,g]);if(g.veto)return p("ajaxSubmit: submit vetoed via form-submit-validate trigger"),
this;g=b.param(f,q);m&&(g=g?g+"&"+m:m);"GET"==a.type.toUpperCase()?(a.url+=(0<=a.url.indexOf("?")?"&":"?")+g,a.data=null):a.data=g;var l=[];a.resetForm&&l.push(function(){t.resetForm()});a.clearForm&&l.push(function(){t.clearForm(a.includeHidden)});if(!a.dataType&&a.target){var E=a.success||function(){};l.push(function(c){var d=a.replaceTarget?"replaceWith":"html";b(a.target)[d](c).each(E,arguments)})}else a.success&&l.push(a.success);a.success=function(b,c,d){for(var g=a.context||this,h=0,n=l.length;h<
n;h++)l[h].apply(g,[b,c,d||t,t])};if(a.error){var F=a.error;a.error=function(b,c,d){F.apply(a.context||this,[b,c,d,t])}}if(a.complete){var G=a.complete;a.complete=function(b,c){G.apply(a.context||this,[b,c,t])}}m=0<b("input[type=file]:enabled",this).filter(function(){return""!==b(this).val()}).length;g="multipart/form-data"==t.attr("enctype")||"multipart/form-data"==t.attr("encoding");q=r&&v;p("fileAPI :"+q);var y;!1!==a.iframe&&(a.iframe||(m||g)&&!q)?a.closeKeepAlive?b.get(a.closeKeepAlive,function(){y=
c(f)}):y=c(f):y=(m||g)&&q?d(f):b.ajax(a);t.removeData("jqxhr").data("jqxhr",y);for(m=0;m<z.length;m++)z[m]=null;this.trigger("form-submit-notify",[this,a]);return this};b.fn.ajaxForm=function(a){a=a||{};a.delegation=a.delegation&&b.isFunction(b.fn.on);if(!a.delegation&&0===this.length){var n=this.selector,d=this.context;if(!b.isReady&&n)return p("DOM not ready, queuing ajaxForm"),b(function(){b(n,d).ajaxForm(a)}),this;p("terminating; zero elements found by selector"+(b.isReady?"":" (DOM not ready)"));
return this}return a.delegation?(b(document).off("submit.form-plugin",this.selector,l).off("click.form-plugin",this.selector,f).on("submit.form-plugin",this.selector,a,l).on("click.form-plugin",this.selector,a,f),this):this.ajaxFormUnbind().bind("submit.form-plugin",a,l).bind("click.form-plugin",a,f)};b.fn.ajaxFormUnbind=function(){return this.unbind("submit.form-plugin click.form-plugin")};b.fn.formToArray=function(a,n){var d=[];if(0===this.length)return d;var c=this[0],h=this.attr("id"),g=a?c.getElementsByTagName("*"):
c.elements;g&&!/MSIE [678]/.test(navigator.userAgent)&&(g=b(g).get());h&&(h=b(':input[form="'+h+'"]').get(),h.length&&(g=(g||[]).concat(h)));if(!g||!g.length)return d;var f,q,l,m,p;f=0;for(p=g.length;f<p;f++)if(m=g[f],(h=m.name)&&!m.disabled)if(a&&c.clk&&"image"==m.type)c.clk==m&&(d.push({name:h,value:b(m).val(),type:m.type}),d.push({name:h+".x",value:c.clk_x},{name:h+".y",value:c.clk_y}));else if((l=b.fieldValue(m,!0))&&l.constructor==Array)for(n&&n.push(m),q=0,m=l.length;q<m;q++)d.push({name:h,
value:l[q]});else if(r&&"file"==m.type)if(n&&n.push(m),l=m.files,l.length)for(q=0;q<l.length;q++)d.push({name:h,value:l[q],type:m.type});else d.push({name:h,value:"",type:m.type});else null!==l&&"undefined"!=typeof l&&(n&&n.push(m),d.push({name:h,value:l,type:m.type,required:m.required}));!a&&c.clk&&(g=b(c.clk),f=g[0],(h=f.name)&&!f.disabled&&"image"==f.type&&(d.push({name:h,value:g.val()}),d.push({name:h+".x",value:c.clk_x},{name:h+".y",value:c.clk_y})));return d};b.fn.formSerialize=function(a){return b.param(this.formToArray(a))};
b.fn.fieldSerialize=function(a){var n=[];this.each(function(){var d=this.name;if(d){var c=b.fieldValue(this,a);if(c&&c.constructor==Array)for(var h=0,g=c.length;h<g;h++)n.push({name:d,value:c[h]});else null!==c&&"undefined"!=typeof c&&n.push({name:this.name,value:c})}});return b.param(n)};b.fn.fieldValue=function(a){for(var n=[],d=0,c=this.length;d<c;d++){var h=b.fieldValue(this[d],a);null===h||"undefined"==typeof h||h.constructor==Array&&!h.length||(h.constructor==Array?b.merge(n,h):n.push(h))}return n};
b.fieldValue=function(a,n){var d=a.name,c=a.type,h=a.tagName.toLowerCase();void 0===n&&(n=!0);if(n&&(!d||a.disabled||"reset"==c||"button"==c||("checkbox"==c||"radio"==c)&&!a.checked||("submit"==c||"image"==c)&&a.form&&a.form.clk!=a||"select"==h&&-1==a.selectedIndex))return null;if("select"==h){var g=a.selectedIndex;if(0>g)return null;for(var d=[],h=a.options,f=(c="select-one"==c)?g+1:h.length,g=c?g:0;g<f;g++){var l=h[g];if(l.selected){var p=l.value;p||(p=l.attributes&&l.attributes.value&&!l.attributes.value.specified?
l.text:l.value);if(c)return p;d.push(p)}}return d}return b(a).val()};b.fn.clearForm=function(a){return this.each(function(){b("input,select,textarea",this).clearFields(a)})};b.fn.clearFields=b.fn.clearInputs=function(a){var f=/^(?:color|date|datetime|email|month|number|password|range|search|tel|text|time|url|week)$/i;return this.each(function(){var d=this.type,c=this.tagName.toLowerCase();f.test(d)||"textarea"==c?this.value="":"checkbox"==d||"radio"==d?this.checked=!1:"select"==c?this.selectedIndex=
-1:"file"==d?/MSIE/.test(navigator.userAgent)?b(this).replaceWith(b(this).clone(!0)):b(this).val(""):a&&(!0===a&&/hidden/.test(d)||"string"==typeof a&&b(this).is(a))&&(this.value="")})};b.fn.resetForm=function(){return this.each(function(){("function"==typeof this.reset||"object"==typeof this.reset&&!this.reset.nodeType)&&this.reset()})};b.fn.enable=function(a){void 0===a&&(a=!0);return this.each(function(){this.disabled=!a})};b.fn.selected=function(a){void 0===a&&(a=!0);return this.each(function(){var f=
this.type;"checkbox"==f||"radio"==f?this.checked=a:"option"==this.tagName.toLowerCase()&&(f=b(this).parent("select"),a&&f[0]&&"select-one"==f[0].type&&f.find("option").selected(!1),this.selected=a)})};b.fn.ajaxSubmit.debug=!1});