You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
8.7 KiB

3 years ago
/* ========================================================================
* Bootstrap (plugin): validator.js v0.11.8
* ========================================================================
* The MIT License (MIT)
*
* Copyright (c) 2016 Cina Saffary.
* Made by @1000hz in the style of Bootstrap 3 era @fat
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* ======================================================================== */
+function(t){"use strict";function e(e){return e.is('[type="checkbox"]')?e.prop("checked"):e.is('[type="radio"]')?!!t('[name="'+e.attr("name")+'"]:checked').length:e.is("select[multiple]")?(e.val()||[]).length:e.val()}function r(e){return this.each(function(){var r=t(this),i=t.extend({},a.DEFAULTS,r.data(),"object"==typeof e&&e),o=r.data("bs.validator");(o||"destroy"!=e)&&(o||r.data("bs.validator",o=new a(this,i)),"string"==typeof e&&o[e]())})}var a=function(r,i){this.options=i,this.validators=t.extend({},a.VALIDATORS,i.custom),this.$element=t(r),this.$btn=t('button[type="submit"], input[type="submit"]').filter('[form="'+this.$element.attr("id")+'"]').add(this.$element.find('input[type="submit"], button[type="submit"]')),this.update(),this.$element.on("input.bs.validator change.bs.validator focusout.bs.validator",t.proxy(this.onInput,this)),this.$element.on("submit.bs.validator",t.proxy(this.onSubmit,this)),this.$element.on("reset.bs.validator",t.proxy(this.reset,this)),this.$element.find("[data-match]").each(function(){var r=t(this),a=r.data("match");t(a).on("input.bs.validator",function(t){e(r)&&r.trigger("input.bs.validator")})}),this.$inputs.filter(function(){return e(t(this))&&!t(this).closest(".has-error").length}).trigger("focusout"),this.$element.attr("novalidate",!0)};a.VERSION="0.11.8",a.INPUT_SELECTOR=':input:not([type="hidden"], [type="submit"], [type="reset"], button)',a.FOCUS_OFFSET=20,a.DEFAULTS={delay:500,html:!1,disable:!0,focus:!0,custom:{},errors:{match:"Does not match",minlength:"Not long enough"},feedback:{success:"glyphicon-ok",error:"glyphicon-remove"}},a.VALIDATORS={"native":function(t){var e=t[0];return e.checkValidity?!e.checkValidity()&&!e.validity.valid&&(e.validationMessage||"error!"):void 0},match:function(e){var r=e.data("match");return e.val()!==t(r).val()&&a.DEFAULTS.errors.match},minlength:function(t){var e=t.data("minlength");return t.val().length<e&&a.DEFAULTS.errors.minlength}},a.prototype.update=function(){var e=this;return this.$inputs=this.$element.find(a.INPUT_SELECTOR).add(this.$element.find('[data-validate="true"]')).not(this.$element.find('[data-validate="false"]').each(function(){e.clearErrors(t(this))})),this.toggleSubmit(),this},a.prototype.onInput=function(e){var r=this,a=t(e.target),i="focusout"!==e.type;this.$inputs.is(a)&&this.validateInput(a,i).done(function(){r.toggleSubmit()})},a.prototype.validateInput=function(r,a){var i=(e(r),r.data("bs.validator.errors"));r.is('[type="radio"]')&&(r=this.$element.find('input[name="'+r.attr("name")+'"]'));var o=t.Event("validate.bs.validator",{relatedTarget:r[0]});if(this.$element.trigger(o),!o.isDefaultPrevented()){var s=this;return this.runValidators(r).done(function(e){r.data("bs.validator.errors",e),e.length?a?s.defer(r,s.showErrors):s.showErrors(r):s.clearErrors(r),i&&e.toString()===i.toString()||(o=e.length?t.Event("invalid.bs.validator",{relatedTarget:r[0],detail:e}):t.Event("valid.bs.validator",{relatedTarget:r[0],detail:i}),s.$element.trigger(o)),s.toggleSubmit(),s.$element.trigger(t.Event("validated.bs.validator",{relatedTarget:r[0]}))})}},a.prototype.runValidators=function(r){function a(t){return r.data(t+"-error")}function i(){var t=r[0].validity;return t.typeMismatch?r.data("type-error"):t.patternMismatch?r.data("pattern-error"):t.stepMismatch?r.data("step-error"):t.rangeOverflow?r.data("max-error"):t.rangeUnderflow?r.data("min-error"):t.valueMissing?r.data("required-error"):null}function o(){return r.data("error")}function s(t){return a(t)||i()||o()}var n=[],l=t.Deferred();return r.data("bs.validator.deferred")&&r.data("bs.validator.deferred").reject(),r.data("bs.validator.deferred",l),t.each(this.validators,t.proxy(function(t,a){var i=null;(e(r)||r.attr("required"))&&(r.data(t)||"native"==t)&&(i=a.call(this,r))&&(i=s(t)||i,!~n.indexOf(i)&&n.push(i))},this)),!n.length&&e(r)&&r.data("remote")?this.defer(r,function(){var a={};a[r.attr("name")]=e(r),t.get(r.data("remote"),a).fail(function(t,e,r){n.push(s("remote")||r)}).always(function(){l.resolve(n)})}):l.resolve(n),l.promise()},a.prototype.validate=function(){var e=thi