|
|
/* * # Semantic UI - 1.7.2 * https://github.com/Semantic-Org/Semantic-UI
* http://www.semantic-ui.com/
* * Copyright 2014 Contributors * Released under the MIT license * http://opensource.org/licenses/MIT
* */ !function(e,t,n,i){e.fn.form=function(t,r){var o,a=e(this),s=e.extend(!0,{},e.fn.form.settings,r),l=e.extend({},e.fn.form.settings.defaults,t),c=s.namespace,u=s.metadata,d=s.selector,f=s.className,m=(s.error,"."+c),p="module-"+c,g=a.selector||"",v=(new Date).getTime(),h=[],b=arguments[0],y="string"==typeof b,k=[].slice.call(arguments,1);return a.each(function(){var t,r=e(this),c=e(this).find(d.field),w=e(this).find(d.group),E=e(this).find(d.message),x=(e(this).find(d.prompt),e(this).find(d.submit)),C=[],F=this,z=r.data(p);t={initialize:function(){t.verbose("Initializing form validation",r,l,s),t.bindEvents(),t.instantiate()},instantiate:function(){t.verbose("Storing instance of module",t),z=t,r.data(p,t)},destroy:function(){t.verbose("Destroying previous module",z),t.removeEvents(),r.removeData(p)},refresh:function(){t.verbose("Refreshing selector cache"),c=r.find(d.field)},submit:function(){t.verbose("Submitting form",r),r.submit()},attachEvents:function(n,i){i=i||"submit",e(n).on("click",function(e){t[i](),e.preventDefault()})},bindEvents:function(){s.keyboardShortcuts&&c.on("keydown"+m,t.event.field.keydown),r.on("submit"+m,t.validate.form),c.on("blur"+m,t.event.field.blur),t.attachEvents(x,"submit"),c.each(function(){var n=e(this).prop("type"),i=t.get.changeEvent(n);e(this).on(i+m,t.event.field.change)})},removeEvents:function(){r.off(m),c.off(m),x.off(m),c.off(m)},event:{field:{keydown:function(n){var i=e(this),r=n.which,o={enter:13,escape:27};r==o.escape&&(t.verbose("Escape key pressed blurring field"),i.blur()),!n.ctrlKey&&r==o.enter&&i.is(d.input)&&i.not(d.checkbox).length>0&&(t.debug("Enter key pressed, submitting form"),x.addClass(f.down),i.one("keyup"+m,t.event.field.keyup))},keyup:function(){t.verbose("Doing keyboard shortcut form submit"),x.removeClass(f.down),t.submit()},blur:function(){var n=e(this),i=n.closest(w);i.hasClass(f.error)?(t.debug("Revalidating field",n,t.get.validation(n)),t.validate.field(t.get.validation(n))):("blur"==s.on||"change"==s.on)&&t.validate.field(t.get.validation(n))},change:function(){var n=e(this),i=n.closest(w);("change"==s.on||i.hasClass(f.error)&&s.revalidate)&&(clearTimeout(t.timer),t.timer=setTimeout(function(){t.debug("Revalidating field",n,t.get.validation(n)),t.validate.field(t.get.validation(n))},s.delay))}}},get:{changeEvent:function(e){return"checkbox"==e||"radio"==e||"hidden"==e?"change":n.createElement("input").oninput!==i?"input":n.createElement("input").onpropertychange!==i?"propertychange":"keyup"},field:function(n){return t.verbose("Finding field with identifier",n),c.filter("#"+n).length>0?c.filter("#"+n):c.filter('[name="'+n+'"]').length>0?c.filter('[name="'+n+'"]'):c.filter("[data-"+u.validate+'="'+n+'"]').length>0?c.filter("[data-"+u.validate+'="'+n+'"]'):e("<input/>")},validation:function(n){var i;return e.each(l,function(e,r){t.get.field(r.identifier).get(0)==n.get(0)&&(i=r)}),i||!1}},has:{field:function(e){return t.verbose("Checking for existence of a field with identifier",e),c.filter("#"+e).length>0?!0:c.filter('[name="'+e+'"]').length>0?!0:c.filter("[data-"+u.validate+'="'+e+'"]').length>0?!0:!1}},add:{prompt:function(n,o){var a=t.get.field(n),l=a.closest(w),c=l.children(d.prompt),u=0!==c.length;o="string"==typeof o?[o]:o,t.verbose("Adding field error state",n),l.addClass(f.error),s.inline&&(u||(c=s.templates.prompt(o),c.appendTo(l)),c.html(o[0]),u?t.verbose("Inline errors are disabled, no inline error added",n):s.transition&&e.fn.transition!==i&&r.transition("is supported")?(t.verbose("Displaying error with css transition",s.transition),c.transition(s.transition+" in",s.duration)):(t.verbose("Displaying error with fallback javascript animation"),c.fadeIn(s.duration)))},errors:function(e){t.debug("Adding form error messages",e),E.html(s.templates.error(e))}},remove:{prompt:function(n){var o=t.get.field(n.identifier),a=o.closest(w),l=a.children(d.prompt);a.removeClass(f.error),s.inline&&l.is(":visible")&&(t.verbose("Removing prompt for field",n),s.transition&&e.fn.transition!==i&&r.transition("is supported")?l.transition(s.transition+" out",s.duration,
|