angular-ui-mask
Advanced tools
Comparing version 1.4.2 to 1.4.3
@@ -8,7 +8,7 @@ { | ||
"dependencies": { | ||
"angular": ">= 1.0.5" | ||
"angular": ">= 1.3.6" | ||
}, | ||
"devDependencies": { | ||
"angular-mocks": ">=1.0.5" | ||
"angular-mocks": ">=1.3.6" | ||
} | ||
} |
/*! | ||
* angular-ui-mask | ||
* https://github.com/angular-ui/ui-mask | ||
* Version: 1.4.2 - 2015-08-10T07:56:13.924Z | ||
* Version: 1.4.3 - 2015-08-26T07:29:49.279Z | ||
* License: MIT | ||
@@ -172,3 +172,2 @@ */ | ||
isValid = validateValue(value); | ||
var viewValue = isValid && value.length ? valueMasked : ''; | ||
if (iAttrs.maxlength) { // Double maxlength to allow pasting new val at end of mask | ||
@@ -180,5 +179,9 @@ iElement.attr('maxlength', maskCaretMap[maskCaretMap.length - 1] * 2); | ||
} | ||
iElement.val(viewValue); | ||
controller.$viewValue = viewValue; | ||
controller.$setValidity('mask', isValid); | ||
var viewValue = controller.$modelValue; | ||
var idx = controller.$formatters.length; | ||
while(idx--) { | ||
viewValue = controller.$formatters[idx](viewValue); | ||
} | ||
controller.$viewValue = viewValue || ''; | ||
controller.$render(); | ||
// Not using $setViewValue so we don't clobber the model value and dirty the form | ||
@@ -185,0 +188,0 @@ // without any kind of user interaction. |
/*! | ||
* angular-ui-mask | ||
* https://github.com/angular-ui/ui-mask | ||
* Version: 1.4.2 - 2015-08-10T07:56:13.924Z | ||
* Version: 1.4.3 - 2015-08-26T07:29:49.279Z | ||
* License: MIT | ||
*/ | ||
!function(){"use strict";angular.module("ui.mask",[]).value("uiMaskConfig",{maskDefinitions:{9:/\d/,A:/[a-zA-Z]/,"*":/[a-zA-Z0-9]/},clearOnBlur:!0,eventsToHandle:["input","keyup","click","focus"]}).directive("uiMask",["uiMaskConfig","$parse",function(e,n){function t(e){return e===document.activeElement&&(!document.hasFocus||document.hasFocus())&&!!(e.type||e.href||~e.tabIndex)}return{priority:100,require:"ngModel",restrict:"A",compile:function(){var i=e;return function(e,r,u,a){function o(e){return angular.isDefined(e)?(y(e),F?(h(),d(),!0):f()):f()}function l(e){e&&(R=e,F&&r.val(m(v(r.val()))))}function s(e){return F?(j=v(e||""),z=p(j),a.$setValidity("mask",z),z&&j.length?m(j):void 0):e}function c(e){return F?(j=v(e||""),z=p(j),a.$viewValue=j.length?m(j):"",a.$setValidity("mask",z),""===j&&u.required&&a.$setValidity("required",!a.$error.required),z?j:void 0):e}function f(){return F=!1,g(),angular.isDefined(K)?r.attr("placeholder",K):r.removeAttr("placeholder"),angular.isDefined(N)?r.attr("maxlength",N):r.removeAttr("maxlength"),r.val(a.$modelValue),a.$viewValue=a.$modelValue,!1}function h(){j=Z=v(a.$modelValue||""),q=H=m(j),z=p(j);var e=z&&j.length?q:"";u.maxlength&&r.attr("maxlength",2*E[E.length-1]),K||r.attr("placeholder",R),r.val(e),a.$viewValue=e,a.$setValidity("mask",z)}function d(){I||(r.bind("blur",k),r.bind("mousedown mouseup",x),r.bind(W.eventsToHandle.join(" "),M),r.bind("paste",w),I=!0)}function g(){I&&(r.unbind("blur",k),r.unbind("mousedown",x),r.unbind("mouseup",x),r.unbind("input",M),r.unbind("keyup",M),r.unbind("click",M),r.unbind("focus",M),r.unbind("paste",w),I=!1)}function p(e){return e.length?e.length>=T:!0}function v(e){var n="",t=_.slice();return e=e.toString(),angular.forEach(P,function(n){e=e.replace(n,"")}),angular.forEach(e.split(""),function(e){t.length&&t[0].test(e)&&(n+=e,t.shift())}),n}function m(e){var n="",t=E.slice();return angular.forEach(R.split(""),function(i,r){e.length&&r===t[0]?(n+=e.charAt(0)||"_",e=e.substr(1),t.shift()):n+=i}),n}function b(e){var n=angular.isDefined(u.uiMaskPlaceholder)?u.uiMaskPlaceholder:u.placeholder;return"undefined"!=typeof n&&n[e]?n[e]:"_"}function $(){return R.replace(/[_]+/g,"_").replace(/([^_]+)([a-zA-Z0-9])([^_])/g,"$1$2_$3").split("_")}function y(e){var n=0;if(E=[],_=[],R="","string"==typeof e){T=0;var t=!1,i=0,r=e.split("");angular.forEach(r,function(e,r){W.maskDefinitions[e]?(E.push(n),R+=b(r-i),_.push(W.maskDefinitions[e]),n++,t||T++):"?"===e?(t=!0,i++):(R+=e,n++)})}E.push(E.slice().pop()+1),P=$(),F=E.length>1?!0:!1}function k(){W.clearOnBlur&&(B=0,C=0,z&&0!==j.length||(q="",r.val(""),e.$apply(function(){a.$setViewValue("")})))}function x(e){"mousedown"===e.type?r.bind("mouseout",V):r.unbind("mouseout",V)}function V(){C=D(this),r.unbind("mouseout",V)}function w(){S(this,r.val().length)}function M(e){e=e||{};var n=e.which,t=e.type;if(16!==n&&91!==n){var i,u=r.val(),o=H,l=v(u),s=Z,c=A(this)||0,f=B||0,h=c-f,d=E[0],g=E[l.length]||E.slice().shift(),p=C||0,b=D(this)>0,$=p>0,y=u.length>o.length||p&&u.length>o.length-p,k=u.length<o.length||p&&u.length===o.length-p,x=n>=37&&40>=n&&e.shiftKey,V=37===n,w=8===n||"keyup"!==t&&k&&-1===h,M=46===n||"keyup"!==t&&k&&0===h&&!$,_=(V||w||"click"===t)&&c>d;if(C=D(this),!x&&(!b||"click"!==t&&"keyup"!==t)){if("input"===t&&k&&!$&&l===s){for(;w&&c>d&&!O(c);)c--;for(;M&&g>c&&-1===E.indexOf(c);)c++;var R=E.indexOf(c);l=l.substring(0,R)+l.substring(R+1)}for(i=m(l),H=i,Z=l,r.val(i),a.$setViewValue(l),y&&d>=c&&(c=d+1),_&&c--,c=c>g?g:d>c?d:c;!O(c)&&c>d&&g>c;)c+=_?-1:1;(_&&g>c||y&&!O(f))&&c++,B=c,S(this,c)}}}function O(e){return E.indexOf(e)>-1}function A(e){if(!e)return 0;if(void 0!==e.selectionStart)return e.selectionStart;if(document.selection&&t(r[0])){e.focus();var n=document.selection.createRange();return n.moveStart("character",e.value?-e.value.length:0),n.text.length}return 0}function S(e,n){if(!e)return 0;if(0!==e.offsetWidth&&0!==e.offsetHeight)if(e.setSelectionRange)t(r[0])&&(e.focus(),e.setSelectionRange(n,n));else if(e.createTextRange){var i=e.createTextRange();i.collapse(!0),i.moveEnd("character",n),i.moveStart("character",n),i.select()}}function D(e){return e?void 0!==e.selectionStart?e.selectionEnd-e.selectionStart:document.selection?document.selection.createRange().text.length:0:0}var E,_,R,P,T,j,q,z,H,Z,B,C,F=!1,I=!1,K=u.placeholder,N=u.maxlength,W={};u.uiOptions?(W=e.$eval("["+u.uiOptions+"]"),angular.isObject(W[0])&&(W=function(e,n){for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&(void 0===n[t]?n[t]=angular.copy(e[t]):angular.extend(n[t],e[t]));return n}(i,W[0]))):W=i,u.$observe("uiMask",o),angular.isDefined(u.uiMaskPlaceholder)?u.$observe("uiMaskPlaceholder",l):u.$observe("placeholder",l);var G=!1;u.$observe("modelViewValue",function(e){"true"===e&&(G=!0)}),e.$watch(u.ngModel,function(t){if(G&&t){var i=n(u.ngModel);i.assign(e,a.$viewValue)}}),a.$formatters.push(s),a.$parsers.push(c),r.bind("mousedown mouseup",x),Array.prototype.indexOf||(Array.prototype.indexOf=function(e){if(null===this)throw new TypeError;var n=Object(this),t=n.length>>>0;if(0===t)return-1;var i=0;if(arguments.length>1&&(i=Number(arguments[1]),i!==i?i=0:0!==i&&1/0!==i&&i!==-1/0&&(i=(i>0||-1)*Math.floor(Math.abs(i)))),i>=t)return-1;for(var r=i>=0?i:Math.max(t-Math.abs(i),0);t>r;r++)if(r in n&&n[r]===e)return r;return-1})}}}}])}(); | ||
!function(){"use strict";angular.module("ui.mask",[]).value("uiMaskConfig",{maskDefinitions:{9:/\d/,A:/[a-zA-Z]/,"*":/[a-zA-Z0-9]/},clearOnBlur:!0,eventsToHandle:["input","keyup","click","focus"]}).directive("uiMask",["uiMaskConfig","$parse",function(e,n){function t(e){return e===document.activeElement&&(!document.hasFocus||document.hasFocus())&&!!(e.type||e.href||~e.tabIndex)}return{priority:100,require:"ngModel",restrict:"A",compile:function(){var r=e;return function(e,i,u,a){function o(e){return angular.isDefined(e)?(y(e),F?(d(),h(),!0):f()):f()}function l(e){e&&(R=e,F&&i.val(m(v(i.val()))))}function s(e){return F?(j=v(e||""),z=p(j),a.$setValidity("mask",z),z&&j.length?m(j):void 0):e}function c(e){return F?(j=v(e||""),z=p(j),a.$viewValue=j.length?m(j):"",a.$setValidity("mask",z),""===j&&u.required&&a.$setValidity("required",!a.$error.required),z?j:void 0):e}function f(){return F=!1,g(),angular.isDefined(K)?i.attr("placeholder",K):i.removeAttr("placeholder"),angular.isDefined(N)?i.attr("maxlength",N):i.removeAttr("maxlength"),i.val(a.$modelValue),a.$viewValue=a.$modelValue,!1}function d(){j=Z=v(a.$modelValue||""),q=H=m(j),z=p(j),u.maxlength&&i.attr("maxlength",2*E[E.length-1]),K||i.attr("placeholder",R);for(var e=a.$modelValue,n=a.$formatters.length;n--;)e=a.$formatters[n](e);a.$viewValue=e||"",a.$render()}function h(){I||(i.bind("blur",k),i.bind("mousedown mouseup",x),i.bind(W.eventsToHandle.join(" "),M),i.bind("paste",w),I=!0)}function g(){I&&(i.unbind("blur",k),i.unbind("mousedown",x),i.unbind("mouseup",x),i.unbind("input",M),i.unbind("keyup",M),i.unbind("click",M),i.unbind("focus",M),i.unbind("paste",w),I=!1)}function p(e){return e.length?e.length>=T:!0}function v(e){var n="",t=_.slice();return e=e.toString(),angular.forEach(P,function(n){e=e.replace(n,"")}),angular.forEach(e.split(""),function(e){t.length&&t[0].test(e)&&(n+=e,t.shift())}),n}function m(e){var n="",t=E.slice();return angular.forEach(R.split(""),function(r,i){e.length&&i===t[0]?(n+=e.charAt(0)||"_",e=e.substr(1),t.shift()):n+=r}),n}function b(e){var n=angular.isDefined(u.uiMaskPlaceholder)?u.uiMaskPlaceholder:u.placeholder;return"undefined"!=typeof n&&n[e]?n[e]:"_"}function $(){return R.replace(/[_]+/g,"_").replace(/([^_]+)([a-zA-Z0-9])([^_])/g,"$1$2_$3").split("_")}function y(e){var n=0;if(E=[],_=[],R="","string"==typeof e){T=0;var t=!1,r=0,i=e.split("");angular.forEach(i,function(e,i){W.maskDefinitions[e]?(E.push(n),R+=b(i-r),_.push(W.maskDefinitions[e]),n++,t||T++):"?"===e?(t=!0,r++):(R+=e,n++)})}E.push(E.slice().pop()+1),P=$(),F=E.length>1?!0:!1}function k(){W.clearOnBlur&&(B=0,C=0,z&&0!==j.length||(q="",i.val(""),e.$apply(function(){a.$setViewValue("")})))}function x(e){"mousedown"===e.type?i.bind("mouseout",V):i.unbind("mouseout",V)}function V(){C=D(this),i.unbind("mouseout",V)}function w(){S(this,i.val().length)}function M(e){e=e||{};var n=e.which,t=e.type;if(16!==n&&91!==n){var r,u=i.val(),o=H,l=v(u),s=Z,c=A(this)||0,f=B||0,d=c-f,h=E[0],g=E[l.length]||E.slice().shift(),p=C||0,b=D(this)>0,$=p>0,y=u.length>o.length||p&&u.length>o.length-p,k=u.length<o.length||p&&u.length===o.length-p,x=n>=37&&40>=n&&e.shiftKey,V=37===n,w=8===n||"keyup"!==t&&k&&-1===d,M=46===n||"keyup"!==t&&k&&0===d&&!$,_=(V||w||"click"===t)&&c>h;if(C=D(this),!x&&(!b||"click"!==t&&"keyup"!==t)){if("input"===t&&k&&!$&&l===s){for(;w&&c>h&&!O(c);)c--;for(;M&&g>c&&-1===E.indexOf(c);)c++;var R=E.indexOf(c);l=l.substring(0,R)+l.substring(R+1)}for(r=m(l),H=r,Z=l,i.val(r),a.$setViewValue(l),y&&h>=c&&(c=h+1),_&&c--,c=c>g?g:h>c?h:c;!O(c)&&c>h&&g>c;)c+=_?-1:1;(_&&g>c||y&&!O(f))&&c++,B=c,S(this,c)}}}function O(e){return E.indexOf(e)>-1}function A(e){if(!e)return 0;if(void 0!==e.selectionStart)return e.selectionStart;if(document.selection&&t(i[0])){e.focus();var n=document.selection.createRange();return n.moveStart("character",e.value?-e.value.length:0),n.text.length}return 0}function S(e,n){if(!e)return 0;if(0!==e.offsetWidth&&0!==e.offsetHeight)if(e.setSelectionRange)t(i[0])&&(e.focus(),e.setSelectionRange(n,n));else if(e.createTextRange){var r=e.createTextRange();r.collapse(!0),r.moveEnd("character",n),r.moveStart("character",n),r.select()}}function D(e){return e?void 0!==e.selectionStart?e.selectionEnd-e.selectionStart:document.selection?document.selection.createRange().text.length:0:0}var E,_,R,P,T,j,q,z,H,Z,B,C,F=!1,I=!1,K=u.placeholder,N=u.maxlength,W={};u.uiOptions?(W=e.$eval("["+u.uiOptions+"]"),angular.isObject(W[0])&&(W=function(e,n){for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&(void 0===n[t]?n[t]=angular.copy(e[t]):angular.extend(n[t],e[t]));return n}(r,W[0]))):W=r,u.$observe("uiMask",o),angular.isDefined(u.uiMaskPlaceholder)?u.$observe("uiMaskPlaceholder",l):u.$observe("placeholder",l);var G=!1;u.$observe("modelViewValue",function(e){"true"===e&&(G=!0)}),e.$watch(u.ngModel,function(t){if(G&&t){var r=n(u.ngModel);r.assign(e,a.$viewValue)}}),a.$formatters.push(s),a.$parsers.push(c),i.bind("mousedown mouseup",x),Array.prototype.indexOf||(Array.prototype.indexOf=function(e){if(null===this)throw new TypeError;var n=Object(this),t=n.length>>>0;if(0===t)return-1;var r=0;if(arguments.length>1&&(r=Number(arguments[1]),r!==r?r=0:0!==r&&r!==1/0&&r!==-(1/0)&&(r=(r>0||-1)*Math.floor(Math.abs(r)))),r>=t)return-1;for(var i=r>=0?r:Math.max(t-Math.abs(r),0);t>i;i++)if(i in n&&n[i]===e)return i;return-1})}}}}])}(); |
var fs = require('fs'); | ||
var gulp = require('gulp'); | ||
var karma = require('karma').server; | ||
var Server = require('karma').Server; | ||
var concat = require('gulp-concat'); | ||
@@ -61,3 +61,3 @@ var jshint = require('gulp-jshint'); | ||
.pipe(uglify({preserveComments: 'some'})) | ||
.pipe(rename({ext:'.min.js'})) | ||
.pipe(rename({extname:'.min.js'})) | ||
.pipe(gulp.dest('dist')); | ||
@@ -68,7 +68,9 @@ | ||
gulp.task('karma', ['build'], function() { | ||
karma.start({configFile : __dirname +'/karma.conf.js', singleRun: true}); | ||
var server = new Server({configFile : __dirname +'/karma.conf.js', singleRun: true}); | ||
server.start(); | ||
}); | ||
gulp.task('karma-watch', ['build'], function() { | ||
karma.start({configFile : __dirname +'/karma.conf.js', singleRun: false}); | ||
var server = new Server({configFile : __dirname +'/karma.conf.js', singleRun: false}); | ||
server.start(); | ||
}); | ||
@@ -75,0 +77,0 @@ |
{ | ||
"name": "angular-ui-mask", | ||
"version": "1.4.2", | ||
"version": "1.4.3", | ||
"author": "https://github.com/angular-ui/ui-mask/graphs/contributors", | ||
@@ -9,21 +9,22 @@ "license": "MIT", | ||
"devDependencies": { | ||
"bower": "~1.3", | ||
"del": "~0.1.1", | ||
"event-stream": "~3.1.0", | ||
"gulp": "~3.8.5", | ||
"gulp-concat": "~2.1.7", | ||
"gulp-header": "~1.0.2", | ||
"del": "~1.2.0", | ||
"event-stream": "~3.3.1", | ||
"gulp": "~3.9.0", | ||
"gulp-concat": "~2.6.0", | ||
"gulp-header": "~1.2.2", | ||
"gulp-footer": "~1.0.5", | ||
"gulp-jshint": "1.6.4", | ||
"gulp-plumber": "^0.6.3", | ||
"gulp-rename": "~0.2.2", | ||
"gulp-uglify": "~0.3.1", | ||
"jshint-stylish": "~0.3.0", | ||
"karma": "^0.12.16", | ||
"karma-chrome-launcher": "^0.1.3", | ||
"gulp-jshint": "1.11.2", | ||
"gulp-plumber": "^1.0.1", | ||
"gulp-rename": "~1.2.2", | ||
"gulp-uglify": "~1.2.0", | ||
"jshint-stylish": "~2.0.1", | ||
"karma": "^0.13.9", | ||
"karma-chrome-launcher": "^0.2.0", | ||
"karma-firefox-launcher": "~0.1", | ||
"karma-jasmine": "~0.2", | ||
"karma-jasmine": "~0.3", | ||
"karma-ng-html2js-preprocessor": "^0.1.0", | ||
"karma-phantomjs-launcher": "~0.1.4", | ||
"karma-coverage": "~0.2" | ||
"karma-phantomjs-launcher": "~0.2.1", | ||
"karma-coverage": "~0.5", | ||
"jasmine-core": "^2.3.4", | ||
"phantomjs": "^1.9.18" | ||
}, | ||
@@ -30,0 +31,0 @@ "scripts": {}, |
@@ -162,3 +162,2 @@ /* | ||
isValid = validateValue(value); | ||
var viewValue = isValid && value.length ? valueMasked : ''; | ||
if (iAttrs.maxlength) { // Double maxlength to allow pasting new val at end of mask | ||
@@ -170,5 +169,9 @@ iElement.attr('maxlength', maskCaretMap[maskCaretMap.length - 1] * 2); | ||
} | ||
iElement.val(viewValue); | ||
controller.$viewValue = viewValue; | ||
controller.$setValidity('mask', isValid); | ||
var viewValue = controller.$modelValue; | ||
var idx = controller.$formatters.length; | ||
while(idx--) { | ||
viewValue = controller.$formatters[idx](viewValue); | ||
} | ||
controller.$viewValue = viewValue || ''; | ||
controller.$render(); | ||
// Not using $setViewValue so we don't clobber the model value and dirty the form | ||
@@ -175,0 +178,0 @@ // without any kind of user interaction. |
@@ -9,2 +9,20 @@ describe("uiMask", function () { | ||
beforeEach(module("ui.mask")); | ||
beforeEach(function() { | ||
angular.module("test",[]).directive("toUpper", function() { | ||
return { | ||
priority: 200, | ||
require: 'ngModel', | ||
restrict: 'A', | ||
link: function (scope, iElement, iAttrs, controller) { | ||
controller.$formatters.push(function(fromModelValue) { | ||
return angular.uppercase(fromModelValue); | ||
}); | ||
controller.$parsers.push(function(fromViewValue) { | ||
return angular.lowercase(fromViewValue); | ||
}); | ||
} | ||
} | ||
}); | ||
module("test"); | ||
}); | ||
beforeEach(inject(function ($rootScope, $compile, uiMaskConfig) { | ||
@@ -64,3 +82,18 @@ scope = $rootScope; | ||
}); | ||
describe("other directives", function() { | ||
beforeEach(function () { | ||
compileElement("<form name='test'><input to-upper name='input' ng-model='x' ui-mask='{{mask}}'></form>"); | ||
}); | ||
it("should play nicely", function() { | ||
scope.$apply("x = 'abc123'"); | ||
scope.$apply("mask = '(A) * 9'"); | ||
expect(scope.x).toBe("abc123"); | ||
expect(scope.test.input.$viewValue).toBe("(A) B 1"); | ||
scope.$apply("mask = '(A)AA'"); | ||
expect(scope.test.input.$viewValue).toBe("(A)BC"); | ||
}); | ||
}); | ||
describe("user input", function () { | ||
@@ -67,0 +100,0 @@ it("should mask-as-you-type", function() { |
96405
1432
20