@justa/mask-directive
Version:
 
2 lines • 8.11 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("inputmask"),require("@angular/forms")):"function"==typeof define&&define.amd?define("@justa/mask-directive",["exports","@angular/core","inputmask","@angular/forms"],t):t(((e=e||self).justa=e.justa||{},e.justa["mask-directive"]={}),e.ng.core,e.InputMask,e.ng.forms)}(this,(function(e,t,r,n){"use strict";r=r&&r.hasOwnProperty("default")?r.default:r;function i(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,i,o=r.call(e),u=[];try{for(;(void 0===t||t-- >0)&&!(n=o.next()).done;)u.push(n.value)}catch(e){i={error:e}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return u}function o(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(i(arguments[t]));return e}var u=function(){function e(e){this.elementRef=e,this.hasDecimal=!1,this.hasPrefix=!1,this.prefixSymbol="R$ ",this.imObject={alias:"currency",autoGroup:!0,groupSeparator:".",radixPoint:",",rightAlign:!1,prefix:"R$ "},this.el=this.elementRef.nativeElement}return e.prototype.ngOnInit=function(){this.hasPrefix&&this.prefixSymbol&&(this.imObject.prefix=this.prefixSymbol),this.hasDecimal&&(this.imObject.numericInput=!0),this.im=new r(this.imObject),this.im.mask(this.el)},e.prototype.onKeyPress=function(e){console.log(e),this.restrictNumeric(e)||e.preventDefault},e.prototype.onPaste=function(e){this.onInputChange(e)},e.prototype.onChange=function(e){this.onInputChange(e)},e.prototype.onInput=function(e){this.onInputChange(e)},e.prototype.onInputChange=function(e){var t=e;"string"==typeof e&&(t.includes("R$")||t.includes("."))&&t.replace(/\D/gi,"")},e.prototype.restrictNumeric=function(e){var t;return!(!e.metaKey&&!e.ctrlKey)||32!==e.which&&(0===e.which||(e.which<33||(t=String.fromCharCode(e.which),!!/[\d\s]/.test(t))))},e.decorators=[{type:t.Directive,args:[{selector:"[jstMoneyMask]"}]}],e.ctorParameters=function(){return[{type:t.ElementRef}]},e.propDecorators={hasDecimal:[{type:t.Input}],hasPrefix:[{type:t.Input}],prefixSymbol:[{type:t.Input}],onKeyPress:[{type:t.HostListener,args:["keypress",["$event"]]}],onPaste:[{type:t.HostListener,args:["paste",["$event"]]}],onChange:[{type:t.HostListener,args:["change",["$event"]]}],onInput:[{type:t.HostListener,args:["input",["$event"]]}]},e}();new RegExp(/(?!(\d)\1{2}.\1{3}.\1{3}-\1{2})\d{3}\.\d{3}\.\d{3}\-\d{2}/gm),new RegExp(/^\d{2}.\d{3}.\d{3}\/\d{4}-\d{2}$/g);var s=[2,5],a=[8],p=[1,4],c=[7],l=[11],f=function(e){return String(e).replace(/[^\d]/g,"")},h=function(e,t){return e===t.length-1},y=function(){function e(e,t,r){this.el=e,this.renderer=t,this._control=r,this.onChange=function(e){},this.onTouched=function(){}}return e.prototype.ngOnInit=function(){var e=this.el.nativeElement.value;if(e&&e.length>0){var t=this.returnValue(e);this.writeValue(t)}},e.prototype.ngOnDestroy=function(){clearTimeout(this.writeTimeout)},Object.defineProperty(e.prototype,"control",{get:function(){return this._control.control},enumerable:!0,configurable:!0}),e.prototype.inputKeyup=function(e){var t=this.returnValue(e.target.value);this.writeValue(t),e.target.value=t},e.prototype.inputOnblur=function(e){var t=this.returnValue(e.value);this.writeValue(t),e.value=t,console.warn("This directive won't work more in Ionic into next minor version!")},e.prototype.inputFocus=function(e){var t=this.returnValue(e.value);this.writeValue(t),e.value=t,console.warn("This directive won't work more in Ionic into next minor version!")},e.prototype.focusInput=function(e){var t=this.returnValue(e.target.value);this.writeValue(t),e.target.value=t},e.prototype.blurInput=function(e){var t=this.returnValue(e.target.value);this.writeValue(t),e.target.value=t},e.prototype.ngModelChangeInput=function(e){var t=this.returnValue(e);this.writeValue(t)},e.prototype.writeValue=function(e){var t=this;this.writeTimeout=setTimeout((function(){t.renderer.setProperty(t.el.nativeElement,"value",e)}),1)},e.prototype.registerOnChange=function(e){this.onChange=e},e.prototype.registerOnTouched=function(e){this.onChange=e},e.prototype.writeValuePerson=function(e){return e.length<=11?(t=f(e)).slice(0,11).split("").reduce((function(e,r,n){var i=""+e+r;if(!h(n,t)){if(s.indexOf(n)>=0)return i+".";if(a.indexOf(n)>=0)return i+"-"}return i}),""):(r=f(e)).slice(0,14).split("").reduce((function(e,t,n){var i=""+e+t;if(!h(n,r)){if(p.includes(n))return i+".";if(c.includes(n))return i+"/";if(l.includes(n))return i+"-"}return i}),"");var t,r},e.prototype.returnValue=function(e){var t=e?e.replace(/\D/gi,""):"";return this.writeValuePerson(t)},e.decorators=[{type:t.Directive,args:[{selector:"[jstLegalDocumentMask]"}]}],e.ctorParameters=function(){return[{type:t.ElementRef},{type:t.Renderer2},{type:n.NgControl}]},e.propDecorators={inputKeyup:[{type:t.HostListener,args:["keyup",["$event"]]}],inputOnblur:[{type:t.HostListener,args:["ionBlur",["$event"]]}],inputFocus:[{type:t.HostListener,args:["ionFocus",["$event"]]}],focusInput:[{type:t.HostListener,args:["focus",["$event"]]}],blurInput:[{type:t.HostListener,args:["blur",["$event"]]}],ngModelChangeInput:[{type:t.HostListener,args:["ngModelChange",["$event"]]}]},e}();var g=function(){function e(e,t){this.elementRef=e,this.renderer=t,this.currencyMultiplier=100,this.currencyPrefix="R$ ",this.masker=new r({alias:"currency",autoGroup:!0,autoUnmask:!0,groupSeparator:".",radixPoint:",",rightAlign:!1,placeholder:"0,00",numericInput:!0,prefix:this.currencyPrefix})}return e.prototype.ngOnInit=function(){this.masker.mask(this.elementRef.nativeElement)},e.prototype.ngOnDestroy=function(){window.clearTimeout(this.rendererTimeout)},e.prototype.writeValue=function(e){var t=this,r=parseFloat(e)/this.currencyMultiplier;this.rendererTimeout=window.setTimeout((function(){t.renderer.setProperty(t.elementRef.nativeElement,"value",r)}),0)},e.prototype.registerOnChange=function(e){this.onChange=e},e.prototype.registerOnTouched=function(e){this.onTouched=e},e.prototype.setDisabledState=function(e){this.renderer.setProperty(this.elementRef.nativeElement,"disabled",e)},e.prototype.onInputBlur=function(e){var t=parseFloat(e.target.value.replace(",","."))*this.currencyMultiplier;this.onChange(t)},e.decorators=[{type:t.Directive,args:[{selector:"[jstCurrencyMask]",providers:[{provide:n.NG_VALUE_ACCESSOR,useExisting:t.forwardRef((function(){return e})),multi:!0}]}]}],e.ctorParameters=function(){return[{type:t.ElementRef},{type:t.Renderer2}]},e.propDecorators={currencyMultiplier:[{type:t.Input}],currencyPrefix:[{type:t.Input}],onInputBlur:[{type:t.HostListener,args:["blur",["$event"]]}]},e}();var d=function(){function e(e,t){this.elementRef=e,this.renderer=t,this.percentSuffix=" %",this.mask=new r({alias:"percentage",autoGroup:!1,autoUnmask:!0,radixPoint:",",rightAlign:!1,placeHolder:"0,00",numericInput:!0,digits:2,suffix:this.percentSuffix})}return e.prototype.ngOnInit=function(){this.mask.mask(this.elementRef.nativeElement)},e.prototype.ngOnDestroy=function(){window.clearTimeout(this.rendererTimeout)},e.prototype.writeValue=function(e){var t=this,r=100*parseFloat(e);this.rendererTimeout=window.setTimeout((function(){t.renderer.setProperty(t.elementRef.nativeElement,"value",r)}),0)},e.prototype.registerOnChange=function(e){this.onChange=e},e.prototype.registerOnTouched=function(e){this.onTouched=e},e.prototype.onInputBlur=function(e){var t=parseFloat(e.target.value.replace(",","."))/100;this.onChange(t)},e.decorators=[{type:t.Directive,args:[{selector:"[jstPercentageMask]",providers:[{provide:n.NG_VALUE_ACCESSOR,useExisting:t.forwardRef((function(){return e})),multi:!0}]}]}],e.ctorParameters=function(){return[{type:t.ElementRef},{type:t.Renderer2}]},e.propDecorators={percentSuffix:[{type:t.Input}],onInputBlur:[{type:t.HostListener,args:["blur",["$event"]]}]},e}();var m=[u,y,g,d],v=function(){function e(){}return e.decorators=[{type:t.NgModule,args:[{declarations:o(m),imports:[],exports:o(m)}]}],e}();e.MaskDirectiveModule=v,e.ɵa=u,e.ɵb=y,e.ɵc=g,e.ɵd=d,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=justa-mask-directive.umd.min.js.map