angular-ui-mask
Advanced tools
Comparing version 1.2.0 to 1.3.0
/*! | ||
* angular-ui-mask | ||
* https://github.com/angular-ui/ui-mask | ||
* Version: 1.2.0 - 2015-07-05T05:14:53.514Z | ||
* Version: 1.3.0 - 2015-07-31T07:01:50.807Z | ||
* License: MIT | ||
@@ -185,2 +185,3 @@ */ | ||
iElement.bind('input keyup click focus', eventHandler); | ||
iElement.bind('paste', onPasteHandler); | ||
eventsBound = true; | ||
@@ -200,2 +201,3 @@ } | ||
iElement.unbind('focus', eventHandler); | ||
iElement.unbind('paste', onPasteHandler); | ||
eventsBound = false; | ||
@@ -339,2 +341,7 @@ } | ||
function onPasteHandler() { | ||
/*jshint validthis: true */ | ||
setCaretPosition(this, iElement.val().length); | ||
} | ||
function eventHandler(e) { | ||
@@ -357,3 +364,2 @@ /*jshint validthis: true */ | ||
valUnmaskedOld = oldValueUnmasked, | ||
valAltered = false, | ||
caretPos = getCaretPosition(this) || 0, | ||
@@ -404,3 +410,2 @@ caretPosOld = oldCaretPosition || 0, | ||
valUnmasked = valUnmasked.substring(0, charIndex) + valUnmasked.substring(charIndex + 1); | ||
valAltered = true; | ||
} | ||
@@ -414,8 +419,3 @@ | ||
iElement.val(valMasked); | ||
if (valAltered) { | ||
// We've altered the raw value after it's been $digest'ed, we need to $apply the new value. | ||
scope.$apply(function() { | ||
controller.$setViewValue(valUnmasked); | ||
}); | ||
} | ||
controller.$setViewValue(valUnmasked); | ||
@@ -422,0 +422,0 @@ // Caret Repositioning |
/*! | ||
* angular-ui-mask | ||
* https://github.com/angular-ui/ui-mask | ||
* Version: 1.2.0 - 2015-07-05T05:14:53.514Z | ||
* Version: 1.3.0 - 2015-07-31T07:01:50.807Z | ||
* License: MIT | ||
*/ | ||
!function(){"use strict";angular.module("ui.mask",[]).value("uiMaskConfig",{maskDefinitions:{9:/\d/,A:/[a-zA-Z]/,"*":/[a-zA-Z0-9]/},clearOnBlur:!0}).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),H?(h(),d(),!0):f()):f()}function l(e){angular.isDefined(e)&&(D=e,H&&w())}function c(e){return H?(j=v(e||""),T=p(j),a.$setValidity("mask",T),T&&j.length?m(j):void 0):e}function s(e){return H?(j=v(e||""),T=p(j),a.$viewValue=j.length?m(j):"",a.$setValidity("mask",T),""===j&&u.required&&a.$setValidity("required",!a.$error.required),T?j:void 0):e}function f(){return H=!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=B=v(a.$modelValue||""),z=Z=m(j),T=p(j);var e=T&&j.length?z:"";u.maxlength&&r.attr("maxlength",2*E[E.length-1]),r.attr("placeholder",D),r.val(e),a.$viewValue=e,a.$setValidity("mask",T)}function d(){I||(r.bind("blur",k),r.bind("mousedown mouseup",x),r.bind("input keyup click focus",w),I=!0)}function g(){I&&(r.unbind("blur",k),r.unbind("mousedown",x),r.unbind("mouseup",x),r.unbind("input",w),r.unbind("keyup",w),r.unbind("click",w),r.unbind("focus",w),I=!1)}function p(e){return e.length?e.length>=q:!0}function v(e){var n="",t=_.slice();return e=e.toString(),angular.forEach(R,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(D.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=u.placeholder;return"undefined"!=typeof n&&n[e]?n[e]:"_"}function $(){return D.replace(/[_]+/g,"_").replace(/([^_]+)([a-zA-Z0-9])([^_])/g,"$1$2_$3").split("_")}function y(e){var n=0;if(E=[],_=[],D="","string"==typeof e){q=0;var t=!1,i=0,r=e.split("");angular.forEach(r,function(e,r){P.maskDefinitions[e]?(E.push(n),D+=b(r-i),_.push(P.maskDefinitions[e]),n++,t||q++):"?"===e?(t=!0,i++):(D+=e,n++)})}E.push(E.slice().pop()+1),R=$(),H=E.length>1?!0:!1}function k(){P.clearOnBlur&&(C=0,F=0,T&&0!==j.length||(z="",r.val(""),e.$apply(function(){a.$setViewValue("")})))}function x(e){"mousedown"===e.type?r.bind("mouseout",V):r.unbind("mouseout",V)}function V(){F=S(this),r.unbind("mouseout",V)}function w(n){n=n||{};var t=n.which,i=n.type;if(16!==t&&91!==t){var u,o=r.val(),l=Z,c=v(o),s=B,f=!1,h=M(this)||0,d=C||0,g=h-d,p=E[0],b=E[c.length]||E.slice().shift(),$=F||0,y=S(this)>0,k=$>0,x=o.length>l.length||$&&o.length>l.length-$,V=o.length<l.length||$&&o.length===l.length-$,w=t>=37&&40>=t&&n.shiftKey,_=37===t,D=8===t||"keyup"!==i&&V&&-1===g,R=46===t||"keyup"!==i&&V&&0===g&&!k,q=(_||D||"click"===i)&&h>p;if(F=S(this),!w&&(!y||"click"!==i&&"keyup"!==i)){if("input"===i&&V&&!k&&c===s){for(;D&&h>p&&!O(h);)h--;for(;R&&b>h&&-1===E.indexOf(h);)h++;var j=E.indexOf(h);c=c.substring(0,j)+c.substring(j+1),f=!0}for(u=m(c),Z=u,B=c,r.val(u),f&&e.$apply(function(){a.$setViewValue(c)}),x&&p>=h&&(h=p+1),q&&h--,h=h>b?b:p>h?p:h;!O(h)&&h>p&&b>h;)h+=q?-1:1;(q&&b>h||x&&!O(d))&&h++,C=h,A(this,h)}}}function O(e){return E.indexOf(e)>-1}function M(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 A(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 S(e){return e?void 0!==e.selectionStart?e.selectionEnd-e.selectionStart:document.selection?document.selection.createRange().text.length:0:0}var E,_,D,R,q,j,z,T,Z,B,C,F,H=!1,I=!1,K=u.placeholder,N=u.maxlength,P={};u.uiOptions?(P=e.$eval("["+u.uiOptions+"]"),angular.isObject(P[0])&&(P=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,P[0]))):P=i,u.$observe("uiMask",o),u.$observe("placeholder",l);var W=!1;u.$observe("modelViewValue",function(e){"true"===e&&(W=!0)}),e.$watch(u.ngModel,function(t){if(W&&t){var i=n(u.ngModel);i.assign(e,a.$viewValue)}}),a.$formatters.push(c),a.$parsers.push(s),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}).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),I?(h(),d(),!0):f()):f()}function l(e){angular.isDefined(e)&&(R=e,I&&O())}function c(e){return I?(z=v(e||""),Z=p(z),a.$setValidity("mask",Z),Z&&z.length?m(z):void 0):e}function s(e){return I?(z=v(e||""),Z=p(z),a.$viewValue=z.length?m(z):"",a.$setValidity("mask",Z),""===z&&u.required&&a.$setValidity("required",!a.$error.required),Z?z:void 0):e}function f(){return I=!1,g(),angular.isDefined(N)?r.attr("placeholder",N):r.removeAttr("placeholder"),angular.isDefined(P)?r.attr("maxlength",P):r.removeAttr("maxlength"),r.val(a.$modelValue),a.$viewValue=a.$modelValue,!1}function h(){z=C=v(a.$modelValue||""),T=B=m(z),Z=p(z);var e=Z&&z.length?T:"";u.maxlength&&r.attr("maxlength",2*_[_.length-1]),r.attr("placeholder",R),r.val(e),a.$viewValue=e,a.$setValidity("mask",Z)}function d(){K||(r.bind("blur",k),r.bind("mousedown mouseup",x),r.bind("input keyup click focus",O),r.bind("paste",w),K=!0)}function g(){K&&(r.unbind("blur",k),r.unbind("mousedown",x),r.unbind("mouseup",x),r.unbind("input",O),r.unbind("keyup",O),r.unbind("click",O),r.unbind("focus",O),r.unbind("paste",w),K=!1)}function p(e){return e.length?e.length>=j:!0}function v(e){var n="",t=D.slice();return e=e.toString(),angular.forEach(q,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=_.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=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(_=[],D=[],R="","string"==typeof e){j=0;var t=!1,i=0,r=e.split("");angular.forEach(r,function(e,r){W.maskDefinitions[e]?(_.push(n),R+=b(r-i),D.push(W.maskDefinitions[e]),n++,t||j++):"?"===e?(t=!0,i++):(R+=e,n++)})}_.push(_.slice().pop()+1),q=$(),I=_.length>1?!0:!1}function k(){W.clearOnBlur&&(F=0,H=0,Z&&0!==z.length||(T="",r.val(""),e.$apply(function(){a.$setViewValue("")})))}function x(e){"mousedown"===e.type?r.bind("mouseout",V):r.unbind("mouseout",V)}function V(){H=E(this),r.unbind("mouseout",V)}function w(){S(this,r.val().length)}function O(e){e=e||{};var n=e.which,t=e.type;if(16!==n&&91!==n){var i,u=r.val(),o=B,l=v(u),c=C,s=A(this)||0,f=F||0,h=s-f,d=_[0],g=_[l.length]||_.slice().shift(),p=H||0,b=E(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,O=46===n||"keyup"!==t&&k&&0===h&&!$,D=(V||w||"click"===t)&&s>d;if(H=E(this),!x&&(!b||"click"!==t&&"keyup"!==t)){if("input"===t&&k&&!$&&l===c){for(;w&&s>d&&!M(s);)s--;for(;O&&g>s&&-1===_.indexOf(s);)s++;var R=_.indexOf(s);l=l.substring(0,R)+l.substring(R+1)}for(i=m(l),B=i,C=l,r.val(i),a.$setViewValue(l),y&&d>=s&&(s=d+1),D&&s--,s=s>g?g:d>s?d:s;!M(s)&&s>d&&g>s;)s+=D?-1:1;(D&&g>s||y&&!M(f))&&s++,F=s,S(this,s)}}}function M(e){return _.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 E(e){return e?void 0!==e.selectionStart?e.selectionEnd-e.selectionStart:document.selection?document.selection.createRange().text.length:0:0}var _,D,R,q,j,z,T,Z,B,C,F,H,I=!1,K=!1,N=u.placeholder,P=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),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(c),a.$parsers.push(s),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})}}}}])}(); |
@@ -15,3 +15,3 @@ // Karma configuration | ||
'bower_components/angular-mocks/angular-mocks.js', | ||
'src/*.js', | ||
'dist/*.min.js', | ||
'test/*Spec.js' | ||
@@ -18,0 +18,0 @@ ], |
{ | ||
"name": "angular-ui-mask", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"author": "https://github.com/angular-ui/ui-mask/graphs/contributors", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -1,2 +0,2 @@ | ||
# ui-mask [![Build Status](https://travis-ci.org/angular-ui/ui-mask.svg?branch=master)](https://travis-ci.org/angular-ui/ui-mask) | ||
# ui-mask [![Build Status](https://travis-ci.org/angular-ui/ui-mask.svg?branch=master)](https://travis-ci.org/angular-ui/ui-mask) [![npm version](https://badge.fury.io/js/angular-ui-mask.svg)](http://badge.fury.io/js/angular-ui-mask) [![Bower version](https://badge.fury.io/bo/angular-ui-mask.svg)](http://badge.fury.io/bo/angular-ui-mask) [![Join the chat at https://gitter.im/angular-ui/ui-mask](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/angular-ui/ui-mask?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
@@ -22,3 +22,3 @@ Apply a mask on an input field so the user can only type pre-determined pattern. | ||
<script type="text/javascript" src="bower_components/angular/angular.js"></script> | ||
<script type="text/javascript" src="bower_components/angular-ui-mask/ui-mask.js"></script> | ||
<script type="text/javascript" src="bower_components/angular-ui-mask/dist/mask.js"></script> | ||
``` | ||
@@ -25,0 +25,0 @@ |
@@ -175,2 +175,3 @@ /* | ||
iElement.bind('input keyup click focus', eventHandler); | ||
iElement.bind('paste', onPasteHandler); | ||
eventsBound = true; | ||
@@ -190,2 +191,3 @@ } | ||
iElement.unbind('focus', eventHandler); | ||
iElement.unbind('paste', onPasteHandler); | ||
eventsBound = false; | ||
@@ -329,2 +331,7 @@ } | ||
function onPasteHandler() { | ||
/*jshint validthis: true */ | ||
setCaretPosition(this, iElement.val().length); | ||
} | ||
function eventHandler(e) { | ||
@@ -347,3 +354,2 @@ /*jshint validthis: true */ | ||
valUnmaskedOld = oldValueUnmasked, | ||
valAltered = false, | ||
caretPos = getCaretPosition(this) || 0, | ||
@@ -394,3 +400,2 @@ caretPosOld = oldCaretPosition || 0, | ||
valUnmasked = valUnmasked.substring(0, charIndex) + valUnmasked.substring(charIndex + 1); | ||
valAltered = true; | ||
} | ||
@@ -404,8 +409,3 @@ | ||
iElement.val(valMasked); | ||
if (valAltered) { | ||
// We've altered the raw value after it's been $digest'ed, we need to $apply the new value. | ||
scope.$apply(function() { | ||
controller.$setViewValue(valUnmasked); | ||
}); | ||
} | ||
controller.$setViewValue(valUnmasked); | ||
@@ -412,0 +412,0 @@ // Caret Repositioning |
@@ -88,2 +88,12 @@ describe("uiMask", function () { | ||
it("should maintain $viewValue consistent with input value", function() { | ||
var form = compileElement(formHtml); | ||
var input = form.find("input"); | ||
scope.$apply("x = ''"); | ||
scope.$apply("mask = '99 9'"); | ||
input.val("3333").triggerHandler("input"); | ||
input.val("3333").triggerHandler("input"); // It used to has a bug when pressing a key repeatedly | ||
expect(scope.test.input.$viewValue).toBe("33 3"); | ||
}); | ||
it("should parse unmasked value to model", function() { | ||
@@ -253,3 +263,2 @@ var form = compileElement(formHtml); | ||
}); | ||
}); | ||
@@ -256,0 +265,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
93642
19
1351