UNPKG

4.66 kBJavaScriptView Raw
1!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/common"),require("primeng/dom")):"function"==typeof define&&define.amd?define("primeng/password",["exports","@angular/core","@angular/common","primeng/dom"],t):t(((e=e||self).primeng=e.primeng||{},e.primeng.password={}),e.ng.core,e.ng.common,e.primeng.dom)}(this,(function(e,t,n,o){"use strict";var i=this&&this.__decorate||function(e,t,n,o){var i,r=arguments.length,s=r<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,o);else for(var l=e.length-1;l>=0;l--)(i=e[l])&&(s=(r<3?i(s):r>3?i(t,n,s):i(t,n))||s);return r>3&&s&&Object.defineProperty(t,n,s),s},r=function(){function e(e,t){this.el=e,this.zone=t,this.promptLabel="Enter a password",this.weakLabel="Weak",this.mediumLabel="Medium",this.strongLabel="Strong",this.feedback=!0}return Object.defineProperty(e.prototype,"showPassword",{set:function(e){this.el.nativeElement.type=e?"text":"password"},enumerable:!0,configurable:!0}),e.prototype.ngDoCheck=function(){this.updateFilledState()},e.prototype.onInput=function(e){this.updateFilledState()},e.prototype.updateFilledState=function(){this.filled=this.el.nativeElement.value&&this.el.nativeElement.value.length},e.prototype.createPanel=function(){this.panel=document.createElement("div"),this.panel.className="ui-password-panel ui-widget ui-state-highlight ui-corner-all",this.meter=document.createElement("div"),this.meter.className="ui-password-meter",this.info=document.createElement("div"),this.info.className="ui-password-info",this.info.textContent=this.promptLabel,this.panel.appendChild(this.meter),this.panel.appendChild(this.info),this.panel.style.minWidth=o.DomHandler.getOuterWidth(this.el.nativeElement)+"px",document.body.appendChild(this.panel)},e.prototype.onFocus=function(e){var t=this;this.feedback&&(this.panel||this.createPanel(),this.panel.style.zIndex=String(++o.DomHandler.zindex),this.zone.runOutsideAngular((function(){setTimeout((function(){o.DomHandler.addClass(t.panel,"ui-password-panel-visible"),o.DomHandler.removeClass(t.panel,"ui-password-panel-hidden")}),1),o.DomHandler.absolutePosition(t.panel,t.el.nativeElement)})))},e.prototype.onBlur=function(e){var t=this;this.feedback&&(o.DomHandler.addClass(this.panel,"ui-password-panel-hidden"),o.DomHandler.removeClass(this.panel,"ui-password-panel-visible"),this.zone.runOutsideAngular((function(){setTimeout((function(){t.ngOnDestroy()}),150)})))},e.prototype.onKeyup=function(e){if(this.feedback){var t=e.target.value,n=null,o=null;if(0===t.length)n=this.promptLabel,o="0px 0px";else{var i=this.testStrength(t);i<30?(n=this.weakLabel,o="0px -10px"):i>=30&&i<80?(n=this.mediumLabel,o="0px -20px"):i>=80&&(n=this.strongLabel,o="0px -30px")}this.meter.style.backgroundPosition=o,this.info.textContent=n}},e.prototype.testStrength=function(e){var t,n=0;return t=e.match("[0-9]"),n+=25*this.normalize(t?t.length:.25,1),t=e.match("[a-zA-Z]"),n+=10*this.normalize(t?t.length:.5,3),t=e.match("[!@#$%^&*?_~.,;=]"),n+=35*this.normalize(t?t.length:1/6,1),t=e.match("[A-Z]"),n+=30*this.normalize(t?t.length:1/6,1),(n*=e.length/8)>100?100:n},e.prototype.normalize=function(e,t){return e-t<=0?e/t:1+e/(e+t/4)*.5},Object.defineProperty(e.prototype,"disabled",{get:function(){return this.el.nativeElement.disabled},enumerable:!0,configurable:!0}),e.prototype.ngOnDestroy=function(){this.panel&&(document.body.removeChild(this.panel),this.panel=null,this.meter=null,this.info=null)},e.ctorParameters=function(){return[{type:t.ElementRef},{type:t.NgZone}]},i([t.Input()],e.prototype,"promptLabel",void 0),i([t.Input()],e.prototype,"weakLabel",void 0),i([t.Input()],e.prototype,"mediumLabel",void 0),i([t.Input()],e.prototype,"strongLabel",void 0),i([t.Input()],e.prototype,"feedback",void 0),i([t.Input()],e.prototype,"showPassword",null),i([t.HostListener("input",["$event"])],e.prototype,"onInput",null),i([t.HostListener("focus",["$event"])],e.prototype,"onFocus",null),i([t.HostListener("blur",["$event"])],e.prototype,"onBlur",null),i([t.HostListener("keyup",["$event"])],e.prototype,"onKeyup",null),e=i([t.Directive({selector:"[pPassword]",host:{"[class.ui-inputtext]":"true","[class.ui-corner-all]":"true","[class.ui-state-default]":"true","[class.ui-widget]":"true","[class.ui-state-filled]":"filled"}})],e)}(),s=function(){function e(){}return e=i([t.NgModule({imports:[n.CommonModule],exports:[r],declarations:[r]})],e)}();e.Password=r,e.PasswordModule=s,Object.defineProperty(e,"__esModule",{value:!0})}));
2//# sourceMappingURL=primeng-password.umd.min.js.map
\No newline at end of file