1
0
Fork 0
mirror of https://github.com/morpheus65535/bazarr synced 2024-12-30 19:46:25 +00:00
bazarr/static/semantic/components/form.min.js
morpheus65535 66dac7f19c
Manual searching implementation (#137)
* Initial commit

* Continuing development

* Continuing development

* Continuing development

* Continuing development

* Continuing development

* Manual searching completed for episode

* Fix for multiple desired languages

* Fix some error

* Continuing development

* Continuing development

* Final part of manual searching #107
2018-09-10 17:10:33 -04:00

1 line
No EOL
20 KiB
JavaScript

!function(e,t,n,r){"use strict";t=void 0!==t&&t.Math==Math?t:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),e.fn.form=function(t){var i,a=e(this),o=a.selector||"",l=(new Date).getTime(),s=[],u=arguments[0],c=arguments[1],d="string"==typeof u,f=[].slice.call(arguments,1);return a.each(function(){var p,m,g,h,v,b,y,x,k,E,w,C,V,R,F,S,A=e(this),T=this,D=[],O=!1;(S={initialize:function(){S.get.settings(),d?(F===r&&S.instantiate(),S.invoke(u)):(F!==r&&F.invoke("destroy"),S.verbose("Initializing form validation",A,v),S.bindEvents(),S.set.defaults(),S.instantiate())},instantiate:function(){S.verbose("Storing instance of module",S),F=S,A.data(V,S)},destroy:function(){S.verbose("Destroying previous module",F),S.removeEvents(),A.removeData(V)},refresh:function(){S.verbose("Refreshing selector cache"),p=A.find(x.field),m=A.find(x.group),g=A.find(x.message),A.find(x.prompt),h=A.find(x.submit),A.find(x.clear),A.find(x.reset)},submit:function(){S.verbose("Submitting form",A),A.submit()},attachEvents:function(t,n){n=n||"submit",e(t).on("click"+R,function(e){S[n](),e.preventDefault()})},bindEvents:function(){S.verbose("Attaching form events"),A.on("submit"+R,S.validate.form).on("blur"+R,x.field,S.event.field.blur).on("click"+R,x.submit,S.submit).on("click"+R,x.reset,S.reset).on("click"+R,x.clear,S.clear),v.keyboardShortcuts&&A.on("keydown"+R,x.field,S.event.field.keydown),p.each(function(){var t=e(this),n=t.prop("type"),r=S.get.changeEvent(n,t);e(this).on(r+R,S.event.field.change)})},clear:function(){p.each(function(){var t=e(this),n=t.parent(),r=t.closest(m),i=r.find(x.prompt),a=t.data(y.defaultValue)||"",o=n.is(x.uiCheckbox),l=n.is(x.uiDropdown);r.hasClass(k.error)&&(S.verbose("Resetting error on field",r),r.removeClass(k.error),i.remove()),l?(S.verbose("Resetting dropdown value",n,a),n.dropdown("clear")):o?t.prop("checked",!1):(S.verbose("Resetting field value",t,a),t.val(""))})},reset:function(){p.each(function(){var t=e(this),n=t.parent(),i=t.closest(m),a=i.find(x.prompt),o=t.data(y.defaultValue),l=n.is(x.uiCheckbox),s=n.is(x.uiDropdown),u=i.hasClass(k.error);o!==r&&(u&&(S.verbose("Resetting error on field",i),i.removeClass(k.error),a.remove()),s?(S.verbose("Resetting dropdown value",n,o),n.dropdown("restore defaults")):l?(S.verbose("Resetting checkbox value",n,o),t.prop("checked",o)):(S.verbose("Resetting field value",t,o),t.val(o)))})},determine:{isValid:function(){var t=!0;return e.each(b,function(e,n){S.validate.field(n,e,!0)||(t=!1)}),t}},is:{bracketedRule:function(e){return e.type&&e.type.match(v.regExp.bracket)},shorthandFields:function(e){var t=e[Object.keys(e)[0]];return S.is.shorthandRules(t)},shorthandRules:function(t){return"string"==typeof t||e.isArray(t)},empty:function(e){return!e||0===e.length||(e.is('input[type="checkbox"]')?!e.is(":checked"):S.is.blank(e))},blank:function(t){return""===e.trim(t.val())},valid:function(t){var n=!0;return t?(S.verbose("Checking if field is valid",t),S.validate.field(b[t],t,!1)):(S.verbose("Checking if form is valid"),e.each(b,function(e,t){S.is.valid(e)||(n=!1)}),n)}},removeEvents:function(){A.off(R),p.off(R),h.off(R),p.off(R)},event:{field:{keydown:function(t){var n=e(this),r=t.which,i=n.is(x.input),a=n.is(x.checkbox),o=n.closest(x.uiDropdown).length>0,l=13;r==27&&(S.verbose("Escape key pressed blurring field"),n.blur()),t.ctrlKey||r!=l||!i||o||a||(O||(n.one("keyup"+R,S.event.field.keyup),S.submit(),S.debug("Enter pressed on input submitting form")),O=!0)},keyup:function(){O=!1},blur:function(t){var n=e(this),r=n.closest(m),i=S.get.validation(n);r.hasClass(k.error)?(S.debug("Revalidating field",n,i),i&&S.validate.field(i)):"blur"==v.on&&i&&S.validate.field(i)},change:function(t){var n=e(this),r=n.closest(m),i=S.get.validation(n);i&&("change"==v.on||r.hasClass(k.error)&&v.revalidate)&&(clearTimeout(S.timer),S.timer=setTimeout(function(){S.debug("Revalidating field",n,S.get.validation(n)),S.validate.field(i)},v.delay))}}},get:{ancillaryValue:function(e){return!(!e.type||!e.value&&!S.is.bracketedRule(e))&&(e.value!==r?e.value:e.type.match(v.regExp.bracket)[1]+"")},ruleName:function(e){return S.is.bracketedRule(e)?e.type.replace(e.type.match(v.regExp.bracket)[0],""):e.type},changeEvent:function(e,t){return"checkbox"==e||"radio"==e||"hidden"==e||t.is("select")?"change":S.get.inputEvent()},inputEvent:function(){return n.createElement("input").oninput!==r?"input":n.createElement("input").onpropertychange!==r?"propertychange":"keyup"},fieldsFromShorthand:function(t){var n={};return e.each(t,function(t,r){"string"==typeof r&&(r=[r]),n[t]={rules:[]},e.each(r,function(e,r){n[t].rules.push({type:r})})}),n},prompt:function(t,n){var r,i,a=S.get.ruleName(t),o=S.get.ancillaryValue(t),l=S.get.field(n.identifier),s=l.val(),u=e.isFunction(t.prompt)?t.prompt(s):t.prompt||v.prompt[a]||v.text.unspecifiedRule,c=-1!==u.search("{value}"),d=-1!==u.search("{name}");return c&&(u=u.replace("{value}",l.val())),d&&(i=1==(r=l.closest(x.group).find("label").eq(0)).length?r.text():l.prop("placeholder")||v.text.unspecifiedField,u=u.replace("{name}",i)),u=(u=u.replace("{identifier}",n.identifier)).replace("{ruleValue}",o),t.prompt||S.verbose("Using default validation prompt for type",u,a),u},settings:function(){if(e.isPlainObject(t)){var n=Object.keys(t);n.length>0&&(t[n[0]].identifier!==r&&t[n[0]].rules!==r)?(v=e.extend(!0,{},e.fn.form.settings,c),b=e.extend({},e.fn.form.settings.defaults,t),S.error(v.error.oldSyntax,T),S.verbose("Extending settings from legacy parameters",b,v)):(t.fields&&S.is.shorthandFields(t.fields)&&(t.fields=S.get.fieldsFromShorthand(t.fields)),v=e.extend(!0,{},e.fn.form.settings,t),b=e.extend({},e.fn.form.settings.defaults,v.fields),S.verbose("Extending settings",b,v))}else v=e.fn.form.settings,b=e.fn.form.settings.defaults,S.verbose("Using default form validation",b,v);C=v.namespace,y=v.metadata,x=v.selector,k=v.className,E=v.regExp,w=v.error,V="module-"+C,R="."+C,F=A.data(V),S.refresh()},field:function(t){return S.verbose("Finding field with identifier",t),t=S.escape.string(t),p.filter("#"+t).length>0?p.filter("#"+t):p.filter('[name="'+t+'"]').length>0?p.filter('[name="'+t+'"]'):p.filter('[name="'+t+'[]"]').length>0?p.filter('[name="'+t+'[]"]'):p.filter("[data-"+y.validate+'="'+t+'"]').length>0?p.filter("[data-"+y.validate+'="'+t+'"]'):e("<input/>")},fields:function(t){var n=e();return e.each(t,function(e,t){n=n.add(S.get.field(t))}),n},validation:function(t){var n,r;return!!b&&(e.each(b,function(e,i){r=i.identifier||e,S.get.field(r)[0]==t[0]&&(i.identifier=r,n=i)}),n||!1)},value:function(e){var t=[];return t.push(e),S.get.values.call(T,t)[e]},values:function(t){var n={};return(e.isArray(t)?S.get.fields(t):p).each(function(t,i){var a=e(i),o=(a.prop("type"),a.prop("name")),l=a.val(),s=a.is(x.checkbox),u=a.is(x.radio),c=-1!==o.indexOf("[]"),d=!!s&&a.is(":checked");o&&(c?(o=o.replace("[]",""),n[o]||(n[o]=[]),s?d?n[o].push(l||!0):n[o].push(!1):n[o].push(l)):u?n[o]!==r&&0!=n[o]||(n[o]=!!d&&(l||!0)):n[o]=s?!!d&&(l||!0):l)}),n}},has:{field:function(e){return S.verbose("Checking for existence of a field with identifier",e),"string"!=typeof(e=S.escape.string(e))&&S.error(w.identifier,e),p.filter("#"+e).length>0||(p.filter('[name="'+e+'"]').length>0||p.filter("[data-"+y.validate+'="'+e+'"]').length>0)}},escape:{string:function(e){return(e=String(e)).replace(E.escape,"\\$&")}},add:{rule:function(e,t){S.add.field(e,t)},field:function(t,n){var r={};S.is.shorthandRules(n)?(n=e.isArray(n)?n:[n],r[t]={rules:[]},e.each(n,function(e,n){r[t].rules.push({type:n})})):r[t]=n,b=e.extend({},b,r),S.debug("Adding rules",r,b)},fields:function(t){var n;n=t&&S.is.shorthandFields(t)?S.get.fieldsFromShorthand(t):t,b=e.extend({},b,n)},prompt:function(t,n){var i=S.get.field(t).closest(m),a=i.children(x.prompt),o=0!==a.length;n="string"==typeof n?[n]:n,S.verbose("Adding field error state",t),i.addClass(k.error),v.inline&&(o||(a=v.templates.prompt(n)).appendTo(i),a.html(n[0]),o?S.verbose("Inline errors are disabled, no inline error added",t):v.transition&&e.fn.transition!==r&&A.transition("is supported")?(S.verbose("Displaying error with css transition",v.transition),a.transition(v.transition+" in",v.duration)):(S.verbose("Displaying error with fallback javascript animation"),a.fadeIn(v.duration)))},errors:function(e){S.debug("Adding form error messages",e),S.set.error(),g.html(v.templates.error(e))}},remove:{rule:function(t,n){var i=e.isArray(n)?n:[n];if(n==r)return S.debug("Removed all rules"),void(b[t].rules=[]);b[t]!=r&&e.isArray(b[t].rules)&&e.each(b[t].rules,function(e,n){-1!==i.indexOf(n.type)&&(S.debug("Removed rule",n.type),b[t].rules.splice(e,1))})},field:function(t){var n=e.isArray(t)?t:[t];e.each(n,function(e,t){S.remove.rule(t)})},rules:function(t,n){e.isArray(t)?e.each(fields,function(e,t){S.remove.rule(t,n)}):S.remove.rule(t,n)},fields:function(e){S.remove.field(e)},prompt:function(t){var n=S.get.field(t).closest(m),i=n.children(x.prompt);n.removeClass(k.error),v.inline&&i.is(":visible")&&(S.verbose("Removing prompt for field",t),v.transition&&e.fn.transition!==r&&A.transition("is supported")?i.transition(v.transition+" out",v.duration,function(){i.remove()}):i.fadeOut(v.duration,function(){i.remove()}))}},set:{success:function(){A.removeClass(k.error).addClass(k.success)},defaults:function(){p.each(function(){var t=e(this),n=t.filter(x.checkbox).length>0?t.is(":checked"):t.val();t.data(y.defaultValue,n)})},error:function(){A.removeClass(k.success).addClass(k.error)},value:function(e,t){var n={};return n[e]=t,S.set.values.call(T,n)},values:function(t){e.isEmptyObject(t)||e.each(t,function(t,n){var r,i=S.get.field(t),a=i.parent(),o=e.isArray(n),l=a.is(x.uiCheckbox),s=a.is(x.uiDropdown),u=i.is(x.radio)&&l;i.length>0&&(o&&l?(S.verbose("Selecting multiple",n,i),a.checkbox("uncheck"),e.each(n,function(e,t){r=i.filter('[value="'+t+'"]'),a=r.parent(),r.length>0&&a.checkbox("check")})):u?(S.verbose("Selecting radio value",n,i),i.filter('[value="'+n+'"]').parent(x.uiCheckbox).checkbox("check")):l?(S.verbose("Setting checkbox value",n,a),!0===n?a.checkbox("check"):a.checkbox("uncheck")):s?(S.verbose("Setting dropdown value",n,a),a.dropdown("set selected",n)):(S.verbose("Setting field value",n,i),i.val(n)))})}},validate:{form:function(e,t){var n=S.get.values();if(O)return!1;if(D=[],S.determine.isValid()){if(S.debug("Form has no validation errors, submitting"),S.set.success(),!0!==t)return v.onSuccess.call(T,e,n)}else if(S.debug("Form has errors"),S.set.error(),v.inline||S.add.errors(D),A.data("moduleApi")!==r&&e.stopImmediatePropagation(),!0!==t)return v.onFailure.call(T,D,n)},field:function(t,n,i){i=i===r||i,"string"==typeof t&&(S.verbose("Validating field",t),n=t,t=b[t]);var a=t.identifier||n,o=S.get.field(a),l=!!t.depends&&S.get.field(t.depends),s=!0,u=[];return t.identifier||(S.debug("Using field name as identifier",a),t.identifier=a),o.prop("disabled")?(S.debug("Field is disabled. Skipping",a),s=!0):t.optional&&S.is.blank(o)?(S.debug("Field is optional and blank. Skipping",a),s=!0):t.depends&&S.is.empty(l)?(S.debug("Field depends on another value that is not present or empty. Skipping",l),s=!0):t.rules!==r&&e.each(t.rules,function(e,n){S.has.field(a)&&!S.validate.rule(t,n)&&(S.debug("Field is invalid",a,n.type),u.push(S.get.prompt(n,t)),s=!1)}),s?(i&&(S.remove.prompt(a,u),v.onValid.call(o)),!0):(i&&(D=D.concat(u),S.add.prompt(a,u),v.onInvalid.call(o,u)),!1)},rule:function(t,n){var i=S.get.field(t.identifier),a=(n.type,i.val()),o=S.get.ancillaryValue(n),l=S.get.ruleName(n),s=v.rules[l];if(e.isFunction(s))return a=a===r||""===a||null===a?"":e.trim(a+""),s.call(i,a,o);S.error(w.noRule,l)}},setting:function(t,n){if(e.isPlainObject(t))e.extend(!0,v,t);else{if(n===r)return v[t];v[t]=n}},internal:function(t,n){if(e.isPlainObject(t))e.extend(!0,S,t);else{if(n===r)return S[t];S[t]=n}},debug:function(){!v.silent&&v.debug&&(v.performance?S.performance.log(arguments):(S.debug=Function.prototype.bind.call(console.info,console,v.name+":"),S.debug.apply(console,arguments)))},verbose:function(){!v.silent&&v.verbose&&v.debug&&(v.performance?S.performance.log(arguments):(S.verbose=Function.prototype.bind.call(console.info,console,v.name+":"),S.verbose.apply(console,arguments)))},error:function(){v.silent||(S.error=Function.prototype.bind.call(console.error,console,v.name+":"),S.error.apply(console,arguments))},performance:{log:function(e){var t,n;v.performance&&(n=(t=(new Date).getTime())-(l||t),l=t,s.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:T,"Execution Time":n})),clearTimeout(S.performance.timer),S.performance.timer=setTimeout(S.performance.display,500)},display:function(){var t=v.name+":",n=0;l=!1,clearTimeout(S.performance.timer),e.each(s,function(e,t){n+=t["Execution Time"]}),t+=" "+n+"ms",o&&(t+=" '"+o+"'"),a.length>1&&(t+=" ("+a.length+")"),(console.group!==r||console.table!==r)&&s.length>0&&(console.groupCollapsed(t),console.table?console.table(s):e.each(s,function(e,t){console.log(t.Name+": "+t["Execution Time"]+"ms")}),console.groupEnd()),s=[]}},invoke:function(t,n,a){var o,l,s,u=F;return n=n||f,a=T||a,"string"==typeof t&&u!==r&&(t=t.split(/[\. ]/),o=t.length-1,e.each(t,function(n,i){var a=n!=o?i+t[n+1].charAt(0).toUpperCase()+t[n+1].slice(1):t;if(e.isPlainObject(u[a])&&n!=o)u=u[a];else{if(u[a]!==r)return l=u[a],!1;if(!e.isPlainObject(u[i])||n==o)return u[i]!==r&&(l=u[i],!1);u=u[i]}})),e.isFunction(l)?s=l.apply(a,n):l!==r&&(s=l),e.isArray(i)?i.push(s):i!==r?i=[i,s]:s!==r&&(i=s),l}}).initialize()}),i!==r?i:this},e.fn.form.settings={name:"Form",namespace:"form",debug:!1,verbose:!1,performance:!0,fields:!1,keyboardShortcuts:!0,on:"submit",inline:!1,delay:200,revalidate:!0,transition:"scale",duration:200,onValid:function(){},onInvalid:function(){},onSuccess:function(){return!0},onFailure:function(){return!1},metadata:{defaultValue:"default",validate:"validate"},regExp:{htmlID:/^[a-zA-Z][\w:.-]*$/g,bracket:/\[(.*)\]/i,decimal:/^\d+\.?\d*$/,email:/^[a-z0-9!#$%&'*+\/=?^_`{|}~.-]+@[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/i,escape:/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,flags:/^\/(.*)\/(.*)?/,integer:/^\-?\d+$/,number:/^\-?\d*(\.\d+)?$/,url:/(https?:\/\/(?:www\.|(?!www))[^\s\.]+\.[^\s]{2,}|www\.[^\s]+\.[^\s]{2,})/i},text:{unspecifiedRule:"Please enter a valid value",unspecifiedField:"This field"},prompt:{empty:"{name} must have a value",checked:"{name} must be checked",email:"{name} must be a valid e-mail",url:"{name} must be a valid url",regExp:"{name} is not formatted correctly",integer:"{name} must be an integer",decimal:"{name} must be a decimal number",number:"{name} must be set to a number",is:'{name} must be "{ruleValue}"',isExactly:'{name} must be exactly "{ruleValue}"',not:'{name} cannot be set to "{ruleValue}"',notExactly:'{name} cannot be set to exactly "{ruleValue}"',contain:'{name} must contain "{ruleValue}"',containExactly:'{name} must contain exactly "{ruleValue}"',doesntContain:'{name} cannot contain "{ruleValue}"',doesntContainExactly:'{name} cannot contain exactly "{ruleValue}"',minLength:"{name} must be at least {ruleValue} characters",length:"{name} must be at least {ruleValue} characters",exactLength:"{name} must be exactly {ruleValue} characters",maxLength:"{name} cannot be longer than {ruleValue} characters",match:"{name} must match {ruleValue} field",different:"{name} must have a different value than {ruleValue} field",creditCard:"{name} must be a valid credit card number",minCount:"{name} must have at least {ruleValue} choices",exactCount:"{name} must have exactly {ruleValue} choices",maxCount:"{name} must have {ruleValue} or less choices"},selector:{checkbox:'input[type="checkbox"], input[type="radio"]',clear:".clear",field:"input, textarea, select",group:".field",input:"input",message:".error.message",prompt:".prompt.label",radio:'input[type="radio"]',reset:'.reset:not([type="reset"])',submit:'.submit:not([type="submit"])',uiCheckbox:".ui.checkbox",uiDropdown:".ui.dropdown"},className:{error:"error",label:"ui prompt label",pressed:"down",success:"success"},error:{identifier:"You must specify a string identifier for each field",method:"The method you called is not defined.",noRule:"There is no rule matching the one you specified",oldSyntax:"Starting in 2.0 forms now only take a single settings object. Validation settings converted to new syntax automatically."},templates:{error:function(t){var n='<ul class="list">';return e.each(t,function(e,t){n+="<li>"+t+"</li>"}),e(n+="</ul>")},prompt:function(t){return e("<div/>").addClass("ui basic red pointing prompt label").html(t[0])}},rules:{empty:function(t){return!(t===r||""===t||e.isArray(t)&&0===t.length)},checked:function(){return e(this).filter(":checked").length>0},email:function(t){return e.fn.form.settings.regExp.email.test(t)},url:function(t){return e.fn.form.settings.regExp.url.test(t)},regExp:function(t,n){if(n instanceof RegExp)return t.match(n);var r,i=n.match(e.fn.form.settings.regExp.flags);return i&&(n=i.length>=2?i[1]:n,r=i.length>=3?i[2]:""),t.match(new RegExp(n,r))},integer:function(t,n){var i,a,o,l=e.fn.form.settings.regExp.integer;return n&&-1===["",".."].indexOf(n)&&(-1==n.indexOf("..")?l.test(n)&&(i=a=n-0):(o=n.split("..",2),l.test(o[0])&&(i=o[0]-0),l.test(o[1])&&(a=o[1]-0))),l.test(t)&&(i===r||t>=i)&&(a===r||t<=a)},decimal:function(t){return e.fn.form.settings.regExp.decimal.test(t)},number:function(t){return e.fn.form.settings.regExp.number.test(t)},is:function(e,t){return t="string"==typeof t?t.toLowerCase():t,(e="string"==typeof e?e.toLowerCase():e)==t},isExactly:function(e,t){return e==t},not:function(e,t){return(e="string"==typeof e?e.toLowerCase():e)!=(t="string"==typeof t?t.toLowerCase():t)},notExactly:function(e,t){return e!=t},contains:function(t,n){return n=n.replace(e.fn.form.settings.regExp.escape,"\\$&"),-1!==t.search(new RegExp(n,"i"))},containsExactly:function(t,n){return n=n.replace(e.fn.form.settings.regExp.escape,"\\$&"),-1!==t.search(new RegExp(n))},doesntContain:function(t,n){return n=n.replace(e.fn.form.settings.regExp.escape,"\\$&"),-1===t.search(new RegExp(n,"i"))},doesntContainExactly:function(t,n){return n=n.replace(e.fn.form.settings.regExp.escape,"\\$&"),-1===t.search(new RegExp(n))},minLength:function(e,t){return e!==r&&e.length>=t},length:function(e,t){return e!==r&&e.length>=t},exactLength:function(e,t){return e!==r&&e.length==t},maxLength:function(e,t){return e!==r&&e.length<=t},match:function(t,n){var i;e(this);return e('[data-validate="'+n+'"]').length>0?i=e('[data-validate="'+n+'"]').val():e("#"+n).length>0?i=e("#"+n).val():e('[name="'+n+'"]').length>0?i=e('[name="'+n+'"]').val():e('[name="'+n+'[]"]').length>0&&(i=e('[name="'+n+'[]"]')),i!==r&&t.toString()==i.toString()},different:function(t,n){var i;e(this);return e('[data-validate="'+n+'"]').length>0?i=e('[data-validate="'+n+'"]').val():e("#"+n).length>0?i=e("#"+n).val():e('[name="'+n+'"]').length>0?i=e('[name="'+n+'"]').val():e('[name="'+n+'[]"]').length>0&&(i=e('[name="'+n+'[]"]')),i!==r&&t.toString()!==i.toString()},creditCard:function(t,n){var r,i,a={visa:{pattern:/^4/,length:[16]},amex:{pattern:/^3[47]/,length:[15]},mastercard:{pattern:/^5[1-5]/,length:[16]},discover:{pattern:/^(6011|622(12[6-9]|1[3-9][0-9]|[2-8][0-9]{2}|9[0-1][0-9]|92[0-5]|64[4-9])|65)/,length:[16]},unionPay:{pattern:/^(62|88)/,length:[16,17,18,19]},jcb:{pattern:/^35(2[89]|[3-8][0-9])/,length:[16]},maestro:{pattern:/^(5018|5020|5038|6304|6759|676[1-3])/,length:[12,13,14,15,16,17,18,19]},dinersClub:{pattern:/^(30[0-5]|^36)/,length:[14]},laser:{pattern:/^(6304|670[69]|6771)/,length:[16,17,18,19]},visaElectron:{pattern:/^(4026|417500|4508|4844|491(3|7))/,length:[16]}},o={},l=!1,s="string"==typeof n&&n.split(",");if("string"==typeof t&&0!==t.length){if(t=t.replace(/[\-]/g,""),s&&(e.each(s,function(n,r){(i=a[r])&&(o={length:-1!==e.inArray(t.length,i.length),pattern:-1!==t.search(i.pattern)}).length&&o.pattern&&(l=!0)}),!l))return!1;if((r={number:-1!==e.inArray(t.length,a.unionPay.length),pattern:-1!==t.search(a.unionPay.pattern)}).number&&r.pattern)return!0;for(var u=t.length,c=0,d=[[0,1,2,3,4,5,6,7,8,9],[0,2,4,6,8,1,3,5,7,9]],f=0;u--;)f+=d[c][parseInt(t.charAt(u),10)],c^=1;return f%10==0&&f>0}},minCount:function(e,t){return 0==t||(1==t?""!==e:e.split(",").length>=t)},exactCount:function(e,t){return 0==t?""===e:1==t?""!==e&&-1===e.search(","):e.split(",").length==t},maxCount:function(e,t){return 0!=t&&(1==t?-1===e.search(","):e.split(",").length<=t)}}}}(jQuery,window,document);