This repository has been archived by the owner on Oct 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest.html
95 lines (89 loc) · 2.57 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
<html>
<head>
<script src="src/richtext.js"></script>
<script src="src/charrange.js"></script>
<script src="src/formatter.js"></script>
<script src="src/input.js"></script>
<script src="src/upgradedinput.js"></script>
<script>
function setupRichText(form, opt_upgrade) {
var inputs = form.getElementsByTagName('input');
for (var i = 0; i < inputs.length; i++) {
var input = inputs[i];
if (opt_upgrade) {
var rt = new richtext.UpgradedInput(input);
} else {
var rt = new richtext.Input();
rt.setText(input.value);
input.parentNode.replaceChild(rt.containerElement, input);
}
var formatter = new richtext.RegExpFormatter();
if (input.name == 'phone') {
formatter.addMatcher(/[0-9]+/, 'font-weight: bold');
formatter.addMatcher(/[-\(\) ]+/, 'color: #aaa');
formatter.addMatcher(/[^0-9-\(\) ]+/, 'color: red');
} else if (input.name == 'url') {
formatter.addMatcher(/[a-z]+:\/\/+/, 'color: #aaa');
} else if (input.name == 'tags') {
formatter.addMatcher(/("[^"]+"|\S+)/, '', 'tag');
}
rt.formatter = formatter;
rt.format();
}
}
window.onload = function() {
setupRichText(document.getElementById('replaced'));
setupRichText(document.getElementById('upgraded'), true);
}
</script>
<style>
.tag {
color: white;
background-color: #0088ef;
font-family: verdana;
padding: 2px 3px 2px 6px;
font-size: 12px;
font-weight: bold;
border-radius: 9px 2px 2px 9px;
-moz-border-radius: 9px 2px 2px 9px;
}
input, .richtext {
font-size: 12pt;
}
.richtext-container {
border: 1px inset #aaa;
padding: 3px;
}
.richtext:focus {
border: none;
outline: none;
}
form {
width: 300px;
float: left;
}
</style>
</head>
<body>
<form id="standard">
<h2>Standard inputs:</h2>
Phone number: <input name="phone" /><br />
Url: <input name="url" /><br />
Tags: <input name="tags" /><br />
</form>
<form id="replaced">
<h2>Replaced inputs:</h2>
Phone number: <input name="phone" /><br />
Url: <input name="url" /><br />
Tags: <input name="tags" /><br />
</form>
<form id="upgraded">
<h2>Upgraded inputs</h2>
Phone number: <input name="phone" /><br />
Url: <input name="url" /><br />
Tags: <input name="tags" /><br />
</form>
<br style="clear: both">
<!-- <a href="http://fettig.net/">A link</a> (Clicking this link and then hitting back should result in preserved form values)-->
</body>
</html>