-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.html
101 lines (100 loc) · 2.95 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
<!DOCTYPE html>
<html>
<head>
<title>simplePinyin test</title>
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.0.0-alpha.5/css/bootstrap.min.css" />
<style>
h2 {
margin: 15px;
}
textarea, .card {
height: 100%;
width: 100%;
}
.pull-right {
float: right;
}
.card-block {
overflow: auto;
}
@media (min-width: 544px) {
.container-fluid {
height: 100%;
}
#editor-container, #pinyin-container {
height: 90vh;
}
}
</style>
</head>
<body>
<div class="container-fluid">
<h2>simplePinyin 测试</h2>
<div id="editor-container" class="col-xs-12 col-sm-6">
<div class="card">
<div class="card-header">
编辑器
<label class="pull-right">
匹配所有字符
<select id="matchFullText">
<option value="">跳过非拼音</option>
<option value="blank">非拼音输出为空字符串</option>
<option value="original">非拼音输出为原始字符</option>
</select>
</label>
</div>
<div class="card-block">
<div id="editor" class="form-group" contenteditable="true">
妈妈跟我说再也不用担心我的 Chinese 不知道怎么念了。
</div>
</div>
</div>
</div>
<div class="col-xs-12 col-sm-6">
<div id="pinyin-container">
<div class="card">
<div class="card-header">
完整翻译
<span id="time" class="pull-right"></span>
</div>
<div class="card-block">
<div id="pinyin" class="form-group"></div>
</div>
</div>
</div>
</div>
</div>
<script src="./dist/index.umd.js"></script>
<script>
var $editor = document.getElementById('editor'),
$matchFullText = document.getElementById('matchFullText'),
$pinyin = document.getElementById('pinyin'),
$time = document.getElementById('time'),
options = { matchFullText: '' },
timer,
text,
now,
time,
pinyin;
var translate = function() {
text = $editor.innerText;
now = performance.now();
pinyin = simplePinyin.default(text, options);
time = (performance.now()) - now;
$time.innerText = '花费时间:' + time + '毫秒。'
console.log('output', JSON.stringify(pinyin));
$pinyin.innerText = pinyin.join(' ');
}
$editor.focus();
$editor.addEventListener('keyup', function() {
clearTimeout(timer);
timer = setTimeout(translate, 300);
});
$matchFullText.addEventListener('change', function() {
options.matchFullText = $matchFullText.value;
translate();
})
translate();
</script>
</body>
</html>