UNPKG

11.8 kBJavaScriptView Raw
1!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/common"),require("primeng/dom"),require("primeng/inputtext"),require("@angular/forms")):"function"==typeof define&&define.amd?define("primeng/inputmask",["exports","@angular/core","@angular/common","primeng/dom","primeng/inputtext","@angular/forms"],e):e(((t=t||self).primeng=t.primeng||{},t.primeng.inputmask={}),t.ng.core,t.ng.common,t.primeng.dom,t.primeng.inputtext,t.ng.forms)}(this,(function(t,e,i,n,o,s){"use strict";var r=this&&this.__decorate||function(t,e,i,n){var o,s=arguments.length,r=s<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,n);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(r=(s<3?o(r):s>3?o(e,i,r):o(e,i))||r);return s>3&&r&&Object.defineProperty(e,i,r),r},a={provide:s.NG_VALUE_ACCESSOR,useExisting:e.forwardRef((function(){return h})),multi:!0},h=function(){function t(t){this.el=t,this.type="text",this.slotChar="_",this.autoClear=!0,this.characterPattern="[A-Za-z]",this.onComplete=new e.EventEmitter,this.onFocus=new e.EventEmitter,this.onBlur=new e.EventEmitter,this.onInput=new e.EventEmitter,this.onModelChange=function(){},this.onModelTouched=function(){}}return t.prototype.ngOnInit=function(){var t=n.DomHandler.getUserAgent();this.androidChrome=/chrome/i.test(t)&&/android/i.test(t),this.initMask()},Object.defineProperty(t.prototype,"mask",{get:function(){return this._mask},set:function(t){this._mask=t,this.initMask(),this.writeValue(""),this.onModelChange(this.value)},enumerable:!0,configurable:!0}),t.prototype.initMask=function(){this.tests=[],this.partialPosition=this.mask.length,this.len=this.mask.length,this.firstNonMaskPos=null,this.defs={9:"[0-9]",a:this.characterPattern,"*":this.characterPattern+"|[0-9]"};for(var t=this.mask.split(""),e=0;e<t.length;e++){"?"==(i=t[e])?(this.len--,this.partialPosition=e):this.defs[i]?(this.tests.push(new RegExp(this.defs[i])),null===this.firstNonMaskPos&&(this.firstNonMaskPos=this.tests.length-1),e<this.partialPosition&&(this.lastRequiredNonMaskPos=this.tests.length-1)):this.tests.push(null)}this.buffer=[];for(e=0;e<t.length;e++){var i;"?"!=(i=t[e])&&(this.defs[i]?this.buffer.push(this.getPlaceholder(e)):this.buffer.push(i))}this.defaultBuffer=this.buffer.join("")},t.prototype.writeValue=function(t){this.value=t,this.inputViewChild&&this.inputViewChild.nativeElement&&(null==this.value||null==this.value?this.inputViewChild.nativeElement.value="":this.inputViewChild.nativeElement.value=this.value,this.checkVal(),this.focusText=this.inputViewChild.nativeElement.value,this.updateFilledState())},t.prototype.registerOnChange=function(t){this.onModelChange=t},t.prototype.registerOnTouched=function(t){this.onModelTouched=t},t.prototype.setDisabledState=function(t){this.disabled=t},t.prototype.caret=function(t,e){var i,n,o;if(this.inputViewChild.nativeElement.offsetParent&&this.inputViewChild.nativeElement===document.activeElement)return"number"!=typeof t?(this.inputViewChild.nativeElement.setSelectionRange?(n=this.inputViewChild.nativeElement.selectionStart,o=this.inputViewChild.nativeElement.selectionEnd):document.selection&&document.selection.createRange&&(o=(n=0-(i=document.selection.createRange()).duplicate().moveStart("character",-1e5))+i.text.length),{begin:n,end:o}):(n=t,o="number"==typeof e?e:n,void(this.inputViewChild.nativeElement.setSelectionRange?this.inputViewChild.nativeElement.setSelectionRange(n,o):this.inputViewChild.nativeElement.createTextRange&&((i=this.inputViewChild.nativeElement.createTextRange()).collapse(!0),i.moveEnd("character",o),i.moveStart("character",n),i.select())))},t.prototype.isCompleted=function(){for(var t=this.firstNonMaskPos;t<=this.lastRequiredNonMaskPos;t++)if(this.tests[t]&&this.buffer[t]===this.getPlaceholder(t))return!1;return!0},t.prototype.getPlaceholder=function(t){return t<this.slotChar.length?this.slotChar.charAt(t):this.slotChar.charAt(0)},t.prototype.seekNext=function(t){for(;++t<this.len&&!this.tests[t];);return t},t.prototype.seekPrev=function(t){for(;--t>=0&&!this.tests[t];);return t},t.prototype.shiftL=function(t,e){var i,n;if(!(t<0)){for(i=t,n=this.seekNext(e);i<this.len;i++)if(this.tests[i]){if(!(n<this.len&&this.tests[i].test(this.buffer[n])))break;this.buffer[i]=this.buffer[n],this.buffer[n]=this.getPlaceholder(n),n=this.seekNext(n)}this.writeBuffer(),this.caret(Math.max(this.firstNonMaskPos,t))}},t.prototype.shiftR=function(t){var e,i,n,o;for(e=t,i=this.getPlaceholder(t);e<this.len;e++)if(this.tests[e]){if(n=this.seekNext(e),o=this.buffer[e],this.buffer[e]=i,!(n<this.len&&this.tests[n].test(o)))break;i=o}},t.prototype.handleAndroidInput=function(t){var e=this,i=this.inputViewChild.nativeElement.value,n=this.caret();if(this.oldVal&&this.oldVal.length&&this.oldVal.length>i.length){for(this.checkVal(!0);n.begin>0&&!this.tests[n.begin-1];)n.begin--;if(0===n.begin)for(;n.begin<this.firstNonMaskPos&&!this.tests[n.begin];)n.begin++;setTimeout((function(){e.caret(n.begin,n.begin),e.updateModel(t),e.isCompleted()&&e.onComplete.emit()}),0)}else{for(this.checkVal(!0);n.begin<this.len&&!this.tests[n.begin];)n.begin++;setTimeout((function(){e.caret(n.begin,n.begin),e.updateModel(t),e.isCompleted()&&e.onComplete.emit()}),0)}},t.prototype.onInputBlur=function(t){if(this.focused=!1,this.onModelTouched(),this.checkVal(),this.updateFilledState(),this.onBlur.emit(t),this.inputViewChild.nativeElement.value!=this.focusText||this.inputViewChild.nativeElement.value!=this.value){this.updateModel(t);var e=document.createEvent("HTMLEvents");e.initEvent("change",!0,!1),this.inputViewChild.nativeElement.dispatchEvent(e)}},t.prototype.onKeyDown=function(t){if(!this.readonly){var e,i,o,s=t.which||t.keyCode,r=/iphone/i.test(n.DomHandler.getUserAgent());this.oldVal=this.inputViewChild.nativeElement.value,8===s||46===s||r&&127===s?(i=(e=this.caret()).begin,(o=e.end)-i==0&&(i=46!==s?this.seekPrev(i):o=this.seekNext(i-1),o=46===s?this.seekNext(o):o),this.clearBuffer(i,o),this.shiftL(i,o-1),this.updateModel(t),this.onInput.emit(t),t.preventDefault()):13===s?(this.onInputBlur(t),this.updateModel(t)):27===s&&(this.inputViewChild.nativeElement.value=this.focusText,this.caret(0,this.checkVal()),this.updateModel(t),t.preventDefault())}},t.prototype.onKeyPress=function(t){var e=this;if(!this.readonly){var i,o,s,r,a=t.which||t.keyCode,h=this.caret();if(!(t.ctrlKey||t.altKey||t.metaKey||a<32||a>34&&a<41)){if(a&&13!==a){if(h.end-h.begin!=0&&(this.clearBuffer(h.begin,h.end),this.shiftL(h.begin,h.end-1)),(i=this.seekNext(h.begin-1))<this.len&&(o=String.fromCharCode(a),this.tests[i].test(o))){if(this.shiftR(i),this.buffer[i]=o,this.writeBuffer(),s=this.seekNext(i),/android/i.test(n.DomHandler.getUserAgent())){setTimeout((function(){e.caret(s)}),0)}else this.caret(s);h.begin<=this.lastRequiredNonMaskPos&&(r=this.isCompleted()),this.onInput.emit(t)}t.preventDefault()}this.updateModel(t),this.updateFilledState(),r&&this.onComplete.emit()}}},t.prototype.clearBuffer=function(t,e){var i;for(i=t;i<e&&i<this.len;i++)this.tests[i]&&(this.buffer[i]=this.getPlaceholder(i))},t.prototype.writeBuffer=function(){this.inputViewChild.nativeElement.value=this.buffer.join("")},t.prototype.checkVal=function(t){var e,i,n,o=this.inputViewChild.nativeElement.value,s=-1;for(e=0,n=0;e<this.len;e++)if(this.tests[e]){for(this.buffer[e]=this.getPlaceholder(e);n++<o.length;)if(i=o.charAt(n-1),this.tests[e].test(i)){this.buffer[e]=i,s=e;break}if(n>o.length){this.clearBuffer(e+1,this.len);break}}else this.buffer[e]===o.charAt(n)&&n++,e<this.partialPosition&&(s=e);return t?this.writeBuffer():s+1<this.partialPosition?this.autoClear||this.buffer.join("")===this.defaultBuffer?(this.inputViewChild.nativeElement.value&&(this.inputViewChild.nativeElement.value=""),this.clearBuffer(0,this.len)):this.writeBuffer():(this.writeBuffer(),this.inputViewChild.nativeElement.value=this.inputViewChild.nativeElement.value.substring(0,s+1)),this.partialPosition?e:this.firstNonMaskPos},t.prototype.onInputFocus=function(t){var e,i=this;this.readonly||(this.focused=!0,clearTimeout(this.caretTimeoutId),this.focusText=this.inputViewChild.nativeElement.value,e=this.checkVal(),this.caretTimeoutId=setTimeout((function(){i.inputViewChild.nativeElement===document.activeElement&&(i.writeBuffer(),e==i.mask.replace("?","").length?i.caret(0,e):i.caret(e))}),10),this.onFocus.emit(t))},t.prototype.onInputChange=function(t){this.androidChrome?this.handleAndroidInput(t):this.handleInputChange(t),this.onInput.emit(t)},t.prototype.handleInputChange=function(t){var e=this;this.readonly||setTimeout((function(){var i=e.checkVal(!0);e.caret(i),e.updateModel(t),e.isCompleted()&&e.onComplete.emit()}),0)},t.prototype.getUnmaskedValue=function(){for(var t=[],e=0;e<this.buffer.length;e++){var i=this.buffer[e];this.tests[e]&&i!=this.getPlaceholder(e)&&t.push(i)}return t.join("")},t.prototype.updateModel=function(t){var e=this.unmask?this.getUnmaskedValue():t.target.value;null===e&&void 0===e||(this.value=e,this.onModelChange(this.value))},t.prototype.updateFilledState=function(){this.filled=this.inputViewChild.nativeElement&&""!=this.inputViewChild.nativeElement.value},t.prototype.focus=function(){this.inputViewChild.nativeElement.focus()},t.prototype.ngOnDestroy=function(){},t.ctorParameters=function(){return[{type:e.ElementRef}]},r([e.Input()],t.prototype,"type",void 0),r([e.Input()],t.prototype,"slotChar",void 0),r([e.Input()],t.prototype,"autoClear",void 0),r([e.Input()],t.prototype,"style",void 0),r([e.Input()],t.prototype,"inputId",void 0),r([e.Input()],t.prototype,"styleClass",void 0),r([e.Input()],t.prototype,"placeholder",void 0),r([e.Input()],t.prototype,"size",void 0),r([e.Input()],t.prototype,"maxlength",void 0),r([e.Input()],t.prototype,"tabindex",void 0),r([e.Input()],t.prototype,"title",void 0),r([e.Input()],t.prototype,"ariaLabel",void 0),r([e.Input()],t.prototype,"ariaRequired",void 0),r([e.Input()],t.prototype,"disabled",void 0),r([e.Input()],t.prototype,"readonly",void 0),r([e.Input()],t.prototype,"unmask",void 0),r([e.Input()],t.prototype,"name",void 0),r([e.Input()],t.prototype,"required",void 0),r([e.Input()],t.prototype,"characterPattern",void 0),r([e.Input()],t.prototype,"autoFocus",void 0),r([e.Input()],t.prototype,"autocomplete",void 0),r([e.ViewChild("input")],t.prototype,"inputViewChild",void 0),r([e.Output()],t.prototype,"onComplete",void 0),r([e.Output()],t.prototype,"onFocus",void 0),r([e.Output()],t.prototype,"onBlur",void 0),r([e.Output()],t.prototype,"onInput",void 0),r([e.Input()],t.prototype,"mask",null),t=r([e.Component({selector:"p-inputMask",template:'<input #input pInputText [attr.id]="inputId" [attr.type]="type" [attr.name]="name" [ngStyle]="style" [ngClass]="styleClass" [attr.placeholder]="placeholder" [attr.title]="title"\n [attr.size]="size" [attr.autocomplete]="autocomplete" [attr.maxlength]="maxlength" [attr.tabindex]="tabindex" [attr.aria-label]="ariaLabel" [attr.aria-required]="ariaRequired" [disabled]="disabled" [readonly]="readonly" [attr.required]="required"\n (focus)="onInputFocus($event)" (blur)="onInputBlur($event)" (keydown)="onKeyDown($event)" (keypress)="onKeyPress($event)" [attr.autofocus]="autoFocus"\n (input)="onInputChange($event)" (paste)="handleInputChange($event)">',host:{"[class.ui-inputwrapper-filled]":"filled","[class.ui-inputwrapper-focus]":"focused"},providers:[a],changeDetection:e.ChangeDetectionStrategy.Default})],t)}(),u=function(){function t(){}return t=r([e.NgModule({imports:[i.CommonModule,o.InputTextModule],exports:[h],declarations:[h]})],t)}();t.INPUTMASK_VALUE_ACCESSOR=a,t.InputMask=h,t.InputMaskModule=u,Object.defineProperty(t,"__esModule",{value:!0})}));
2//# sourceMappingURL=primeng-inputmask.umd.min.js.map
\No newline at end of file