From 839982699dfd2a0db214caa0d2e146b918bfecc8 Mon Sep 17 00:00:00 2001 From: Kelp Date: Thu, 29 Sep 2016 16:48:37 +0800 Subject: [PATCH] fixed the select element don't have `.select()` --- dist/angular-validator.js | 6 +++++- dist/angular-validator.min.js | 2 +- src/directive.coffee | 5 ++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/dist/angular-validator.js b/dist/angular-validator.js index 6527574..28df102 100644 --- a/dist/angular-validator.js +++ b/dist/angular-validator.js @@ -60,7 +60,11 @@ try { element[0].scrollIntoViewIfNeeded(); } catch (_error) {} - return element[0].select(); + if (element[0].select) { + return element[0].select(); + } else { + return element[0].focus(); + } } } }); diff --git a/dist/angular-validator.min.js b/dist/angular-validator.min.js index eb30ebf..50a85e4 100644 --- a/dist/angular-validator.min.js +++ b/dist/angular-validator.min.js @@ -1 +1 @@ -(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={}),l=0,h=0,i=function(){var a,h,i;if(++l>=o.length){for(f.$setValidity(e.ngModel,!0),h=0,i=o.length;i>h;h++)a=o[h],a.success(j(c),c,d,e,b);"function"==typeof g.success&&g.success()}},0===o.length)return i();for(m=function(a){return a.validator(j(c),c,d,e,{success:function(){return i()},error:function(){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(i){}return d[0].select()}}})},n=0,p=o.length;p>n;n++){switch(k=o[n],a){case"blur":if("blur"!==k.invoke)continue;k.enableError=!0;break;case"watch":if("watch"!==k.invoke&&!k.enableError){i();continue}break;case"broadcast":k.enableError=!0}m(k)}},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=[],f=g=0,h=o.length;h>g;f=g+=1)(null!=(i=o[f])?i.name:void 0)===a&&(o[f].success(j(c),c,d,e,b),o.splice(f,1),k.push(f--));return k},e.$observe("validator",function(a){var f,g,i,j,l,n,p;if(o.length=0,(k.validatorRequired||k.required)&&m(),f=a.match(/^\/(.*)\/$/))return i=h.convertRule("dynamic",{validator:RegExp(f[1]),invoke:e.validatorInvoke,error:e.validatorError}),void o.push(i);if(f=a.match(/^\[(.+)\]$/)){for(j=f[1].split(","),p=[],l=0,n=j.length;n>l;l++)g=j[l],i=h.getRule(g.replace(/^\s+|\s+$/g,"")),"function"==typeof i.init&&i.init(c,d,e,b),p.push(i?o.push(i):void 0);return p}}),e.$observe("validatorError",function(a){var b,c;return b=e.validator.match(/^\/(.*)\/$/),b?(n("dynamic"),c=h.convertRule("dynamic",{validator:RegExp(b[1]),invoke:e.validatorInvoke,error:a}),o.push(c)):void 0}),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?!0:a.targetScope===c?0===e.ngModel.indexOf(b):(d=function(a,b){var c,e;for(c in a)switch(e=a[c],typeof e){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,i=g(h)(c),d(g(b)(a.targetScope),i.$$hashKey)):!0},c.$on(h.broadcastChannel.prepare,function(a,b){return i(a,b.model)?b.accept():void 0}),c.$on(h.broadcastChannel.start,function(a,b){return i(a,b.model)?p("broadcast",{success:b.success,error:b.error}):void 0}),c.$on(h.broadcastChannel.reset,function(a,g){var h,k,l;if(i(a,g.model)){for(k=0,l=o.length;l>k;k++)h=o[k],h.success(j(c),c,d,e,b),"watch"!==h.invoke&&(h.enableError=!1);return f.$setValidity(e.ngModel,!0)}}),c.$watch(e.ngModel,function(a,b){return a!==b?p("watch",{oldValue:b}):void 0}),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,m;for(i=a(e).parent(),m=[];0!==i.length;){if(i.hasClass("form-group")){for(i.addClass("has-error"),l=i.find("label"),j=0,k=l.length;k>j;j++)h=l[j],a(h).hasClass("error")&&a(h).remove();g=a(""),f.id&&g.attr("for",f.id),a(e).parent().hasClass("input-group")?a(e).parent().parent().append(g):a(e).parent().append(g);break}m.push(i=i.parent())}return m})},this.convertSuccess=function(b){return"function"==typeof b?b:function(b,c,d){var e,f,g,h,i,j;for(f=a(d).parent(),j=[];0!==f.length;){if(f.hasClass("has-error")){for(f.removeClass("has-error"),i=f.find("label"),g=0,h=i.length;h>g;g++)e=i[g],a(e).hasClass("error")&&a(e).remove();break}j.push(f=f.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={}),d={name:b,enableError:"watch"===c.invoke,invoke:c.invoke,init:c.init,validator:null!=(e=c.validator)?e:function(){return!0},error:null!=(f=c.error)?f:"",success:c.success},d.error=a.convertError(d.error),d.success=a.convertSuccess(d.success),d.validator=a.convertValidator(d.validator),d}}(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,g;if(++h.success===h.total){for(f=j.promises.success,b=0,d=f.length;d>b;b++)(a=f[b])();for(g=j.promises.then,c=0,e=g.length;e>c;c++)(a=g[c])()}return h.success},validatedError:function(){var a,b,c,d,e,f,g;if(0===h.error++){for(f=j.promises.error,b=0,d=f.length;d>b;b++)(a=f[b])();for(g=j.promises.then,c=0,e=g.length;e>c;c++)(a=g[c])()}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,i;{if(0!==h.total)return a=b.get("$validator"),e.$broadcast(a.broadcastChannel.start,g);for(i=j.promises.success,d=0,f=i.length;f>d;d++)(c=i[d])()}}),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); \ No newline at end of file +(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={}),l=0,h=0,i=function(){var a,h,i;if(++l>=o.length){for(f.$setValidity(e.ngModel,!0),h=0,i=o.length;h=0?e.ngModel.substr(0,f):e.ngModel,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(k=0,l=o.length;k"+c+""),f.id&&g.attr("for",f.id),a(e).parent().hasClass("input-group")?a(e).parent().parent().append(g):a(e).parent().append(g);break}m.push(i=i.parent())}return m})},this.convertSuccess=function(b){return"function"==typeof b?b:function(b,c,d){var e,f,g,h,i,j;for(f=a(d).parent(),j=[];0!==f.length;){if(f.hasClass("has-error")){for(f.removeClass("has-error"),i=f.find("label"),g=0,h=i.length;g0&&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={}),d={name:b,enableError:"watch"===c.invoke,invoke:c.invoke,init:c.init,validator:null!=(e=c.validator)?e:function(){return!0},error:null!=(f=c.error)?f:"",success:c.success},d.error=a.convertError(d.error),d.success=a.convertSuccess(d.success),d.validator=a.convertValidator(d.validator),d}}(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,g;if(++h.success===h.total){for(f=j.promises.success,b=0,d=f.length;b