-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinput-password.js
148 lines (132 loc) · 2.8 KB
/
input-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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
(function() {
/**
* input-password is an unstyled password field where user can show and hide the input value.
*
* Example:
*
* <input-password visible toggleText="Show/Hide"></input-password>
*
* @element input-password
* @homepage http://jorgecasar.github.io/input-password/
* @demo
*/
Polymer({
is: 'input-password',
behaviors: [
Polymer.IronFormElementBehavior,
Polymer.PaperInputBehavior,
Polymer.IronControlState
],
/**
* Fired when the value of is shown.
* @event showValue
*/
/**
* Fired when the value of is hidden.
* @event hideValue
*/
properties: {
/**
* If true, the user can show the password.
*
* @attribute value
* @type boolean
* @default false
*/
visible: {
type: Boolean,
value: false
},
/**
* The button text to show and hide the input value.
*
* @attribute value
* @type string
* @default 'Toggle'
*/
toggleText: {
type: String,
value: 'Toggle'
},
/**
* This css class will be included
* when the password is visible.
*
* @attribute value
* @type string
* @default 'visible'
*/
visibleClass: {
type: String,
value: 'visible'
}
},
observers: [
'_visibleChanged(visible)',
'_toggleTextChanged(toggleText)'
],
listeners: {
'visibilityButton.tap': 'toggle'
},
attached: function() {
this._toggleTextChanged();
this._visibleChanged();
},
/**
* Observer for visible property
*/
_visibleChanged: function() {
this[this.visible ? '_showValue' : '_hideValue']();
},
/**
* Observer for toggle-text property
*/
_toggleTextChanged: function() {
this._showText = this.showText;
this._hideText = this.hideText;
},
/**
* Get the text of the button for show action
*/
get showText() {
return this.toggleText.split('/')[0];
},
/**
* Get the text of the button for hide action
*/
get hideText() {
return this.toggleText.split('/')[1] || this._showText;
},
/**
* Action to show the input value
*/
_showValue: function() {
if( this.visible ) { this.visible = true; }
this.visible = true;
this.$.input.type = 'text';
if(this.visibleClass) {
this.toggleClass(this.visibleClass, this.visible);
}
this.$.visibilityButton.innerHTML = this._hideText;
this.fire('showValue');
},
/**
* Action to hide the input value
*/
_hideValue: function() {
if( this.visible ) { this.visible = false; }
this.$.input.type = 'password';
if(this.visibleClass) {
this.toggleClass(this.visibleClass, this.visible);
}
this.$.visibilityButton.innerHTML = this._showText;
this.fire('hideValue');
},
/**
* Toggle the visibily of the input value
*/
toggle: function() {
this.visible = !this.visible;
}
});
})();