-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.html
143 lines (139 loc) · 3.98 KB
/
test.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>Balzac.js JavaScript library – Web browser tests</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/necolas/normalize.css/normalize.min.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/visicode/formalize.css/formalize.min.css" />
<style>
:root {
--input-invalid-color: red;
}
form {
width: 550px;
}
fieldset {
margin: 25px;
padding: 25px;
}
label {
margin: 3px 0;
display: inline-block;
}
label > span:first-child {
width: 150px;
display: inline-block;
text-align: right;
margin-right: 6px;
}
label > span:first-child::after {
content: ":";
}
label > span:first-child:has(+ :required)::before {
content: "* ";
}
input:not([name="age"]), textarea {
width: 206px;
}
input[type="button"], input[type="submit"], input[type="reset"] {
width: 146px;
}
output {
margin-left: 6px;
}
meter {
width: 206px;
margin-left: 160px;
}
fieldset .user-invalid { /* replaces :user-invalid */
border-color: var(--input-invalid-color);
}
</style>
<script defer type="text/javascript" src="https://polyfill.io/v3/polyfill.min.js"></script>
<script defer type="module" src="https://cdn.jsdelivr.net/gh/visicode/Balzac.js/balzac.js"></script>
</head>
<body>
<form>
<fieldset>
<legend>Enter your details:</legend>
<label>
<span>Name</span>
<input type="text" name="name" minlength="3" maxlength="50" case="title" required />
</label>
<label>
<span>Age</span>
<input type="number" name="age" min="12" max="120" required />
</label>
<label>
<span>E-mail address</span>
<input type="email" name="email" required />
</label>
<label>
<span>Phone number</span>
<input type="tel" name="phone" required />
</label>
<label>
<span>Passport number</span>
<input type="passport" name="passport" required />
</label>
<label>
<span>IBAN number</span>
<input type="iban" name="iban" required />
</label>
<label>
<span>Postal code</span>
<input type="postcode" name="postcode" required />
</label>
<label>
<span>Picture</span>
<input type="file" name="file" accept="image/*" oninput="checkPicture(this)" />
<output for="file"></output>
</label>
<label>
<span>Password</span>
<input type="password" name="pwd" oninput="checkPassword(this)" required />
<output for="pwd"></output>
</label>
<label>
<span>Message</span>
<textarea name="msg" maxlength="140" rows="5" case="sentence"></textarea>
</label>
<hr />
<div id="infos"></div>
<hr />
<input type="button" value="Load" onclick="doLoad()" />
<input type="submit" />
<input type="reset" />
</fieldset>
</form>
<script type="text/javascript">
function checkPicture(input) {
input.getOutputs()[0].innerText = input.files.length
? Math.roundTo(input.files[0].size / File.SIZE.MEGABYTE, 2) + ' MB'
: null;
}
const strengthMessages = ['Empty', 'Too short', 'Weak', 'Medium', 'Good', 'Strong'];
function checkPassword(input) {
const meter = document.createElement('meter');
meter.min = WebUtility.PASSWORD_STRENGTH.EMPTY;
meter.optimum = meter.max = WebUtility.PASSWORD_STRENGTH.STRONG;
meter.low = WebUtility.PASSWORD_STRENGTH.GOOD;
meter.high = meter.low + .1; // GOOD excluded
meter.value = WebUtility.getPasswordStrength(input.value);
input.getOutputs()[0].replaceChildren(strengthMessages[meter.value], meter);
}
function doLoad() {
Fetch.get('balzac.js')
.then(response => response.ok && response.text())
.then(text => infos.innerText = text.firstLines(1));
}
(callback => document.readyState === 'loading'
? document.addEventListener('DOMContentLoaded', callback)
: setTimeout(callback, 0)
)(_ =>
infos.innerText = WebUtility.toPlainText(document.body.innerHTML).truncate(200).toSentenceCase()
);
</script>
</body>
</html>