angular-ui-mask
Advanced tools
Comparing version 1.6.8 to 1.7.0
/*! | ||
* angular-ui-mask | ||
* https://github.com/angular-ui/ui-mask | ||
* Version: 1.6.8 - 2016-01-20T02:51:38.491Z | ||
* Version: 1.7.0 - 2016-01-25T02:23:34.418Z | ||
* License: MIT | ||
@@ -22,2 +22,3 @@ */ | ||
clearOnBlur: true, | ||
clearOnBlurPlaceholder: false, | ||
eventsToHandle: ['input', 'keyup', 'click', 'focus'] | ||
@@ -361,3 +362,3 @@ }) | ||
function blurHandler() { | ||
if (linkOptions.clearOnBlur) { | ||
if (linkOptions.clearOnBlur || ((linkOptions.clearOnBlurPlaceholder) && (value.length === 0) && iAttrs.placeholder)) { | ||
oldCaretPosition = 0; | ||
@@ -512,3 +513,3 @@ oldSelectionLength = 0; | ||
valUnmasked = valUnmasked.substring(0, charIndex) + valUnmasked.substring(charIndex + 1); | ||
// If value has not changed, don't want to call $setViewValue, may be caused by IE raising input event due to placeholder | ||
@@ -515,0 +516,0 @@ if (valUnmasked !== valUnmaskedOld) |
/*! | ||
* angular-ui-mask | ||
* https://github.com/angular-ui/ui-mask | ||
* Version: 1.6.8 - 2016-01-20T02:51:38.491Z | ||
* Version: 1.7.0 - 2016-01-25T02:23:34.418Z | ||
* 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",function(e){function n(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 t=e;return function(e,i,r,a){function u(e){return angular.isDefined(e)?($(e),q?(h(),d(),!0):f()):f()}function o(e){e&&(j=e,!q||0===i.val().length&&angular.isDefined(r.placeholder)||i.val(m(p(i.val()))))}function l(){return u(r.uiMask)}function c(e){return q?(_=p(e||""),F=v(_),a.$setValidity("mask",F),F&&_.length?m(_):void 0):e}function s(e){return q?(_=p(e||""),F=v(_),a.$viewValue=_.length?m(_):"",a.$setValidity("mask",F),F?J?a.$viewValue:_:void 0):e}function f(){return q=!1,g(),angular.isDefined(K)?i.attr("placeholder",K):i.removeAttr("placeholder"),angular.isDefined(W)?i.attr("maxlength",W):i.removeAttr("maxlength"),i.val(a.$modelValue),a.$viewValue=a.$modelValue,!1}function h(){_=z=p(a.$modelValue||""),H=N=m(_),F=v(_),r.maxlength&&i.attr("maxlength",2*S[S.length-1]),K||i.attr("placeholder",j);for(var e=a.$modelValue,n=a.$formatters.length;n--;)e=a.$formatters[n](e);a.$viewValue=e||"",a.$render()}function d(){I||(i.bind("blur",y),i.bind("mousedown mouseup",E),i.bind("keydown",x),i.bind(Q.eventsToHandle.join(" "),V),I=!0)}function g(){I&&(i.unbind("blur",y),i.unbind("mousedown",E),i.unbind("mouseup",E),i.unbind("keydown",x),i.unbind("input",V),i.unbind("keyup",V),i.unbind("click",V),i.unbind("focus",V),I=!1)}function v(e){return e.length?e.length>=T:!0}function p(e){var n="",t=C.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=S.slice();return angular.forEach(j.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,t=angular.isDefined(r.uiMaskPlaceholder)?r.uiMaskPlaceholder:r.placeholder;return angular.isDefined(t)&&t[e]?t[e]:(n=angular.isDefined(r.uiMaskPlaceholderChar)&&r.uiMaskPlaceholderChar?r.uiMaskPlaceholderChar:"_","space"===n.toLowerCase()?" ":n[0])}function k(){var e,n=j.split("");return S&&!isNaN(S[0])&&angular.forEach(S,function(e){n[e]="_"}),e=n.join(""),e.replace(/[_]+/g,"_").split("_")}function $(e){var n=0;if(S=[],C=[],j="",angular.isString(e)){T=0;var t=!1,i=0,r=e.split("");angular.forEach(r,function(e,r){Q.maskDefinitions[e]?(S.push(n),j+=b(r-i),C.push(Q.maskDefinitions[e]),n++,t||T++,t=!1):"?"===e?(t=!0,i++):(j+=e,n++)})}S.push(S.slice().pop()+1),R=k(),q=S.length>1?!0:!1}function y(){Q.clearOnBlur&&(B=0,L=0,F&&0!==_.length||(H="",i.val(""),e.$apply(function(){a.$viewValue=""}))),_!==U&&w(i[0]),U=_}function w(e){var n;angular.isFunction(window.Event)&&!e.fireEvent?(n=new Event("change",{view:window,bubbles:!0,cancelable:!1}),e.dispatchEvent(n)):"createEvent"in document?(n=document.createEvent("HTMLEvents"),n.initEvent("change",!1,!0),e.dispatchEvent(n)):e.fireEvent&&e.fireEvent("onchange")}function E(e){"mousedown"===e.type?i.bind("mouseout",M):i.unbind("mouseout",M)}function M(){L=P(this),i.unbind("mouseout",M)}function x(e){var n=8===e.which,t=D(this)-1||0;if(n){for(;t>=0;){if(O(t)){A(this,t+1);break}t--}Z=-1===t}}function V(n){n=n||{};var t=n.which,r=n.type;if(16!==t&&91!==t){var u,o=i.val(),l=N,c=!1,s=p(o),f=z,h=D(this)||0,d=B||0,g=h-d,v=S[0],b=S[s.length]||S.slice().shift(),k=L||0,$=P(this)>0,y=k>0,w=o.length>l.length||k&&o.length>l.length-k,E=o.length<l.length||k&&o.length===l.length-k,M=t>=37&&40>=t&&n.shiftKey,x=37===t,V=8===t||"keyup"!==r&&E&&-1===g,C=46===t||"keyup"!==r&&E&&0===g&&!y,R=(x||V||"click"===r)&&h>v;if(L=P(this),!M&&(!$||"click"!==r&&"keyup"!==r)){if(V&&Z)return i.val(j),e.$apply(function(){a.$setViewValue("")}),void A(this,d);if("input"===r&&E&&!y&&s===f){for(;V&&h>v&&!O(h);)h--;for(;C&&b>h&&-1===S.indexOf(h);)h++;var T=S.indexOf(h);s=s.substring(0,T)+s.substring(T+1),s!==f&&(c=!0)}for(u=m(s),N=u,z=s,!c&&o.length>u.length&&(c=!0),i.val(u),c&&e.$apply(function(){a.$setViewValue(s)}),w&&v>=h&&(h=v+1),R&&h--,h=h>b?b:v>h?v:h;!O(h)&&h>v&&b>h;)h+=R?-1:1;(R&&b>h||w&&!O(d))&&h++,B=h,A(this,h)}}}function O(e){return S.indexOf(e)>-1}function D(e){if(!e)return 0;if(void 0!==e.selectionStart)return e.selectionStart;if(document.selection&&n(i[0])){e.focus();var t=document.selection.createRange();return t.moveStart("character",e.value?-e.value.length:0),t.text.length}return 0}function A(e,t){if(!e)return 0;if(0!==e.offsetWidth&&0!==e.offsetHeight)if(e.setSelectionRange)n(i[0])&&(e.focus(),e.setSelectionRange(t,t));else if(e.createTextRange){var r=e.createTextRange();r.collapse(!0),r.moveEnd("character",t),r.moveStart("character",t),r.select()}}function P(e){return e?void 0!==e.selectionStart?e.selectionEnd-e.selectionStart:document.selection?document.selection.createRange().text.length:0:0}var S,C,j,R,T,_,H,F,N,z,B,L,Z,q=!1,I=!1,K=r.placeholder,W=r.maxlength,G=a.$isEmpty;a.$isEmpty=function(e){return G(q?p(e||""):e)};var J=!1;r.$observe("modelViewValue",function(e){"true"===e&&(J=!0)});var Q={};r.uiOptions?(Q=e.$eval("["+r.uiOptions+"]"),Q=angular.isObject(Q[0])?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.isObject(n[t])&&!angular.isArray(n[t])&&(n[t]=angular.extend({},e[t],n[t])));return n}(t,Q[0]):t):Q=t,r.$observe("uiMask",u),angular.isDefined(r.uiMaskPlaceholder)?r.$observe("uiMaskPlaceholder",o):r.$observe("placeholder",o),angular.isDefined(r.uiMaskPlaceholderChar)&&r.$observe("uiMaskPlaceholderChar",l),a.$formatters.push(c),a.$parsers.unshift(s);var U=i.val();i.bind("mousedown mouseup",E),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&&i!==1/0&&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,clearOnBlurPlaceholder:!1,eventsToHandle:["input","keyup","click","focus"]}).directive("uiMask",["uiMaskConfig",function(e){function n(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 t=e;return function(e,i,r,a){function u(e){return angular.isDefined(e)?($(e),q?(h(),d(),!0):f()):f()}function l(e){e&&(j=e,!q||0===i.val().length&&angular.isDefined(r.placeholder)||i.val(m(p(i.val()))))}function o(){return u(r.uiMask)}function c(e){return q?(_=p(e||""),H=v(_),a.$setValidity("mask",H),H&&_.length?m(_):void 0):e}function s(e){return q?(_=p(e||""),H=v(_),a.$viewValue=_.length?m(_):"",a.$setValidity("mask",H),H?J?a.$viewValue:_:void 0):e}function f(){return q=!1,g(),angular.isDefined(K)?i.attr("placeholder",K):i.removeAttr("placeholder"),angular.isDefined(W)?i.attr("maxlength",W):i.removeAttr("maxlength"),i.val(a.$modelValue),a.$viewValue=a.$modelValue,!1}function h(){_=N=p(a.$modelValue||""),B=F=m(_),H=v(_),r.maxlength&&i.attr("maxlength",2*S[S.length-1]),K||i.attr("placeholder",j);for(var e=a.$modelValue,n=a.$formatters.length;n--;)e=a.$formatters[n](e);a.$viewValue=e||"",a.$render()}function d(){I||(i.bind("blur",y),i.bind("mousedown mouseup",E),i.bind("keydown",x),i.bind(Q.eventsToHandle.join(" "),V),I=!0)}function g(){I&&(i.unbind("blur",y),i.unbind("mousedown",E),i.unbind("mouseup",E),i.unbind("keydown",x),i.unbind("input",V),i.unbind("keyup",V),i.unbind("click",V),i.unbind("focus",V),I=!1)}function v(e){return e.length?e.length>=T:!0}function p(e){var n="",t=C.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=S.slice();return angular.forEach(j.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,t=angular.isDefined(r.uiMaskPlaceholder)?r.uiMaskPlaceholder:r.placeholder;return angular.isDefined(t)&&t[e]?t[e]:(n=angular.isDefined(r.uiMaskPlaceholderChar)&&r.uiMaskPlaceholderChar?r.uiMaskPlaceholderChar:"_","space"===n.toLowerCase()?" ":n[0])}function k(){var e,n=j.split("");return S&&!isNaN(S[0])&&angular.forEach(S,function(e){n[e]="_"}),e=n.join(""),e.replace(/[_]+/g,"_").split("_")}function $(e){var n=0;if(S=[],C=[],j="",angular.isString(e)){T=0;var t=!1,i=0,r=e.split("");angular.forEach(r,function(e,r){Q.maskDefinitions[e]?(S.push(n),j+=b(r-i),C.push(Q.maskDefinitions[e]),n++,t||T++,t=!1):"?"===e?(t=!0,i++):(j+=e,n++)})}S.push(S.slice().pop()+1),R=k(),q=S.length>1?!0:!1}function y(){(Q.clearOnBlur||Q.clearOnBlurPlaceholder&&0===_.length&&r.placeholder)&&(z=0,L=0,H&&0!==_.length||(B="",i.val(""),e.$apply(function(){a.$viewValue=""}))),_!==U&&w(i[0]),U=_}function w(e){var n;angular.isFunction(window.Event)&&!e.fireEvent?(n=new Event("change",{view:window,bubbles:!0,cancelable:!1}),e.dispatchEvent(n)):"createEvent"in document?(n=document.createEvent("HTMLEvents"),n.initEvent("change",!1,!0),e.dispatchEvent(n)):e.fireEvent&&e.fireEvent("onchange")}function E(e){"mousedown"===e.type?i.bind("mouseout",M):i.unbind("mouseout",M)}function M(){L=A(this),i.unbind("mouseout",M)}function x(e){var n=8===e.which,t=D(this)-1||0;if(n){for(;t>=0;){if(O(t)){P(this,t+1);break}t--}Z=-1===t}}function V(n){n=n||{};var t=n.which,r=n.type;if(16!==t&&91!==t){var u,l=i.val(),o=F,c=!1,s=p(l),f=N,h=D(this)||0,d=z||0,g=h-d,v=S[0],b=S[s.length]||S.slice().shift(),k=L||0,$=A(this)>0,y=k>0,w=l.length>o.length||k&&l.length>o.length-k,E=l.length<o.length||k&&l.length===o.length-k,M=t>=37&&40>=t&&n.shiftKey,x=37===t,V=8===t||"keyup"!==r&&E&&-1===g,C=46===t||"keyup"!==r&&E&&0===g&&!y,R=(x||V||"click"===r)&&h>v;if(L=A(this),!M&&(!$||"click"!==r&&"keyup"!==r)){if(V&&Z)return i.val(j),e.$apply(function(){a.$setViewValue("")}),void P(this,d);if("input"===r&&E&&!y&&s===f){for(;V&&h>v&&!O(h);)h--;for(;C&&b>h&&-1===S.indexOf(h);)h++;var T=S.indexOf(h);s=s.substring(0,T)+s.substring(T+1),s!==f&&(c=!0)}for(u=m(s),F=u,N=s,!c&&l.length>u.length&&(c=!0),i.val(u),c&&e.$apply(function(){a.$setViewValue(s)}),w&&v>=h&&(h=v+1),R&&h--,h=h>b?b:v>h?v:h;!O(h)&&h>v&&b>h;)h+=R?-1:1;(R&&b>h||w&&!O(d))&&h++,z=h,P(this,h)}}}function O(e){return S.indexOf(e)>-1}function D(e){if(!e)return 0;if(void 0!==e.selectionStart)return e.selectionStart;if(document.selection&&n(i[0])){e.focus();var t=document.selection.createRange();return t.moveStart("character",e.value?-e.value.length:0),t.text.length}return 0}function P(e,t){if(!e)return 0;if(0!==e.offsetWidth&&0!==e.offsetHeight)if(e.setSelectionRange)n(i[0])&&(e.focus(),e.setSelectionRange(t,t));else if(e.createTextRange){var r=e.createTextRange();r.collapse(!0),r.moveEnd("character",t),r.moveStart("character",t),r.select()}}function A(e){return e?void 0!==e.selectionStart?e.selectionEnd-e.selectionStart:document.selection?document.selection.createRange().text.length:0:0}var S,C,j,R,T,_,B,H,F,N,z,L,Z,q=!1,I=!1,K=r.placeholder,W=r.maxlength,G=a.$isEmpty;a.$isEmpty=function(e){return G(q?p(e||""):e)};var J=!1;r.$observe("modelViewValue",function(e){"true"===e&&(J=!0)});var Q={};r.uiOptions?(Q=e.$eval("["+r.uiOptions+"]"),Q=angular.isObject(Q[0])?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.isObject(n[t])&&!angular.isArray(n[t])&&(n[t]=angular.extend({},e[t],n[t])));return n}(t,Q[0]):t):Q=t,r.$observe("uiMask",u),angular.isDefined(r.uiMaskPlaceholder)?r.$observe("uiMaskPlaceholder",l):r.$observe("placeholder",l),angular.isDefined(r.uiMaskPlaceholderChar)&&r.$observe("uiMaskPlaceholderChar",o),a.$formatters.push(c),a.$parsers.unshift(s);var U=i.val();i.bind("mousedown mouseup",E),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&&i!==1/0&&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})}}}}])}(); |
{ | ||
"name": "angular-ui-mask", | ||
"version": "1.6.8", | ||
"version": "1.7.0", | ||
"author": "https://github.com/angular-ui/ui-mask/graphs/contributors", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -58,3 +58,3 @@ # 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) | ||
Inside of `ui-options`, you can customize these three properties: | ||
Inside of `ui-options`, you can customize these four properties: | ||
@@ -67,2 +67,3 @@ * `maskDefinitions` - default: `{ | ||
* `clearOnBlur` - default: `true`, | ||
* `clearOnBlurPlaceholder` - default: `false`, | ||
* `eventsToHandle` - default: `['input', 'keyup', 'click', 'focus']` | ||
@@ -72,2 +73,4 @@ | ||
When setting `clearOnBlurPlaceholder` to `true`, it will show the placeholder text instead of the empty mask. It requires the `ui-mask-placeholder` attribute to be set on the input to display properly. | ||
Whereas, `maskDefinitions` is an object, so any custom object you supply will be merged together with the defaults using `angular.extend()`. This allows you to override the defaults selectively, if you wish. | ||
@@ -74,0 +77,0 @@ |
@@ -12,2 +12,3 @@ /* | ||
clearOnBlur: true, | ||
clearOnBlurPlaceholder: false, | ||
eventsToHandle: ['input', 'keyup', 'click', 'focus'] | ||
@@ -351,3 +352,3 @@ }) | ||
function blurHandler() { | ||
if (linkOptions.clearOnBlur) { | ||
if (linkOptions.clearOnBlur || ((linkOptions.clearOnBlurPlaceholder) && (value.length === 0) && iAttrs.placeholder)) { | ||
oldCaretPosition = 0; | ||
@@ -502,3 +503,3 @@ oldSelectionLength = 0; | ||
valUnmasked = valUnmasked.substring(0, charIndex) + valUnmasked.substring(charIndex + 1); | ||
// If value has not changed, don't want to call $setViewValue, may be caused by IE raising input event due to placeholder | ||
@@ -505,0 +506,0 @@ if (valUnmasked !== valUnmaskedOld) |
@@ -614,4 +614,43 @@ describe("uiMask", function () { | ||
}); | ||
var inputHtmlClearOnBlurPlaceholder = "<input name='input' ng-model='x' ui-mask='{{mask}}' ui-options=\"input.options\" ui-mask-placeholder placeholder=\"PLACEHOLDER\">"; | ||
it("should not show placeholder when value is invalid if clearOnBlurPlaceholder is false", function() { | ||
scope.input = { | ||
options: { | ||
clearOnBlur: false, | ||
clearOnBlurPlaceholder: false | ||
} | ||
}; | ||
var input = compileElement(inputHtmlClearOnBlurPlaceholder); | ||
scope.$apply("x = ''"); | ||
scope.$apply("mask = '(9) * A'"); | ||
input.val("").triggerHandler("input"); | ||
input.triggerHandler("blur"); | ||
expect(input.val()).toBe("(_) _ _"); | ||
}); | ||
it("should show placeholder when value is invalid if clearOnBlurPlaceholder is true", function() { | ||
scope.input = { | ||
options: { | ||
clearOnBlur: false, | ||
clearOnBlurPlaceholder: true | ||
} | ||
}; | ||
var input = compileElement(inputHtmlClearOnBlurPlaceholder); | ||
scope.$apply("x = ''"); | ||
scope.$apply("mask = '(9) * A'"); | ||
input.val("").triggerHandler("input"); | ||
input.triggerHandler("blur"); | ||
expect(input.val()).toBe(""); | ||
expect(input.attr("placeholder")).toBe("PLACEHOLDER"); | ||
}); | ||
}); | ||
}); |
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
130366
1893
106