LocalCDN-Firefox-Chrome-Brave/resources/semantic-ui/2.5.0/components/form.min.jsm

1 line
20 KiB
JavaScript
Raw Normal View History

2022-10-07 06:16:13 +02:00
!function(T,e,D,O){"use strict";e=void 0!==e&&e.Math==Math?e:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),T.fn.form=function(x){var k,E=T(this),w=E.selector||"",C=(new Date).getTime(),V=[],R=x,F=arguments[1],S="string"==typeof R,A=[].slice.call(arguments,1);return E.each(function(){var n,s,t,e,d,u,c,f,p,r,l,i,a,m,g,o=T(this),h=this,v=[],b=!1,y={initialize:function(){y.get.settings(),S?(g===O&&y.instantiate(),y.invoke(R)):(g!==O&&g.invoke("destroy"),y.verbose("Initializing form validation",o,d),y.bindEvents(),y.set.defaults(),y.instantiate())},instantiate:function(){y.verbose("Storing instance of module",y),g=y,o.data(a,y)},destroy:function(){y.verbose("Destroying previous module",g),y.removeEvents(),o.removeData(a)},refresh:function(){y.verbose("Refreshing selector cache"),n=o.find(f.field),s=o.find(f.group),t=o.find(f.message),o.find(f.prompt),e=o.find(f.submit),o.find(f.clear),o.find(f.reset)},submit:function(){y.verbose("Submitting form",o),o.submit()},attachEvents:function(e,t){t=t||"submit",T(e).on("click"+m,function(e){y[t](),e.preventDefault()})},bindEvents:function(){y.verbose("Attaching form events"),o.on("submit"+m,y.validate.form).on("blur"+m,f.field,y.event.field.blur).on("click"+m,f.submit,y.submit).on("click"+m,f.reset,y.reset).on("click"+m,f.clear,y.clear),d.keyboardShortcuts&&o.on("keydown"+m,f.field,y.event.field.keydown),n.each(function(){var e=T(this),t=e.prop("type"),n=y.get.changeEvent(t,e);T(this).on(n+m,y.event.field.change)})},clear:function(){n.each(function(){var e=T(this),t=e.parent(),n=e.closest(s),r=n.find(f.prompt),i=e.data(c.defaultValue)||"",a=t.is(f.uiCheckbox),o=t.is(f.uiDropdown);n.hasClass(p.error)&&(y.verbose("Resetting error on field",n),n.removeClass(p.error),r.remove()),o?(y.verbose("Resetting dropdown value",t,i),t.dropdown("clear")):a?e.prop("checked",!1):(y.verbose("Resetting field value",e,i),e.val(""))})},reset:function(){n.each(function(){var e=T(this),t=e.parent(),n=e.closest(s),r=n.find(f.prompt),i=e.data(c.defaultValue),a=t.is(f.uiCheckbox),o=t.is(f.uiDropdown),l=n.hasClass(p.error);i!==O&&(l&&(y.verbose("Resetting error on field",n),n.removeClass(p.error),r.remove()),o?(y.verbose("Resetting dropdown value",t,i),t.dropdown("restore defaults")):a?(y.verbose("Resetting checkbox value",t,i),e.prop("checked",i)):(y.verbose("Resetting field value",e,i),e.val(i)))})},determine:{isValid:function(){var n=!0;return T.each(u,function(e,t){y.validate.field(t,e,!0)||(n=!1)}),n}},is:{bracketedRule:function(e){return e.type&&e.type.match(d.regExp.bracket)},shorthandFields:function(e){var t=e[Object.keys(e)[0]];return y.is.shorthandRules(t)},shorthandRules:function(e){return"string"==typeof e||T.isArray(e)},empty:function(e){return!e||0===e.length||(e.is('input[type="checkbox"]')?!e.is(":checked"):y.is.blank(e))},blank:function(e){return""===T.trim(e.val())},valid:function(e){var n=!0;return e?(y.verbose("Checking if field is valid",e),y.validate.field(u[e],e,!1)):(y.verbose("Checking if form is valid"),T.each(u,function(e,t){y.is.valid(e)||(n=!1)}),n)}},removeEvents:function(){o.off(m),n.off(m),e.off(m),n.off(m)},event:{field:{keydown:function(e){var t=T(this),n=e.which,r=t.is(f.input),i=t.is(f.checkbox),a=0<t.closest(f.uiDropdown).length,o=13;n==27&&(y.verbose("Escape key pressed blurring field"),t.blur()),e.ctrlKey||n!=o||!r||a||i||(b||(t.one("keyup"+m,y.event.field.keyup),y.submit(),y.debug("Enter pressed on input submitting form")),b=!0)},keyup:function(){b=!1},blur:function(e){var t=T(this),n=t.closest(s),r=y.get.validation(t);n.hasClass(p.error)?(y.debug("Revalidating field",t,r),r&&y.validate.field(r)):"blur"==d.on&&r&&y.validate.field(r)},change:function(e){var t=T(this),n=t.closest(s),r=y.get.validation(t);r&&("change"==d.on||n.hasClass(p.error)&&d.revalidate)&&(clearTimeout(y.timer),y.timer=setTimeout(function(){y.debug("Revalidating field",t,y.get.validation(t)),y.validate.field(r)},d.delay))}}},get:{ancillaryValue:function(e){return!(!e.type||!e.value&&!y.is.bracketedRule(e))&&(e.value!==O?e.value:e.type.match(d.regExp.bracket)[1]+"")},ruleName:f