angular-ui-mask
Advanced tools
Comparing version 1.5.0 to 1.5.1
/*! | ||
* angular-ui-mask | ||
* https://github.com/angular-ui/ui-mask | ||
* Version: 1.5.0 - 2015-11-03T03:09:24.207Z | ||
* Version: 1.5.1 - 2015-11-04T03:46:01.010Z | ||
* License: MIT | ||
@@ -129,4 +129,4 @@ */ | ||
} else { | ||
if (angular.isObject(current[i])) { | ||
angular.extend(current[i], original[i]); | ||
if (angular.isObject(current[i]) && !angular.isArray(current[i])) { | ||
current[i] = angular.extend({}, original[i], current[i]); | ||
} | ||
@@ -138,2 +138,4 @@ } | ||
})(options, linkOptions[0]); | ||
} else { | ||
linkOptions = options; //gotta be a better way to do this.. | ||
} | ||
@@ -140,0 +142,0 @@ } else { |
/*! | ||
* angular-ui-mask | ||
* https://github.com/angular-ui/ui-mask | ||
* Version: 1.5.0 - 2015-11-03T03:09:24.207Z | ||
* Version: 1.5.1 - 2015-11-04T03:46:01.010Z | ||
* 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)?(k(e),L?(h(),d(),!0):f()):f()}function o(e){e&&(_=e,L&&i.val(m(p(i.val()))))}function l(){return u(r.uiMask)}function c(e){return L?(j=p(e||""),H=v(j),a.$setValidity("mask",H),H&&j.length?m(j):void 0):e}function s(e){return L?(j=p(e||""),H=v(j),a.$viewValue=j.length?m(j):"",a.$setValidity("mask",H),""===j&&r.required&&a.$setValidity("required",!a.$error.required),H?W?a.$viewValue:j:void 0):e}function f(){return L=!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 h(){j=Z=p(a.$modelValue||""),q=z=m(j),H=v(j),r.maxlength&&i.attr("maxlength",2*S[S.length-1]),K||i.attr("placeholder",_);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",M),i.bind(G.eventsToHandle.join(" "),V),i.bind("paste",x),I=!0)}function g(){I&&(i.unbind("blur",y),i.unbind("mousedown",M),i.unbind("mouseup",M),i.unbind("input",V),i.unbind("keyup",V),i.unbind("click",V),i.unbind("focus",V),i.unbind("paste",x),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(_.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"undefined"!=typeof t&&t[e]?t[e]:(n=angular.isDefined(r.uiMaskPlaceholderChar)&&r.uiMaskPlaceholderChar?r.uiMaskPlaceholderChar:"_","space"===n.toLowerCase()?" ":n[0])}function $(){return _.replace(/[_]+/g,"_").replace(/([^_]+)([a-zA-Z0-9])([^_])/g,"$1$2_$3").split("_")}function k(e){var n=0;if(S=[],C=[],_="","string"==typeof e){T=0;var t=!1,i=0,r=e.split("");angular.forEach(r,function(e,r){G.maskDefinitions[e]?(S.push(n),_+=b(r-i),C.push(G.maskDefinitions[e]),n++,t||T++):"?"===e?(t=!0,i++):(_+=e,n++)})}S.push(S.slice().pop()+1),R=$(),L=S.length>1?!0:!1}function y(){G.clearOnBlur&&(B=0,F=0,H&&0!==j.length||(q="",i.val(""),e.$apply(function(){a.$setViewValue("")}))),j!==J&&w(i[0]),J=j}function w(e){var n;"function"!=typeof window.Event||e.fireEvent?"createEvent"in document?(n=document.createEvent("HTMLEvents"),n.initEvent("change",!1,!0),e.dispatchEvent(n)):e.fireEvent&&e.fireEvent("onchange"):(n=new Event("change",{view:window,bubbles:!0,cancelable:!1}),e.dispatchEvent(n))}function M(e){"mousedown"===e.type?i.bind("mouseout",E):i.unbind("mouseout",E)}function E(){F=P(this),i.unbind("mouseout",E)}function x(){D(this,i.val().length)}function V(n){n=n||{};var t=n.which,r=n.type;if(16!==t&&91!==t){var u,o=i.val(),l=z,c=p(o),s=Z,f=A(this)||0,h=B||0,d=f-h,g=S[0],v=S[c.length]||S.slice().shift(),b=F||0,$=P(this)>0,k=b>0,y=o.length>l.length||b&&o.length>l.length-b,w=o.length<l.length||b&&o.length===l.length-b,M=t>=37&&40>=t&&n.shiftKey,E=37===t,x=8===t||"keyup"!==r&&w&&-1===d,V=46===t||"keyup"!==r&&w&&0===d&&!k,C=(E||x||"click"===r)&&f>g;if(F=P(this),!M&&(!$||"click"!==r&&"keyup"!==r)){if("input"===r&&w&&!k&&c===s){for(;x&&f>g&&!O(f);)f--;for(;V&&v>f&&-1===S.indexOf(f);)f++;var _=S.indexOf(f);c=c.substring(0,_)+c.substring(_+1)}for(u=m(c),z=u,Z=c,i.val(u),e.$apply(function(){a.$setViewValue(c)}),y&&g>=f&&(f=g+1),C&&f--,f=f>v?v:g>f?g:f;!O(f)&&f>g&&v>f;)f+=C?-1:1;(C&&v>f||y&&!O(h))&&f++,B=f,D(this,f)}}}function O(e){return S.indexOf(e)>-1}function A(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 D(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,_,R,T,j,q,H,z,Z,B,F,L=!1,I=!1,K=r.placeholder,N=r.maxlength,W=!1;r.$observe("modelViewValue",function(e){"true"===e&&(W=!0)});var G={};r.uiOptions?(G=e.$eval("["+r.uiOptions+"]"),angular.isObject(G[0])&&(G=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.extend(n[t],e[t]));return n}(t,G[0]))):G=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.push(s);var J=i.val();i.bind("mousedown mouseup",M),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,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,r,i,a){function u(e){return angular.isDefined(e)?(k(e),L?(h(),d(),!0):f()):f()}function o(e){e&&(_=e,L&&r.val(m(p(r.val()))))}function l(){return u(i.uiMask)}function c(e){return L?(j=p(e||""),H=v(j),a.$setValidity("mask",H),H&&j.length?m(j):void 0):e}function s(e){return L?(j=p(e||""),H=v(j),a.$viewValue=j.length?m(j):"",a.$setValidity("mask",H),""===j&&i.required&&a.$setValidity("required",!a.$error.required),H?W?a.$viewValue:j:void 0):e}function f(){return L=!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=p(a.$modelValue||""),q=z=m(j),H=v(j),i.maxlength&&r.attr("maxlength",2*S[S.length-1]),K||r.attr("placeholder",_);for(var e=a.$modelValue,n=a.$formatters.length;n--;)e=a.$formatters[n](e);a.$viewValue=e||"",a.$render()}function d(){I||(r.bind("blur",y),r.bind("mousedown mouseup",M),r.bind(G.eventsToHandle.join(" "),V),r.bind("paste",x),I=!0)}function g(){I&&(r.unbind("blur",y),r.unbind("mousedown",M),r.unbind("mouseup",M),r.unbind("input",V),r.unbind("keyup",V),r.unbind("click",V),r.unbind("focus",V),r.unbind("paste",x),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(_.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,t=angular.isDefined(i.uiMaskPlaceholder)?i.uiMaskPlaceholder:i.placeholder;return"undefined"!=typeof t&&t[e]?t[e]:(n=angular.isDefined(i.uiMaskPlaceholderChar)&&i.uiMaskPlaceholderChar?i.uiMaskPlaceholderChar:"_","space"===n.toLowerCase()?" ":n[0])}function $(){return _.replace(/[_]+/g,"_").replace(/([^_]+)([a-zA-Z0-9])([^_])/g,"$1$2_$3").split("_")}function k(e){var n=0;if(S=[],C=[],_="","string"==typeof e){T=0;var t=!1,r=0,i=e.split("");angular.forEach(i,function(e,i){G.maskDefinitions[e]?(S.push(n),_+=b(i-r),C.push(G.maskDefinitions[e]),n++,t||T++):"?"===e?(t=!0,r++):(_+=e,n++)})}S.push(S.slice().pop()+1),R=$(),L=S.length>1?!0:!1}function y(){G.clearOnBlur&&(B=0,F=0,H&&0!==j.length||(q="",r.val(""),e.$apply(function(){a.$setViewValue("")}))),j!==J&&w(r[0]),J=j}function w(e){var n;"function"!=typeof window.Event||e.fireEvent?"createEvent"in document?(n=document.createEvent("HTMLEvents"),n.initEvent("change",!1,!0),e.dispatchEvent(n)):e.fireEvent&&e.fireEvent("onchange"):(n=new Event("change",{view:window,bubbles:!0,cancelable:!1}),e.dispatchEvent(n))}function M(e){"mousedown"===e.type?r.bind("mouseout",E):r.unbind("mouseout",E)}function E(){F=P(this),r.unbind("mouseout",E)}function x(){D(this,r.val().length)}function V(n){n=n||{};var t=n.which,i=n.type;if(16!==t&&91!==t){var u,o=r.val(),l=z,c=p(o),s=Z,f=A(this)||0,h=B||0,d=f-h,g=S[0],v=S[c.length]||S.slice().shift(),b=F||0,$=P(this)>0,k=b>0,y=o.length>l.length||b&&o.length>l.length-b,w=o.length<l.length||b&&o.length===l.length-b,M=t>=37&&40>=t&&n.shiftKey,E=37===t,x=8===t||"keyup"!==i&&w&&-1===d,V=46===t||"keyup"!==i&&w&&0===d&&!k,C=(E||x||"click"===i)&&f>g;if(F=P(this),!M&&(!$||"click"!==i&&"keyup"!==i)){if("input"===i&&w&&!k&&c===s){for(;x&&f>g&&!O(f);)f--;for(;V&&v>f&&-1===S.indexOf(f);)f++;var _=S.indexOf(f);c=c.substring(0,_)+c.substring(_+1)}for(u=m(c),z=u,Z=c,r.val(u),e.$apply(function(){a.$setViewValue(c)}),y&&g>=f&&(f=g+1),C&&f--,f=f>v?v:g>f?g:f;!O(f)&&f>g&&v>f;)f+=C?-1:1;(C&&v>f||y&&!O(h))&&f++,B=f,D(this,f)}}}function O(e){return S.indexOf(e)>-1}function A(e){if(!e)return 0;if(void 0!==e.selectionStart)return e.selectionStart;if(document.selection&&n(r[0])){e.focus();var t=document.selection.createRange();return t.moveStart("character",e.value?-e.value.length:0),t.text.length}return 0}function D(e,t){if(!e)return 0;if(0!==e.offsetWidth&&0!==e.offsetHeight)if(e.setSelectionRange)n(r[0])&&(e.focus(),e.setSelectionRange(t,t));else if(e.createTextRange){var i=e.createTextRange();i.collapse(!0),i.moveEnd("character",t),i.moveStart("character",t),i.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,_,R,T,j,q,H,z,Z,B,F,L=!1,I=!1,K=i.placeholder,N=i.maxlength,W=!1;i.$observe("modelViewValue",function(e){"true"===e&&(W=!0)});var G={};i.uiOptions?(G=e.$eval("["+i.uiOptions+"]"),G=angular.isObject(G[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,G[0]):t):G=t,i.$observe("uiMask",u),angular.isDefined(i.uiMaskPlaceholder)?i.$observe("uiMaskPlaceholder",o):i.$observe("placeholder",o),angular.isDefined(i.uiMaskPlaceholderChar)&&i.$observe("uiMaskPlaceholderChar",l),a.$formatters.push(c),a.$parsers.push(s);var J=r.val();r.bind("mousedown mouseup",M),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})}}}}])}(); |
{ | ||
"name": "angular-ui-mask", | ||
"version": "1.5.0", | ||
"version": "1.5.1", | ||
"author": "https://github.com/angular-ui/ui-mask/graphs/contributors", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -119,4 +119,4 @@ /* | ||
} else { | ||
if (angular.isObject(current[i])) { | ||
angular.extend(current[i], original[i]); | ||
if (angular.isObject(current[i]) && !angular.isArray(current[i])) { | ||
current[i] = angular.extend({}, original[i], current[i]); | ||
} | ||
@@ -128,2 +128,4 @@ } | ||
})(options, linkOptions[0]); | ||
} else { | ||
linkOptions = options; //gotta be a better way to do this.. | ||
} | ||
@@ -130,0 +132,0 @@ } else { |
@@ -5,3 +5,3 @@ describe("uiMask", function () { | ||
var formHtml = "<form name='test'><input name='input' ng-model='x' ui-mask='{{mask}}'></form>"; | ||
var inputHtml = "<input name='input' ng-model='x' ui-mask='{{mask}}'>"; | ||
var inputHtml = "<input name='input' ng-model='x' ui-mask='{{mask}}' ui-options='options'>"; | ||
var compileElement, scope, config; | ||
@@ -425,3 +425,3 @@ | ||
config.maskDefinitions["@"] = /[fz]/; | ||
var input = compileElement(inputHtml); | ||
@@ -435,11 +435,44 @@ | ||
}); | ||
it("should merge the mask definition set globally with the definition set per element", function() { | ||
scope.options = { | ||
maskDefinitions: { | ||
"A": /[A-Z]/, //make A caps only | ||
"b": /[a-z]/ //make b lowercase only | ||
} | ||
}; | ||
var input = compileElement(inputHtml); | ||
scope.$apply("x = ''"); | ||
scope.$apply("mask = '@193Ab'"); | ||
input.val("f123cCCc").triggerHandler("input"); | ||
input.triggerHandler("blur"); | ||
expect(input.val()).toBe("f123Cc"); | ||
}); | ||
it("should accept the new events to handle per element", function() { | ||
scope.options = { | ||
eventsToHandle: ['keyup'] | ||
}; | ||
var input = compileElement(inputHtml); | ||
scope.$apply("x = ''"); | ||
scope.$apply("mask = '@99-9'"); | ||
input.val("f111").triggerHandler("input focus click"); | ||
expect(input.val()).toBe("f111"); | ||
input.triggerHandler('keyup'); | ||
expect(input.val()).toBe("f11-1"); | ||
}); | ||
it("should accept the new mask definition set per element", function() { | ||
delete config.maskDefinitions["@"]; | ||
scope.input = { | ||
options: {maskDefinitions: {"@": /[fz]/}} | ||
scope.options = { | ||
maskDefinitions: {"@": /[fz]/} | ||
}; | ||
var input = compileElement(inputHtml); | ||
var input = compileElement("<input type=\"text\" ng-model=\"x\" ui-mask=\"{{mask}}\" ui-options=\"input.options\">"); | ||
scope.$apply("x = ''"); | ||
@@ -446,0 +479,0 @@ scope.$apply("mask = '@999'"); |
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
111976
1676