forked from gabriel/font-detect-js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
126 lines (110 loc) · 3.67 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
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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Font Detective</title>
<style>
p {
margin: 0;
}
body {
font-family: "Lucida Grande", Lucida, Helvetica, Arial, Verdana, sans-serif;
font-size: 12px;
background-color: white;
color: black;
margin: 0px auto;
text-align: center;
width: 900px;
padding-top: 10px;
max-width: 100%;
}
h1 {
margin-top: 30px;
margin-bottom: 30px;
}
#content {
text-align: left;
}
.sample-text {
font-size: 32px;
padding: 10px 0;
border: 1px solid #FFF;
}
.sample-text:hover {
border: 1px dashed #CCC;
}
.sample-text:focus {
border: 1px dashed #555;
}
.sample-text * {
font-family: inherit;
}
.sample-font-family {
position: relative;
top: -12px;
left: 0px;
width: 100%;
font-family: Monaco, sans-serif;
font-size: 12px;
}
@media print {
.no-print {
display: none;
}
}
</style>
<meta name="viewport" content="width=device-width" />
</head>
<body>
<a href="https://github.com/1j01/font-detective"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://github.com/camo/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a>
<h1><img src="img/font-detective.png" alt="Font Detective"/></h1>
<div id="content">
<div class="no-print">
<p id="status">Hello</p>
</div>
</div>
<script src="lib/jquery.min.js"></script>
<script src="lib/coffee-script.js"></script>
<script src="lib/font-detective.js"></script>
<script type="text/coffeescript">
statusError = (message)-> $("#status").text(message).css(color: "#a00")
statusText = (message)-> $("#status").text(message).css(color: "#000")
# Global uncaught error handling
$(window).on "error", (e)->
# This shouldn't be needed, but it's better to display any unforeseen errors
# rather than to leave some message like "Loading..." on display indefinitely
err = e.originalEvent
statusError err.message
statusText "Loading..."
FontDetective.all (fonts)->
statusText "Detected #{fonts.length} fonts"
sampleText = "
Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
"
for font in fonts
$("<p class='sample-text'>")
.appendTo "#content"
.text sampleText
.css fontFamily: font
.attr contentEditable: yes
.on "keydown keypress keyup input paste", (e)->
$sampleText = $(@)
# If you've pasted rich text, make sure there's no font-family styles
# (That would kind of ruin the demo, wouldn't it?)
$sampleText.find("*").css(fontFamily: "")
# Store the position of the sample text on the screen
clientTop = $sampleText[0].getBoundingClientRect().top
# Synchronize this html to other elements
# (careful not to set the html of this element,
# as that can mess up the cursor/caret position)
$(".sample-text").not($sampleText).html $sampleText.html()
# Scroll the document to account for changes in the sample text's position
# due to updating the content of any .sample-text elements above
$(window).scrollTop $sampleText.position().top - clientTop
$("<div class='sample-font-family'>")
.appendTo "#content"
.text font.name
</script>
</body>
</html>