1 | (function (global, factory) {
|
2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('primeng/dom')) :
|
3 | typeof define === 'function' && define.amd ? define('primeng/password', ['exports', '@angular/core', '@angular/common', 'primeng/dom'], factory) :
|
4 | (global = global || self, factory((global.primeng = global.primeng || {}, global.primeng.password = {}), global.ng.core, global.ng.common, global.primeng.dom));
|
5 | }(this, (function (exports, core, common, dom) { 'use strict';
|
6 |
|
7 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
8 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
9 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
10 | 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;
|
11 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
12 | };
|
13 | var Password = (function () {
|
14 | function Password(el, zone) {
|
15 | this.el = el;
|
16 | this.zone = zone;
|
17 | this.promptLabel = 'Enter a password';
|
18 | this.weakLabel = 'Weak';
|
19 | this.mediumLabel = 'Medium';
|
20 | this.strongLabel = 'Strong';
|
21 | this.feedback = true;
|
22 | }
|
23 | Object.defineProperty(Password.prototype, "showPassword", {
|
24 | set: function (show) {
|
25 | this.el.nativeElement.type = show ? 'text' : 'password';
|
26 | },
|
27 | enumerable: true,
|
28 | configurable: true
|
29 | });
|
30 | Password.prototype.ngDoCheck = function () {
|
31 | this.updateFilledState();
|
32 | };
|
33 |
|
34 | Password.prototype.onInput = function (e) {
|
35 | this.updateFilledState();
|
36 | };
|
37 | Password.prototype.updateFilledState = function () {
|
38 | this.filled = this.el.nativeElement.value && this.el.nativeElement.value.length;
|
39 | };
|
40 | Password.prototype.createPanel = function () {
|
41 | this.panel = document.createElement('div');
|
42 | this.panel.className = 'ui-password-panel ui-widget ui-state-highlight ui-corner-all';
|
43 | this.meter = document.createElement('div');
|
44 | this.meter.className = 'ui-password-meter';
|
45 | this.info = document.createElement('div');
|
46 | this.info.className = 'ui-password-info';
|
47 | this.info.textContent = this.promptLabel;
|
48 | this.panel.appendChild(this.meter);
|
49 | this.panel.appendChild(this.info);
|
50 | this.panel.style.minWidth = dom.DomHandler.getOuterWidth(this.el.nativeElement) + 'px';
|
51 | document.body.appendChild(this.panel);
|
52 | };
|
53 | Password.prototype.onFocus = function (e) {
|
54 | var _this = this;
|
55 | if (this.feedback) {
|
56 | if (!this.panel) {
|
57 | this.createPanel();
|
58 | }
|
59 | this.panel.style.zIndex = String(++dom.DomHandler.zindex);
|
60 | this.zone.runOutsideAngular(function () {
|
61 | setTimeout(function () {
|
62 | dom.DomHandler.addClass(_this.panel, 'ui-password-panel-visible');
|
63 | dom.DomHandler.removeClass(_this.panel, 'ui-password-panel-hidden');
|
64 | }, 1);
|
65 | dom.DomHandler.absolutePosition(_this.panel, _this.el.nativeElement);
|
66 | });
|
67 | }
|
68 | };
|
69 | Password.prototype.onBlur = function (e) {
|
70 | var _this = this;
|
71 | if (this.feedback) {
|
72 | dom.DomHandler.addClass(this.panel, 'ui-password-panel-hidden');
|
73 | dom.DomHandler.removeClass(this.panel, 'ui-password-panel-visible');
|
74 | this.zone.runOutsideAngular(function () {
|
75 | setTimeout(function () {
|
76 | _this.ngOnDestroy();
|
77 | }, 150);
|
78 | });
|
79 | }
|
80 | };
|
81 | Password.prototype.onKeyup = function (e) {
|
82 | if (this.feedback) {
|
83 | var value = e.target.value, label = null, meterPos = null;
|
84 | if (value.length === 0) {
|
85 | label = this.promptLabel;
|
86 | meterPos = '0px 0px';
|
87 | }
|
88 | else {
|
89 | var score = this.testStrength(value);
|
90 | if (score < 30) {
|
91 | label = this.weakLabel;
|
92 | meterPos = '0px -10px';
|
93 | }
|
94 | else if (score >= 30 && score < 80) {
|
95 | label = this.mediumLabel;
|
96 | meterPos = '0px -20px';
|
97 | }
|
98 | else if (score >= 80) {
|
99 | label = this.strongLabel;
|
100 | meterPos = '0px -30px';
|
101 | }
|
102 | }
|
103 | this.meter.style.backgroundPosition = meterPos;
|
104 | this.info.textContent = label;
|
105 | }
|
106 | };
|
107 | Password.prototype.testStrength = function (str) {
|
108 | var grade = 0;
|
109 | var val;
|
110 | val = str.match('[0-9]');
|
111 | grade += this.normalize(val ? val.length : 1 / 4, 1) * 25;
|
112 | val = str.match('[a-zA-Z]');
|
113 | grade += this.normalize(val ? val.length : 1 / 2, 3) * 10;
|
114 | val = str.match('[!@#$%^&*?_~.,;=]');
|
115 | grade += this.normalize(val ? val.length : 1 / 6, 1) * 35;
|
116 | val = str.match('[A-Z]');
|
117 | grade += this.normalize(val ? val.length : 1 / 6, 1) * 30;
|
118 | grade *= str.length / 8;
|
119 | return grade > 100 ? 100 : grade;
|
120 | };
|
121 | Password.prototype.normalize = function (x, y) {
|
122 | var diff = x - y;
|
123 | if (diff <= 0)
|
124 | return x / y;
|
125 | else
|
126 | return 1 + 0.5 * (x / (x + y / 4));
|
127 | };
|
128 | Object.defineProperty(Password.prototype, "disabled", {
|
129 | get: function () {
|
130 | return this.el.nativeElement.disabled;
|
131 | },
|
132 | enumerable: true,
|
133 | configurable: true
|
134 | });
|
135 | Password.prototype.ngOnDestroy = function () {
|
136 | if (this.panel) {
|
137 | document.body.removeChild(this.panel);
|
138 | this.panel = null;
|
139 | this.meter = null;
|
140 | this.info = null;
|
141 | }
|
142 | };
|
143 | Password.ctorParameters = function () { return [
|
144 | { type: core.ElementRef },
|
145 | { type: core.NgZone }
|
146 | ]; };
|
147 | __decorate([
|
148 | core.Input()
|
149 | ], Password.prototype, "promptLabel", void 0);
|
150 | __decorate([
|
151 | core.Input()
|
152 | ], Password.prototype, "weakLabel", void 0);
|
153 | __decorate([
|
154 | core.Input()
|
155 | ], Password.prototype, "mediumLabel", void 0);
|
156 | __decorate([
|
157 | core.Input()
|
158 | ], Password.prototype, "strongLabel", void 0);
|
159 | __decorate([
|
160 | core.Input()
|
161 | ], Password.prototype, "feedback", void 0);
|
162 | __decorate([
|
163 | core.Input()
|
164 | ], Password.prototype, "showPassword", null);
|
165 | __decorate([
|
166 | core.HostListener('input', ['$event'])
|
167 | ], Password.prototype, "onInput", null);
|
168 | __decorate([
|
169 | core.HostListener('focus', ['$event'])
|
170 | ], Password.prototype, "onFocus", null);
|
171 | __decorate([
|
172 | core.HostListener('blur', ['$event'])
|
173 | ], Password.prototype, "onBlur", null);
|
174 | __decorate([
|
175 | core.HostListener('keyup', ['$event'])
|
176 | ], Password.prototype, "onKeyup", null);
|
177 | Password = __decorate([
|
178 | core.Directive({
|
179 | selector: '[pPassword]',
|
180 | host: {
|
181 | '[class.ui-inputtext]': 'true',
|
182 | '[class.ui-corner-all]': 'true',
|
183 | '[class.ui-state-default]': 'true',
|
184 | '[class.ui-widget]': 'true',
|
185 | '[class.ui-state-filled]': 'filled'
|
186 | }
|
187 | })
|
188 | ], Password);
|
189 | return Password;
|
190 | }());
|
191 | var PasswordModule = (function () {
|
192 | function PasswordModule() {
|
193 | }
|
194 | PasswordModule = __decorate([
|
195 | core.NgModule({
|
196 | imports: [common.CommonModule],
|
197 | exports: [Password],
|
198 | declarations: [Password]
|
199 | })
|
200 | ], PasswordModule);
|
201 | return PasswordModule;
|
202 | }());
|
203 |
|
204 | exports.Password = Password;
|
205 | exports.PasswordModule = PasswordModule;
|
206 |
|
207 | Object.defineProperty(exports, '__esModule', { value: true });
|
208 |
|
209 | })));
|
210 |
|