text: (function(){var a;a=angular.element,angular.module("validator.directive",["validator.provider"]).directive("validator",["$injector",function(b){return{restrict:"A",require:"ngModel",link:function(c,d,e,f){var g,h,i,j,k,l,m,n,o,p;return h=b.get("$validator"),g=b.get("$parse"),j=g(e.ngModel),o=[],p=function(a,g){var h,i,k,l,m,n,p;if(null==g&&(g={}),p=0,h=0,l=function(){var a,h,i;if(++p>=o.length){for(f.$setValidity(e.ngModel,!0),a=0,h=o.length;a<h;a++)i=o[a],i.success(j(c),c,d,e,b);"function"==typeof g.success&&g.success()}},0===o.length)return l();for(i=function(a){return a.validator(j(c),c,d,e,{success:function(){return l()},error:function(){var i,k;if(a.enableError&&1==++h&&(f.$setValidity(e.ngModel,!1),a.error(j(c),c,d,e,b)),1===("function"==typeof g.error?g.error():void 0)){try{d[0].scrollIntoViewIfNeeded()}catch(a){}return d[0].select?"function"==typeof(i=d[0]).select?i.select():void 0:"function"==typeof(k=d[0]).focus?k.focus():void 0}}})},k=0,m=o.length;k<m;k++){switch(n=o[k],a){case"blur":if("blur"!==n.invoke)continue;n.enableError=!0;break;case"watch":if("watch"!==n.invoke&&!n.enableError){l();continue}break;case"broadcast":n.enableError=!0}i(n)}},m=function(){var a;return a=h.getRule("required"),null==a&&(a=h.convertRule("required",{validator:/^.+$/,invoke:"watch"})),o.push(a)},n=function(a){var f,g,h,i,k;for(k=[],g=f=0,h=o.length;f<h;g=f+=1)(null!=(i=o[g])?i.name:void 0)===a&&(o[g].success(j(c),c,d,e,b),o.splice(g,1),k.push(g--));return k},e.$observe("validator",function(a){var f,g,i,j,l,n,p;if(o.length=0,(k.validatorRequired||k.required)&&m(),i=a.match(/^\/(.*)\/$/))return n=h.convertRule("dynamic",{validator:RegExp(i[1]),invoke:e.validatorInvoke,error:e.validatorError}),void o.push(n);if(i=a.match(/^\[(.+)\]$/)){for(p=i[1].split(","),l=[],f=0,g=p.length;f<g;f++)j=p[f],n=h.getRule(j.replace(/^\s+|\s+$/g,"")),"function"==typeof n.init&&n.init(c,d,e,b),n?l.push(o.push(n)):l.push(void 0);return l}}),e.$observe("validatorError",function(a){var b,c;if(b=e.validator.match(/^\/(.*)\/$/))return n("dynamic"),c=h.convertRule("dynamic",{validator:RegExp(b[1]),invoke:e.validatorInvoke,error:a}),o.push(c)}),k={validatorRequired:!1,required:!1},e.$observe("validatorRequired",function(a){return a&&"false"!==a?(m(),k.validatorRequired=!0):k.validatorRequired?(n("required"),k.validatorRequired=!1):void 0}),e.$observe("required",function(a){return a&&"false"!==a?(m(),k.required=!0):k.required?(n("required"),k.required=!1):void 0}),i=function(a,b){var d,f,h,i;return!b||(e.validatorGroup===b||(a.targetScope===c?0===e.ngModel.indexOf(b):(d=function(a,b){var c,e;for(c in a)switch(typeof(e=a[c])){case"string":if("$$hashKey"===c&&e===b)return!0;break;case"object":if(d(e,b))return!0}return!1},f=e.ngModel.indexOf("."),h=f>=0?e.ngModel.substr(0,f):e.ngModel,null!=(i=g(h)(c))&&d(g(b)(a.targetScope),i.$$hashKey))))},c.$on(h.broadcastChannel.prepare,function(a,b){if(i(a,b.model))return b.accept()}),c.$on(h.broadcastChannel.start,function(a,b){if(i(a,b.model))return p("broadcast",{success:b.success,error:b.error})}),c.$on(h.broadcastChannel.reset,function(a,g){var h,k,l;if(i(a,g.model)){for(h=0,k=o.length;h<k;h++)l=o[h],l.success(j(c),c,d,e,b),"watch"!==l.invoke&&(l.enableError=!1);return f.$setValidity(e.ngModel,!0)}}),c.$watch(e.ngModel,function(a,b){if(a!==b)return p("watch",{oldValue:b})}),l=function(){return c.$root.$$phase?p("blur"):c.$apply(function(){return p("blur")})},a(d).bind("blur",l),c.$on("$destroy",function(){return a(d).unbind("blur",l)})}}}])}).call(this),function(){angular.module("validator",["validator.directive"])}.call(this),function(){var a;a=angular.element,angular.module("validator.provider",[]).provider("$validator",function(){var b,c,d;b=null,c=null,d=null,this.rules={},this.broadcastChannel={prepare:"$validatePrepare",start:"$validateStart",reset:"$validateReset"},this.setupProviders=function(a){return b=a,c=b.get("$q"),d=b.get("$timeout")},this.convertError=function(b){var c;return"function"==typeof b?b:(c=b.constructor===String?b:"",function(b,d,e,f){var g,h,i,j,k,l;if(k=e.closest(".form-group"),k.length){for(k.addClass("has-error"),l=k.find("label"),h=0,j=l.length;h<j;h++)i=l[h],a(i).hasClass("error")&&a(i).remove();return g=a("<label class='control-label error'>"+c+"</label>"),f.id&&g.attr("for",f.id),e.parent().hasClass("input-group")?e.parent().parent().append(g):e.parent().append(g)}})},this.convertSuccess=function(b){return"function"==typeof b?b:function(b,c,d){var e,f,g,h,i,j;for(h=d.parent(),j=[];0!==h.length;){if(h.hasClass("has-error")){for(h.removeClass("has-error"),i=h.find("label"),e=0,g=i.length;e<g;e++)f=i[e],a(f).hasClass("error")&&a(f).remove();break}j.push(h=h.parent())}return j}},this.convertValidator=function(a){var d,e,f;return f=function(){},a.constructor===RegExp?(e=a,f=function(a,b,c,d,f){return null==a&&(a=""),e.test(a)?"function"==typeof f.success?f.success():void 0:"function"==typeof f.error?f.error():void 0}):"function"==typeof a&&(d=a,f=function(a,e,f,g,h){return c.all([d(a,e,f,g,b)]).then(function(a){return a&&a.length>0&&a[0]?"function"==typeof h.success?h.success():void 0:"function"==typeof h.error?h.error():void 0},function(){return"function"==typeof h.error?h.error():void 0})}),f},this.convertRule=function(a){return function(b,c){var d,e,f;return null==c&&(c={}),f={name:b,enableError:"watch"===c.invoke,invoke:c.invoke,init:c.init,validator:null!=(d=c.validator)?d:function(){return!0},error:null!=(e=c.error)?e:"",success:c.success},f.error=a.convertError(f.error),f.success=a.convertSuccess(f.success),f.validator=a.convertValidator(f.validator),f}}(this),this.register=function(a,b){return null==b&&(b={}),this.rules[a]=this.convertRule(a,b)},this.getRule=function(a){return this.rules[a]?angular.copy(this.rules[a]):null},this.validate=function(a){return function(e,f){var g,h,i,j,k;return i=c.defer(),k=i.promise,h={total:0,success:0,error:0},j={promises:{success:[],error:[],then:[]},accept:function(){return h.total++},validatedSuccess:function(){var a,b,c,d,e,f;if(++h.success===h.total){for(e=j.promises.success,a=0,c=e.length;a<c;a++)(0,e[a])();for(f=j.promises.then,b=0,d=f.length;b<d;b++)(0,f[b])()}return h.success},validatedError:function(){var a,b,c,d,e,f;if(0==h.error++){for(e=j.promises.error,a=0,c=e.length;a<c;a++)(0,e[a])();for(f=j.promises.then,b=0,d=f.length;b<d;b++)(0,f[b])()}return h.error}},k.success=function(a){return j.promises.success.push(a),k},k.error=function(a){return j.promises.error.push(a),k},k.then=function(a){return j.promises.then.push(a),k},g={model:f,accept:j.accept,success:j.validatedSuccess,error:j.validatedError},e.$broadcast(a.broadcastChannel.prepare,g),d(function(){var a,c,d,f;{if(0!==h.total)return a=b.get("$validator"),e.$broadcast(a.broadcastChannel.start,g);for(f=j.promises.success,c=0,d=f.length;c<d;c++)(0,f[c])()}}),k}}(this),this.reset=function(a){return function(b,c){return b.$broadcast(a.broadcastChannel.reset,{model:c})}}(this),this.get=function(a){return this.setupProviders(a),{rules:this.rules,broadcastChannel:this.broadcastChannel,register:this.register,convertRule:this.convertRule,getRule:this.getRule,validate:this.validate,reset:this.reset}},this.get.$inject=["$injector"],this.$get=this.get})}.call(this);