-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
60 lines (56 loc) · 2.49 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
<html>
<head>
<meta charset="UTF-8">
<title>String fit dimension</title>
<style type="text/css">
.container, #values{
width: 500px;
height: 280px;
margin: 3em auto;
}
#values {
font-size: 16px;
line-height: 1.5em;
}
.element {
font-size: 15px;
margin-top: 10px;
line-height: 20px;
padding-bottom: 10px;
}
.different {
font-weight: bold;
text-transform: uppercase;
}
</style>
</head>
<body>
<article class="container">
<div class="element">But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or <span class="different">avoids pleasure itself</span>, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, <span class="different">because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure</different>.</div>
</article>
<div id="values">
</div>
<script type="text/javascript" src="source/textmeasure.js"></script>
<script type="text/javascript">
(function(d){
var html = document.querySelector('.element').innerHTML;
var string = document.querySelector('.element').textContent;
var getDimension = textMeasure.getDimension;
var t0 = performance.now();
var dim = getDimension(html, 500, 280, 'element', 'container');
var t1 = performance.now();
console.log("getDimension took", (t1 - t0), "milliseconds");
var longestWord = textMeasure.longestWord(string.trim(), 'element', 'container');
var output = document.getElementById('values');
var html = '<div>width: ' + dim.width + '</div>';;
html += '<div>height: ' + dim.height + '</div>';
html += '<div>overflow: ' + dim.overflow + '</div>';
html += '<div>milliseconds: ' + (t1 - t0) + 'ms</div>';
html += '<div> </div>';
html += '<div>longest word: ' + longestWord.word + '</div>';
html += '<div>Word Width: ' + longestWord.width + '</div>';
output.innerHTML = html;
}(document));
</script>
</body>
</html>