| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- var __metadata = (this && this.__metadata) || function (k, v) {
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var core_1 = require("@angular/core");
- var common_1 = require("@angular/common");
- var domhandler_1 = require("../dom/domhandler");
- var Password = /** @class */ (function () {
- function Password(el, zone) {
- this.el = el;
- this.zone = zone;
- this.promptLabel = 'Enter a password';
- this.weakLabel = 'Weak';
- this.mediumLabel = 'Medium';
- this.strongLabel = 'Strong';
- this.feedback = true;
- }
- Object.defineProperty(Password.prototype, "showPassword", {
- set: function (show) {
- this.el.nativeElement.type = show ? 'text' : 'password';
- },
- enumerable: true,
- configurable: true
- });
- Password.prototype.ngDoCheck = function () {
- this.updateFilledState();
- };
- //To trigger change detection to manage ui-state-filled for material labels when there is no value binding
- Password.prototype.onInput = function (e) {
- this.updateFilledState();
- };
- Password.prototype.updateFilledState = function () {
- this.filled = this.el.nativeElement.value && this.el.nativeElement.value.length;
- };
- Password.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 = domhandler_1.DomHandler.getOuterWidth(this.el.nativeElement) + 'px';
- document.body.appendChild(this.panel);
- };
- Password.prototype.onFocus = function (e) {
- var _this = this;
- if (this.feedback) {
- if (!this.panel) {
- this.createPanel();
- }
- this.panel.style.zIndex = String(++domhandler_1.DomHandler.zindex);
- this.zone.runOutsideAngular(function () {
- setTimeout(function () {
- domhandler_1.DomHandler.addClass(_this.panel, 'ui-password-panel-visible');
- domhandler_1.DomHandler.removeClass(_this.panel, 'ui-password-panel-hidden');
- }, 1);
- domhandler_1.DomHandler.absolutePosition(_this.panel, _this.el.nativeElement);
- });
- }
- };
- Password.prototype.onBlur = function (e) {
- var _this = this;
- if (this.feedback) {
- domhandler_1.DomHandler.addClass(this.panel, 'ui-password-panel-hidden');
- domhandler_1.DomHandler.removeClass(this.panel, 'ui-password-panel-visible');
- this.zone.runOutsideAngular(function () {
- setTimeout(function () {
- _this.ngOnDestroy();
- }, 150);
- });
- }
- };
- Password.prototype.onKeyup = function (e) {
- if (this.feedback) {
- var value = e.target.value, label = null, meterPos = null;
- if (value.length === 0) {
- label = this.promptLabel;
- meterPos = '0px 0px';
- }
- else {
- var score = this.testStrength(value);
- if (score < 30) {
- label = this.weakLabel;
- meterPos = '0px -10px';
- }
- else if (score >= 30 && score < 80) {
- label = this.mediumLabel;
- meterPos = '0px -20px';
- }
- else if (score >= 80) {
- label = this.strongLabel;
- meterPos = '0px -30px';
- }
- }
- this.meter.style.backgroundPosition = meterPos;
- this.info.textContent = label;
- }
- };
- Password.prototype.testStrength = function (str) {
- var grade = 0;
- var val;
- val = str.match('[0-9]');
- grade += this.normalize(val ? val.length : 1 / 4, 1) * 25;
- val = str.match('[a-zA-Z]');
- grade += this.normalize(val ? val.length : 1 / 2, 3) * 10;
- val = str.match('[!@#$%^&*?_~.,;=]');
- grade += this.normalize(val ? val.length : 1 / 6, 1) * 35;
- val = str.match('[A-Z]');
- grade += this.normalize(val ? val.length : 1 / 6, 1) * 30;
- grade *= str.length / 8;
- return grade > 100 ? 100 : grade;
- };
- Password.prototype.normalize = function (x, y) {
- var diff = x - y;
- if (diff <= 0)
- return x / y;
- else
- return 1 + 0.5 * (x / (x + y / 4));
- };
- Object.defineProperty(Password.prototype, "disabled", {
- get: function () {
- return this.el.nativeElement.disabled;
- },
- enumerable: true,
- configurable: true
- });
- Password.prototype.ngOnDestroy = function () {
- if (this.panel) {
- document.body.removeChild(this.panel);
- this.panel = null;
- this.meter = null;
- this.info = null;
- }
- };
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Password.prototype, "promptLabel", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Password.prototype, "weakLabel", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Password.prototype, "mediumLabel", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Password.prototype, "strongLabel", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean)
- ], Password.prototype, "feedback", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean),
- __metadata("design:paramtypes", [Boolean])
- ], Password.prototype, "showPassword", null);
- __decorate([
- core_1.HostListener('input', ['$event']),
- __metadata("design:type", Function),
- __metadata("design:paramtypes", [Object]),
- __metadata("design:returntype", void 0)
- ], Password.prototype, "onInput", null);
- __decorate([
- core_1.HostListener('focus', ['$event']),
- __metadata("design:type", Function),
- __metadata("design:paramtypes", [Object]),
- __metadata("design:returntype", void 0)
- ], Password.prototype, "onFocus", null);
- __decorate([
- core_1.HostListener('blur', ['$event']),
- __metadata("design:type", Function),
- __metadata("design:paramtypes", [Object]),
- __metadata("design:returntype", void 0)
- ], Password.prototype, "onBlur", null);
- __decorate([
- core_1.HostListener('keyup', ['$event']),
- __metadata("design:type", Function),
- __metadata("design:paramtypes", [Object]),
- __metadata("design:returntype", void 0)
- ], Password.prototype, "onKeyup", null);
- Password = __decorate([
- core_1.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'
- }
- }),
- __metadata("design:paramtypes", [core_1.ElementRef, core_1.NgZone])
- ], Password);
- return Password;
- }());
- exports.Password = Password;
- var PasswordModule = /** @class */ (function () {
- function PasswordModule() {
- }
- PasswordModule = __decorate([
- core_1.NgModule({
- imports: [common_1.CommonModule],
- exports: [Password],
- declarations: [Password]
- })
- ], PasswordModule);
- return PasswordModule;
- }());
- exports.PasswordModule = PasswordModule;
- //# sourceMappingURL=password.js.map
|