11 lines
No EOL
27 KiB
JavaScript
11 lines
No EOL
27 KiB
JavaScript
/*
|
|
* # Fomantic UI - 2.9.3
|
|
* https://github.com/fomantic/Fomantic-UI
|
|
* https://fomantic-ui.com/
|
|
*
|
|
* Copyright 2023 Contributors
|
|
* Released under the MIT license
|
|
* https://opensource.org/licenses/MIT
|
|
*
|
|
*/
|
|
!function(j,O,L){"use strict";function z(e){return"function"==typeof e&&"number"!=typeof e.nodeType}O=void 0!==O&&O.Math===Math?O:globalThis,j.fn.form=function(C){var w,V=j(this),A=V.selector||"",D=Date.now(),R=[],S=C,F="string"==typeof S,T=[].slice.call(arguments,1);return V.each(function(){var i,d,e,t,f,s,m,p,g,n,u,r,a,l,c,o=j(this),h=this,v=[],b=!1,y=!1,x=!1,k=["clean","clean"],E={initialize:function(){E.get.settings(),F?(void 0===c&&E.instantiate(),E.invoke(S)):(void 0!==c&&(c.invoke("destroy"),E.refresh()),E.verbose("Initializing form validation",o,f),E.bindEvents(),E.set.defaults(),f.autoCheckRequired&&E.set.autoCheck(),E.instantiate())},instantiate:function(){E.verbose("Storing instance of module",E),c=E,o.data(a,E)},destroy:function(){E.verbose("Destroying previous module",c),E.removeEvents(),o.removeData(a)},refresh:function(){E.verbose("Refreshing selector cache"),i=o.find(p.field),d=o.find(p.group),e=o.find(p.message),o.find(p.prompt),t=o.find(p.submit),o.find(p.clear),o.find(p.reset)},refreshEvents:function(){E.removeEvents(),E.bindEvents()},submit:function(){E.verbose("Submitting form",o),y=!0,o.trigger("submit")},attachEvents:function(e,t){t=t||"submit",j(e).on("click"+l,function(e){E[t](),e.preventDefault()})},bindEvents:function(){E.verbose("Attaching form events"),o.on("submit"+l,E.validate.form).on("blur"+l,p.field,E.event.field.blur).on("click"+l,p.submit,E.submit).on("click"+l,p.reset,E.reset).on("click"+l,p.clear,E.clear),f.keyboardShortcuts&&o.on("keydown"+l,p.field,E.event.field.keydown),i.each(function(e,t){var t=j(t),n=t.prop("type"),n=E.get.changeEvent(n,t);t.on(n+l,E.event.field.change)}),f.preventLeaving&&j(O).on("beforeunload"+l,E.event.beforeUnload),i.on("change click keyup keydown blur",function(e){E.determine.isDirty()}),o.on("dirty"+l,function(e){f.onDirty.call()}),o.on("clean"+l,function(e){f.onClean.call()})},clear:function(){i.each(function(e,t){var t=j(t),n=t.parent(),r=t.closest(d),i=r.find(p.prompt),a=t.closest(p.uiCalendar),o=t.data(m.defaultValue)||"",l=t.is(p.checkbox),s=n.is(p.uiDropdown)&&E.can.useElement("dropdown"),u=0<a.length&&E.can.useElement("calendar");r.hasClass(g.error)&&(E.verbose("Resetting error on field",r),r.removeClass(g.error),i.remove()),s?(E.verbose("Resetting dropdown value",n,o),n.dropdown("clear",!0)):l?t.prop("checked",!1):u?a.calendar("clear"):(E.verbose("Resetting field value",t,o),t.val(""))}),E.remove.states()},reset:function(){i.each(function(e,t){var t=j(t),n=t.parent(),r=t.closest(d),i=t.closest(p.uiCalendar),a=r.find(p.prompt),o=t.data(m.defaultValue),l=t.is(p.checkbox),s=n.is(p.uiDropdown)&&E.can.useElement("dropdown"),u=0<i.length&&E.can.useElement("calendar"),c=r.hasClass(g.error);void 0!==o&&(c&&(E.verbose("Resetting error on field",r),r.removeClass(g.error),a.remove()),s?(E.verbose("Resetting dropdown value",n,o),n.dropdown("restore defaults",!0)):l?(E.verbose("Resetting checkbox value",t,o),t.prop("checked",o)):u?i.calendar("set date",o):(E.verbose("Resetting field value",t,o),t.val(o)))}),E.remove.states()},determine:{isValid:function(){var n=!0;return j.each(s,function(e,t){E.validate.field(t,e,!0)||(n=!1)}),n},isDirty:function(e){var r=!1;i.each(function(e,t){var t=j(t),n=0<t.filter(p.checkbox).length?E.is.checkboxDirty(t):E.is.fieldDirty(t);t.data(f.metadata.isDirty,n),r=r||n}),r?E.set.dirty():E.set.clean()}},is:{bracketedRule:function(e){return e.type&&e.type.match(f.regExp.bracket)},shorthandRules:function(e){return"string"==typeof e||Array.isArray(e)},empty:function(e){return!e||0===e.length||(e.is(p.checkbox)?!e.is(":checked"):E.is.blank(e))},blank:function(e){return""===String(e.val()).trim()},valid:function(e,n){var r=!0;return e?(E.verbose("Checking if field is valid",e),E.validate.field(s[e],e,!!n)):(E.verbose("Checking if form is valid"),j.each(s,function(e,t){E.is.valid(e,n)||(r=!1)}),r)},dirty:function(){return x},clean:function(){return!x},fieldDirty:function(e){var t=e.data(m.defaultValue),e=(null==t?t="":Array.isArray(t)&&(t=t.toString()),e.val()),n=(null==e?e="":Array.isArray(e)&&(e=e.toString()),/^(true|false)$/i);return n.test(t)&&n.test(e)?!new RegExp("^"+t+"$","i").test(e):e!==t},checkboxDirty:function(e){return e.data(m.defaultValue)!==e.is(":checked")},justDirty:function(){return"dirty"===k[0]},justClean:function(){return"clean"===k[0]}},removeEvents:function(){o.off(l),i.off(l),t.off(l)},event:{field:{keydown:function(e){var t=j(this),n=e.which,r=t.is(p.input),i=t.is(p.checkbox),a=0<t.closest(p.uiDropdown).length,o=13;n===27&&(E.verbose("Escape key pressed blurring field"),t[0].blur()),e.ctrlKey||n!==o||!r||a||i||(b||(t.one("keyup"+l,E.event.field.keyup),E.submit(),E.debug("Enter pressed on input submitting form"),e.preventDefault()),b=!0)},keyup:function(){b=!1},blur:function(e){var t=j(this),n=t.closest(d),r=E.get.validation(t);r&&("blur"===f.on||n.hasClass(g.error)&&f.revalidate)&&(E.debug("Revalidating field",t,r),E.validate.field(r),f.inline||E.validate.form(!1,!0))},change:function(e){var t=j(this),n=t.closest(d),r=E.get.validation(t);r&&("change"===f.on||n.hasClass(g.error)&&f.revalidate)&&(clearTimeout(E.timer),E.timer=setTimeout(function(){E.debug("Revalidating field",t,r),E.validate.field(r),f.inline||E.validate.form(!1,!0)},f.delay))}},beforeUnload:function(e){if(E.is.dirty()&&!y)return(e=e||O.event)&&(e.returnValue=f.text.leavingMessage),f.text.leavingMessage}},get:{ancillaryValue:function(e){return!(!e.type||!e.value&&!E.is.bracketedRule(e))&&(void 0!==e.value?e.value:e.type.match(f.regExp.bracket)[1]+"")},ruleName:function(e){return E.is.bracketedRule(e)?e.type.replace(e.type.match(f.regExp.bracket)[0],""):e.type},changeEvent:function(e,t){return"checkbox"===e||"radio"===e||"hidden"===e||t.is("select")?"change":E.get.inputEvent()},inputEvent:function(){return void 0!==L.createElement("input").oninput?"input":void 0!==L.createElement("input").onpropertychange?"propertychange":"keyup"},fieldsFromShorthand:function(e){var r={};return j.each(e,function(n,e){Array.isArray(e)||"object"!=typeof e?("string"==typeof e&&(e=[e]),r[n]={rules:[]},j.each(e,function(e,t){r[n].rules.push({type:t})})):r[n]=e}),r},prompt:function(e,t){var n,r=E.get.ruleName(e),i=E.get.ancillaryValue(e),a=E.get.field(t.identifier),o=a.val(),o=z(e.prompt)?e.prompt(o):e.prompt||f.prompt[r]||f.text.unspecifiedRule,l=-1!==o.search("{value}"),s=-1!==o.search("{name}");return i&&0<=["integer","decimal","number","size"].indexOf(r)&&0<=i.indexOf("..")&&(n=i.split("..",2),e.prompt||"size"===r||(o+=(""===n[0]?f.prompt.maxValue.replace(/{ruleValue}/g,"{max}"):""===n[1]?f.prompt.minValue.replace(/{ruleValue}/g,"{min}"):f.prompt.range).replace(/{name}/g," "+f.text.and)),o=(o=o.replace(/{min}/g,n[0])).replace(/{max}/g,n[1])),i&&0<=["match","different"].indexOf(r)&&(o=o.replace(/{ruleValue}/g,E.get.fieldLabel(i,!0))),l&&(o=o.replace(/{value}/g,a.val())),o=(o=(o=s?o.replace(/{name}/g,E.get.fieldLabel(a)):o).replace(/{identifier}/g,t.identifier)).replace(/{ruleValue}/g,i),e.prompt||E.verbose("Using default validation prompt for type",o,r),o},settings:function(){j.isPlainObject(C)?(C.fields&&(C.fields=E.get.fieldsFromShorthand(C.fields)),f=j.extend(!0,{},j.fn.form.settings,C),s=j.extend(!0,{},j.fn.form.settings.defaults,f.fields),E.verbose("Extending settings",s,f)):(f=j.extend(!0,{},j.fn.form.settings),s=j.extend(!0,{},j.fn.form.settings.defaults),E.verbose("Using default form validation",s,f)),r=f.namespace,m=f.metadata,p=f.selector,g=f.className,n=f.regExp,u=f.error,a="module-"+r,l="."+r,((c=o.data(a))||E).refresh()},field:function(e,t){var n;return E.verbose("Finding field with identifier",e),e=E.escape.string(e),0<(n=i.filter("#"+e)).length||0<(n=i.filter('[name="'+e+'"]')).length||0<(n=i.filter('[name="'+e+'[]"]')).length||0<(n=i.filter("[data-"+m.validate+'="'+e+'"]')).length?n:(E.error(u.noField.replace("{identifier}",e)),t?j():j("<input/>"))},fields:function(e,n){var r=j();return j.each(e,function(e,t){r=r.add(E.get.field(t,n))}),r},fieldLabel:function(e,t){var n="string"==typeof e?E.get.field(e):e,r=n.closest(p.group).find("label").eq(0);return 1===r.length?r.text():n.prop("placeholder")||(t?e:f.text.unspecifiedField)},validation:function(r){var i,a;return s&&(j.each(s,function(e,n){a=n.identifier||e,j.each(E.get.field(a),function(e,t){if(t==r[0])return n.identifier=a,i=n,!1})}),i)||!1},value:function(e,t){var n=[];return n.push(e),e=E.get.values.call(h,n,t),0<(n=Object.keys(e)).length?e[n[0]]:void 0},values:function(e,t){var e=Array.isArray(e)&&0<e.length?E.get.fields(e,t):i,d={};return e.each(function(e,t){var t=j(t),n=t.closest(p.uiCalendar),r=t.prop("name"),i=t.val(),a=t.is(p.checkbox),o=t.is(p.radio),l=-1!==r.indexOf("[]"),s=0<n.length&&E.can.useElement("calendar"),t=!!a&&t.is(":checked");if(r)if(l)r=r.replace("[]",""),d[r]||(d[r]=[]),a?t?d[r].push(i||!0):d[r].push(!1):d[r].push(i);else if(o)void 0!==d[r]&&!1!==d[r]||(d[r]=!!t&&(i||!0));else if(a)d[r]=!!t&&(i||!0);else if(s){var u=n.calendar("get date");if(null!==u)switch(f.dateHandling){case"date":d[r]=u;break;case"input":d[r]=n.calendar("get input date");break;case"formatter":var c=n.calendar("setting","type");switch(c){case"date":d[r]=f.formatter.date(u);break;case"datetime":d[r]=f.formatter.datetime(u);break;case"time":d[r]=f.formatter.time(u);break;case"month":d[r]=f.formatter.month(u);break;case"year":d[r]=f.formatter.year(u);break;default:E.debug("Wrong calendar mode",n,c),d[r]=""}}else d[r]=""}else d[r]=i}),d},dirtyFields:function(){return i.filter(function(e,t){return j(t).data(m.isDirty)})}},has:{field:function(e){return E.verbose("Checking for existence of a field with identifier",e),0<E.get.field(e,!0).length}},can:{useElement:function(e){return void 0!==j.fn[e]||(E.error(u.noElement.replace("{element}",e)),!1)}},escape:{string:function(e){return(e=String(e)).replace(n.escape,"\\$&")}},checkErrors:function(e,t){return e&&0!==e.length?!t&&"string"==typeof e?[e]:e:(t||E.error(f.error.noErrorMessage),!1)},add:{rule:function(e,t){E.add.field(e,t)},field:function(n,e){void 0!==s[n]&&void 0!==s[n].rules||(s[n]={rules:[]});var r={rules:[]};E.is.shorthandRules(e)?(e=Array.isArray(e)?e:[e],j.each(e,function(e,t){r.rules.push({type:t})})):r.rules=e.rules,j.each(r.rules,function(e,t){0===j.grep(s[n].rules,function(e){return e.type===t.type}).length&&s[n].rules.push(t)}),E.debug("Adding rules",r.rules,s),E.refreshEvents()},fields:function(e){s=j.extend(!0,{},s,E.get.fieldsFromShorthand(e)),E.refreshEvents()},prompt:function(e,t,n){var r,i,a;!1!==(t=E.checkErrors(t))&&(a=0<(i=(r=E.get.field(e).closest(d)).children(p.prompt)).length,E.verbose("Adding field error state",e),n||r.addClass(g.error),f.inline)&&(a||(i=j("<div/>").addClass(g.label)).appendTo(r),i.html(f.templates.prompt(t)),a?E.verbose("Inline errors are disabled, no inline error added",e):f.transition&&E.can.useElement("transition")?(E.verbose("Displaying error with css transition",f.transition),i.transition(f.transition+" in",f.duration)):(E.verbose("Displaying error with fallback javascript animation"),i.fadeIn(f.duration)))},errors:function(t){var r,i;!1!==(t=E.checkErrors(t))&&(E.debug("Adding form error messages",t),E.set.error(),r=[],j.isPlainObject(t)?j.each(Object.keys(t),function(e,n){!1!==E.checkErrors(t[n],!0)&&(f.inline?E.add.prompt(n,t[n]):!1!==(i=E.checkErrors(t[n]))&&j.each(i,function(e,t){r.push(f.prompt.addErrors.replace(/{name}/g,E.get.fieldLabel(n)).replace(/{error}/g,t))}))}):r=t,0<r.length)&&e.html(f.templates.error(r))}},remove:{errors:function(){E.debug("Removing form error messages"),e.empty()},states:function(){o.removeClass(g.error).removeClass(g.success),f.inline||E.remove.errors(),E.determine.isDirty()},rule:function(n,e){var r=Array.isArray(e)?e:[e];void 0!==s[n]&&Array.isArray(s[n].rules)&&(void 0===e?(E.debug("Removed all rules"),E.has.field(n)?s[n].rules=[]:delete s[n]):j.each(s[n].rules,function(e,t){t&&-1!==r.indexOf(t.type)&&(E.debug("Removed rule",t.type),s[n].rules.splice(e,1))}))},field:function(e){e=Array.isArray(e)?e:[e];j.each(e,function(e,t){E.remove.rule(t)}),E.refreshEvents()},rules:function(e,n){Array.isArray(e)?j.each(e,function(e,t){E.remove.rule(t,n)}):E.remove.rule(e,n)},fields:function(e){E.remove.field(e)},prompt:function(e){var t=E.get.field(e).closest(d),n=t.children(p.prompt);t.removeClass(g.error),f.inline&&n.is(":visible")&&(E.verbose("Removing prompt for field",e),f.transition&&E.can.useElement("transition")?n.transition(f.transition+" out",f.duration,function(){n.remove()}):n.fadeOut(f.duration,function(){n.remove()}))}},set:{success:function(){o.removeClass(g.error).addClass(g.success)},defaults:function(){i.each(function(e,t){var t=j(t),n=t.parent(),r=0<t.filter(p.checkbox).length,i=(n.is(p.uiDropdown)||t.is(p.uiDropdown))&&E.can.useElement("dropdown"),a=t.closest(p.uiCalendar),o=0<a.length&&E.can.useElement("calendar"),r=r?t.is(":checked"):t.val();i?(n.is(p.uiDropdown)?n:t).dropdown("save defaults"):o&&a.calendar("refresh"),t.data(m.defaultValue,r),t.data(m.isDirty,!1)})},error:function(){o.removeClass(g.success).addClass(g.error)},value:function(e,t){var n={};return n[e]=t,E.set.values.call(h,n)},values:function(e){j.isEmptyObject(e)||j.each(e,function(e,t){var n,r=E.get.field(e),i=r.parent(),e=r.closest(p.uiCalendar),a=Array.isArray(t),o=i.is(p.uiCheckbox)&&E.can.useElement("checkbox"),l=i.is(p.uiDropdown)&&E.can.useElement("dropdown"),s=r.is(p.radio)&&o,u=0<e.length&&E.can.useElement("calendar");0<r.length&&(a&&o?(E.verbose("Selecting multiple",t,r),i.checkbox("uncheck"),j.each(t,function(e,t){n=r.filter('[value="'+t+'"]'),i=n.parent(),0<n.length&&i.checkbox("check")})):s?(E.verbose("Selecting radio value",t,r),r.filter('[value="'+t+'"]').parent(p.uiCheckbox).checkbox("check")):o?(E.verbose("Setting checkbox value",t,i),!0===t||1===t||"on"===t?i.checkbox("check"):i.checkbox("uncheck"),"string"==typeof t&&r.val(t)):l?(E.verbose("Setting dropdown value",t,i),i.dropdown("set selected",t)):u?e.calendar("set date",t):(E.verbose("Setting field value",t,r),r.val(t)))})},dirty:function(){E.verbose("Setting state dirty"),x=!0,k[0]=k[1],k[1]="dirty",E.is.justClean()&&o.trigger("dirty")},clean:function(){E.verbose("Setting state clean"),x=!1,k[0]=k[1],k[1]="clean",E.is.justDirty()&&o.trigger("clean")},asClean:function(){E.set.defaults(),E.set.clean()},asDirty:function(){E.set.defaults(),E.set.dirty()},autoCheck:function(){E.debug("Enabling auto check on required fields"),s&&j.each(s,function(e){E.has.field(e)||(E.verbose("Field not found, removing from validation",e),E.remove.field(e))}),i.each(function(e,t){var t=j(t),n=t.closest(d),r=0<t.filter(p.checkbox).length,i=t.prop("required")||n.hasClass(g.required)||n.parent().hasClass(g.required),n=t.is(":disabled")||n.hasClass(g.disabled)||n.parent().hasClass(g.disabled),a=E.get.validation(t),o=!!a&&0!==j.grep(a.rules,function(e){return"empty"===e.type}),a=a.identifier||t.attr("id")||t.attr("name")||t.data(m.validate);!i||n||o||void 0===a||(r?(E.verbose("Adding 'checked' rule on field",a),E.add.rule(a,"checked")):(E.verbose("Adding 'empty' rule on field",a),E.add.rule(a,"empty")))})},optional:function(n,r){r=!1!==r,j.each(s,function(e,t){n!==e&&n!==t.identifier||(t.optional=r)})}},validate:{form:function(e,t){var n,r=E.get.values();if(b)return!1;if(v=[],E.determine.isValid()){if(E.debug("Form has no validation errors, submitting"),E.set.success(),f.inline||E.remove.errors(),!0!==t)return f.onSuccess.call(h,e,r)}else if(E.debug("Form has errors"),y=!1,E.set.error(),f.inline||E.add.errors(v),e&&void 0!==o.data("moduleApi")&&e.stopImmediatePropagation(),f.errorFocus&&!0!==t&&(e=!0,"string"==typeof f.errorFocus?(e=(n=j(L).find(f.errorFocus)).is("[tabindex]"))||n.attr("tabindex",-1):n=d.filter("."+g.error).first().find(p.field),n.trigger("focus"),e||n.removeAttr("tabindex")),!0!==t)return f.onFailure.call(h,v,r)},field:function(r,e,i){if(i=void 0===i||i,"string"==typeof r&&(E.verbose("Validating field",r),r=s[e=r]),r){var a=r.identifier||e,t=E.get.field(a),n=!!r.depends&&E.get.field(r.depends),o=!0,l=[];if(r.identifier||(E.debug("Using field name as identifier",a),r.identifier=a),0===t.filter(":not(:disabled)").length?E.debug("Field is disabled. Skipping",a):r.optional&&E.is.blank(t)?E.debug("Field is optional and blank. Skipping",a):r.depends&&E.is.empty(n)?E.debug("Field depends on another value that is not present or empty. Skipping",n):void 0!==r.rules&&(i&&t.closest(d).removeClass(g.error),j.each(r.rules,function(e,t){var n;E.has.field(a)&&0<(n=E.validate.rule(r,t,!0)||[]).length&&(E.debug("Field is invalid",a,t.type),l.push(E.get.prompt(t,r)),o=!1,i)&&j(n).closest(d).addClass(g.error)})),!o)return i&&(v=v.concat(l),E.add.prompt(a,l,!0),f.onInvalid.call(t,l)),!1;i&&(E.remove.prompt(a,l),f.onValid.call(t))}else E.debug("Unable to find field validation. Skipping",e);return!0},rule:function(e,n,t){function r(e){var t=void 0===(t=(s?j(e).filter(":checked"):j(e)).val())||""===t||null===t?"":f.shouldTrim&&!1!==n.shouldTrim||n.shouldTrim?String(t+"").trim():String(t+"");return o.call(e,t,i,E)}var e=E.get.field(e.identifier),i=E.get.ancillaryValue(n),a=E.get.ruleName(n),o=f.rules[a],l=[],s=e.is(p.checkbox);if(z(o))return s?r(e)||(l=e):j.each(e,function(e,t){r(t)||l.push(t)}),t?l:0===l.length;E.error(u.noRule,a)}},setting:function(e,t){if(j.isPlainObject(e))j.extend(!0,f,e);else{if(void 0===t)return f[e];f[e]=t}},internal:function(e,t){if(j.isPlainObject(e))j.extend(!0,E,e);else{if(void 0===t)return E[e];E[e]=t}},debug:function(){!f.silent&&f.debug&&(f.performance?E.performance.log(arguments):(E.debug=Function.prototype.bind.call(console.info,console,f.name+":"),E.debug.apply(console,arguments)))},verbose:function(){!f.silent&&f.verbose&&f.debug&&(f.performance?E.performance.log(arguments):(E.verbose=Function.prototype.bind.call(console.info,console,f.name+":"),E.verbose.apply(console,arguments)))},error:function(){f.silent||(E.error=Function.prototype.bind.call(console.error,console,f.name+":"),E.error.apply(console,arguments))},performance:{log:function(e){var t,n;f.performance&&(n=(t=Date.now())-(D||t),D=t,R.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:h,"Execution Time":n})),clearTimeout(E.performance.timer),E.performance.timer=setTimeout(E.performance.display,500)},display:function(){var e=f.name+":",n=0;D=!1,clearTimeout(E.performance.timer),j.each(R,function(e,t){n+=t["Execution Time"]}),e+=" "+n+"ms",A&&(e+=" '"+A+"'"),1<V.length&&(e+=" ("+V.length+")"),0<R.length&&(console.groupCollapsed(e),console.table?console.table(R):j.each(R,function(e,t){console.log(t.Name+": "+t["Execution Time"]+"ms")}),console.groupEnd()),R=[]}},invoke:function(r,e,t){var i,a,n,o=c;return e=e||T,t=t||h,"string"==typeof r&&void 0!==o&&(r=r.split(/[ .]/),i=r.length-1,j.each(r,function(e,t){var n=e!==i?t+r[e+1].charAt(0).toUpperCase()+r[e+1].slice(1):r;if(j.isPlainObject(o[n])&&e!==i)o=o[n];else{if(void 0!==o[n])return a=o[n],!1;{if(!j.isPlainObject(o[t])||e===i)return void 0!==o[t]?a=o[t]:E.error(u.method,r),!1;o=o[t]}}})),z(a)?n=a.apply(t,e):void 0!==a&&(n=a),Array.isArray(w)?w.push(n):void 0!==w?w=[w,n]:void 0!==n&&(w=n),a}};E.initialize()}),void 0!==w?w:this},j.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,shouldTrim:!0,transition:"scale",duration:200,autoCheckRequired:!1,preventLeaving:!1,errorFocus:!0,dateHandling:"date",onValid:function(){},onInvalid:function(){},onSuccess:function(){return!0},onFailure:function(){return!1},onDirty:function(){},onClean:function(){},metadata:{defaultValue:"default",validate:"validate",isDirty:"isDirty"},regExp:{htmlID:/^[A-Za-z][\w.:-]*$/g,bracket:/\[(.*)]/i,decimal:/^\d+\.?\d*$/,email:/^[\w!#$%&'*+./=?^`{|}~-]+@[\da-z]([\da-z-]*[\da-z])?(\.[\da-z]([\da-z-]*[\da-z])?)*$/i,escape:/[$()*+,./:=?@[\\\]^{|}-]/g,flags:/^\/(.*)\/(.*)?/,integer:/^-?\d+$/,number:/^-?\d*(\.\d+)?$/,url:/(https?:\/\/(?:www\.|(?!www))[^\s.]+\.\S{2,}|www\.\S+\.\S{2,})/i},text:{and:"and",unspecifiedRule:"Please enter a valid value",unspecifiedField:"This field",leavingMessage:"There are unsaved changes on this page which will be discarded if you continue."},prompt:{range:"{name} must be in a range from {min} to {max}",maxValue:"{name} must have a maximum value of {ruleValue}",minValue:"{name} must have a minimum value of {ruleValue}",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",exactLength:"{name} must be exactly {ruleValue} characters",maxLength:"{name} cannot be longer than {ruleValue} characters",size:"{name} must have a length between {min} and {max} 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",addErrors:"{name}: {error}"},selector:{checkbox:'input[type="checkbox"], input[type="radio"]',clear:".clear",field:'input:not(.search):not([type="file"]):not([type="reset"]):not([type="button"]):not([type="submit"]), textarea, select',group:".field",input:'input:not([type="file"])',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",uiCalendar:".ui.calendar"},className:{error:"error",label:"ui basic red pointing prompt label",pressed:"down",success:"success",required:"required",disabled:"disabled"},error:{method:"The method you called is not defined.",noRule:"There is no rule matching the one you specified",noField:"Field identifier {identifier} not found",noElement:"This module requires ui {element}",noErrorMessage:"No error message provided"},templates:{error:function(e){var n='<ul class="list">';return j.each(e,function(e,t){n+="<li>"+t+"</li>"}),n+="</ul>"},prompt:function(e){var n;return 1===e.length?e[0]:(n='<ul class="ui list">',j.each(e,function(e,t){n+="<li>"+t+"</li>"}),n+="</ul>")}},formatter:{date:function(e){return Intl.DateTimeFormat("en-GB").format(e)},datetime:function(e){return Intl.DateTimeFormat("en-GB",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}).format(e)},time:function(e){return Intl.DateTimeFormat("en-GB",{hour:"2-digit",minute:"2-digit",second:"2-digit"}).format(e)},month:function(e){return Intl.DateTimeFormat("en-GB",{month:"2-digit",year:"numeric"}).format(e)},year:function(e){return Intl.DateTimeFormat("en-GB",{year:"numeric"}).format(e)}},rules:{empty:function(e){return!(void 0===e||""===e||Array.isArray(e)&&0===e.length)},checked:function(){return 0<j(this).filter(":checked").length},email:function(e){return j.fn.form.settings.regExp.email.test(e)},url:function(e){return j.fn.form.settings.regExp.url.test(e)},regExp:function(e,t){var n,r;return t instanceof RegExp?e.match(t):((n=t.match(j.fn.form.settings.regExp.flags))&&(t=2<=n.length?n[1]:t,r=3<=n.length?n[2]:""),e.match(new RegExp(t,r)))},minValue:function(e,t){return j.fn.form.settings.rules.range(e,t+"..","number")},maxValue:function(e,t){return j.fn.form.settings.rules.range(e,".."+t,"number")},integer:function(e,t){return j.fn.form.settings.rules.range(e,t,"integer")},range:function(e,t,n,r){var i,a;return(n="string"==typeof n?j.fn.form.settings.regExp[n]:n)instanceof RegExp||(n=j.fn.form.settings.regExp.integer),t&&-1===["",".."].indexOf(t)&&(-1===t.indexOf("..")?n.test(t)&&(a=i=+t):(t=t.split("..",2),n.test(t[0])&&(i=+t[0]),n.test(t[1])&&(a=+t[1]))),r&&(e=e.length),n.test(e)&&(void 0===i||i<=e)&&(void 0===a||e<=a)},decimal:function(e,t){return j.fn.form.settings.rules.range(e,t,"decimal")},number:function(e,t){return j.fn.form.settings.rules.range(e,t,"number")},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(e,t){return t=t.replace(j.fn.form.settings.regExp.escape,"\\$&"),-1!==e.search(new RegExp(t,"i"))},containsExactly:function(e,t){return t=t.replace(j.fn.form.settings.regExp.escape,"\\$&"),-1!==e.search(new RegExp(t))},doesntContain:function(e,t){return t=t.replace(j.fn.form.settings.regExp.escape,"\\$&"),-1===e.search(new RegExp(t,"i"))},doesntContainExactly:function(e,t){return t=t.replace(j.fn.form.settings.regExp.escape,"\\$&"),-1===e.search(new RegExp(t))},minLength:function(e,t){return j.fn.form.settings.rules.range(e,t+"..","integer",!0)},exactLength:function(e,t){return j.fn.form.settings.rules.range(e,t+".."+t,"integer",!0)},maxLength:function(e,t){return j.fn.form.settings.rules.range(e,".."+t,"integer",!0)},size:function(e,t){return j.fn.form.settings.rules.range(e,t,"integer",!0)},match:function(e,t,n){n=n.get.value(t,!0);return void 0!==n&&e.toString()===n.toString()},different:function(e,t,n){n=n.get.value(t,!0);return void 0!==n&&e.toString()!==n.toString()},creditCard:function(n,e){var r,i={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]\d|[2-8]\d{2}|9[01]\d|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]\d)/,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]}},a=!1,e="string"==typeof e&&e.split(",");if("string"==typeof n&&0!==n.length){if(n=n.replace(/[\s-]/g,""),e&&(j.each(e,function(e,t){(r=i[t])&&0<(r={length:-1!==j.inArray(n.length,r.length),pattern:-1!==n.search(r.pattern)}).length&&r.pattern&&(a=!0)}),!a))return!1;if((e={number:-1!==j.inArray(n.length,i.unionPay.length),pattern:-1!==n.search(i.unionPay.pattern)}).number&&e.pattern)return!0;for(var t=n.length,o=0,l=[[0,1,2,3,4,5,6,7,8,9],[0,2,4,6,8,1,3,5,7,9]],s=0;t--;)s+=l[o][parseInt(n.charAt(t),10)],o^=1;return s%10==0&&0<s}},minCount:function(e,t){return 0===(t=Number(t))||(1===t?""!==e:e.split(",").length>=t)},exactCount:function(e,t){return 0===(t=Number(t))?""===e:1===t?""!==e&&-1===e.search(","):e.split(",").length===t},maxCount:function(e,t){return 0!==(t=Number(t))&&(1===t?-1===e.search(","):e.split(",").length<=t)}}}}(jQuery,window,document); |