-
Notifications
You must be signed in to change notification settings - Fork 1
/
angular-displayable-password.js
70 lines (62 loc) · 1.88 KB
/
angular-displayable-password.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
'use strict';
angular.module('mchambaud.angular-displayable-password', [])
.directive('displayablePassword', function () {
return {
restrict: 'E',
replace: true,
scope: {
password:'=ngModel',
required:'=ngRequired',
minLength: '=ngMinlength',
maxLength: '=ngMaxlength',
pattern: '=ngPattern',
placeholder:'@',
name: '@',
labelVisible: '@',
labelHidden: '@'
},
template: '<div class="angular-displayable-password">' +
'<input type="text"' +
'placeholder="{{placeholder}}"' +
'ng-hide="isVisible"' +
'ng-model="visiblePassword"> ' +
'<input input-change-notifier id="inputPassword" type="password"' +
'placeholder="{{placeholder}}"' +
'name="{{name}}"' +
'ng-show="isVisible"' +
'ng-model="password"' +
'ng-model-options="{ updateOn: \'change blur\' }"' +
'ng-required="required"' +
'ng-maxlength="maxLength"' +
'ng-minlength="minLength"' +
'ng-pattern="pattern"> ' +
'<input type="checkbox" id="display-password" ' +
'ng-click="isVisible = !isVisible"> ' +
'<label for="display-password" title="{{isVisible ? labelVisible : labelHidden}}">{{isVisible ? labelVisible : labelHidden}}</label>' +
'</div>',
controller: ['$scope', function($scope) {
$scope.isVisible = true;
$scope.notifier = function(viewValue) {
return $scope.visiblePassword = viewValue;
};
$scope.$watch('visiblePassword', function(v){
$scope.password = v;
})
}]
}
})
.directive('inputChangeNotifier', function () {
return {
require: ['^displayablePassword', 'ngModel'],
link: function(scope, element, attrs, ctrls) {
var ngModel = ctrls[1];
ngModel.$parsers.unshift(function(inputVal) {
scope.notifier(inputVal);
return inputVal;
});
}
}
});
if (typeof module !== 'undefined' && module && module.exports) {
module.exports = 'mchambaud.angular-displayable-password';
}