-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdemo.html
More file actions
62 lines (62 loc) · 2.34 KB
/
demo.html
File metadata and controls
62 lines (62 loc) · 2.34 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>trimMiddle() test page</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 1em;
}
output {
line-height: 1.6;
}
form {
background-color: #eee;
padding: 1em 2em;
margin-bottom: 1em;
border:1px solid #ccc;
border-radius: 5px;
}
</style>
</head>
<body>
<h1>trimMiddle() test page</h1>
<form>
<label for="length">Length</label>
<input type="range" id="length" min=5 max=50 value="16" placeholder="Enter a number">
<label for="replacechar">Replacement char</label>
<input type="text" id="replacechar" size="3" placeholder="Enter a string" value="…">
</form>
<pre>trimMiddle("This is a long string that will be trimmed", <span id="ln"></span>, "<span id="rc"></span>");</pre>
<output id="output"></output>
<script src="clientside.js"></script>
<script>
const demosentences = [
"This is a long string that will be trimmed",
"This is a short string",
"This is a medium string that will be trimmed",
"This 🇺🇳 is 🤡 🐥 a string 🥰 🧑🧑🧒🧒 with compound emoji 😊 ",
"This is a string with a compound emoji 🧑🧑🧒🧒",
"This is a string with a compound emoji 🧑🧑🧒🧒 and a flag 🇺🇳",
"Dies is ein öü deutscher String mit Umlauten äß"
];
const render = () => {
let out = '';
let length = document.querySelector('#length').value;
let replacechar = document.querySelector('#replacechar').value;
document.querySelector('#ln').innerText = length;
document.querySelector('#rc').innerText = replacechar;
demosentences.forEach(sentence => {
out += sentence + '\n';
out += trimMiddle(sentence, +length, replacechar);
out += "\n";
});
document.querySelector("#output").innerText = out;
}
render();
document.querySelector('form').addEventListener('change', render);
</script>
</body>
</html>