-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
108 lines (90 loc) · 2.68 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>React UiPass</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.3/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.3/JSXTransformer.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<style>
.ui-pass input[type="password"] {
display: none;
}
</style>
</head>
<body>
<h1>React UiPass</h1>
<div id="content"></div>
<script type="text/jsx">
var UiPass = React.createClass({
getInitialState: function () {
return {
pass: null,
uipass: null,
sent: false
};
},
_onSubmit: function (ev) {
ev.preventDefault();
this.setState({
sent: true
});
},
_onChange: function (ev) {
this.setState({
pass: this._getPassword(ev.target.value),
uipass: this._getUiPass(ev.target.value)
});
},
_getPassword: function (value) {
var char = value.charAt(value.length-1)
, newState = this.state.pass + char;
return (this.state.pass) ? newState : char;
},
_getUiPass: function (value) {
var maskPass = [];
if (value.length > 1) {
for (var i=0, len=value.length; i < len-1; i++) {
maskPass.push('-');
}
}
maskPass.push(value.charAt(value.length-1));
setTimeout(function () {
// maskPass[maskPass.length-1] = '-';
this._changeLastChar();
}.bind(this), 300);
return maskPass.join('');
},
_changeLastChar: function () {
var value = this.state.uipass.slice(0, -1) + '-';
this.setState({
uipass: value
});
},
render: function() {
return (
<div>
<form onSubmit={this._onSubmit}>
<div className="ui-pass">
<input type="password" value={this.state.pass} />
<input type="text" value={this.state.uipass} onChange={this._onChange} />
</div>
<input type="submit" />
{
this.state.sent && <p>
sent password:
<strong> {this.state.pass}</strong>
</p>
}
</form>
</div>
);
}
});
React.render(
<UiPass />,
document.getElementById('content')
);
</script>
</body>
</html>