forked from malarkey/hardboiled-type-design
/
responsive-type.html
233 lines (210 loc) · 9.68 KB
/
responsive-type.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<!doctype html>
<!--
320 and Up boilerplate extension
Author: Andy Clarke (http://about.me/malarkey)
Author: Keith Clark (http://twitter.com/keithclarkcouk)
URL: http://stuffandnonsense.co.uk/projects/320andup/
License: http://creativecommons.org/licenses/MIT/
Dynamicness: Conor MacNeill (http://twitter.com/thefella)
-->
<!--[if IEMobile 7]><html class="no-js iem7 oldie"><![endif]-->
<!--[if lt IE 7]><html class="no-js ie6 oldie" lang="en"><![endif]-->
<!--[if (IE 7)&!(IEMobile)]><html class="no-js ie7 oldie" lang="en"><![endif]-->
<!--[if (IE 8)&!(IEMobile)]><html class="no-js ie8 oldie" lang="en"><![endif]-->
<!--[if gt IE 8]><!--><html class="no-js" lang="en"><!--<![endif]-->
<!--[if (gte IE 9)|(gt IEMobile 7)]><!--><html class="no-js" lang="en"><!--<![endif]-->
<head>
<meta charset="utf-8">
<title>Type readability reference | Fashionably Flexible Responsive Web Design</title>
<meta name="description" content="">
<meta name="author" content="">
<!-- http://t.co/dKP3o1e -->
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
html,body{margin:0;padding:0;}
h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,cite,code,del,dfn,em,img,q,s,samp,small,strike,strong,sub,sup,tt,var,dd,dl,dt,li,ol,ul,fieldset,form,label,legend,button,table,caption,tbody,tfoot,thead,tr,th,td{margin:0;padding:0;border:0;font-weight:normal;font-style:normal;font-size:100%;line-height:1;font-family:inherit;}
article,aside,details,figcaption,figure,footer,header,hgroup,nav,section{display:block;}
audio[controls],canvas,video{display:inline-block;*display:inline;*zoom:1;}
html{overflow-y:scroll;background:#fff;font-size:62.5%;}
body { padding : 22px; font-size:16px;font-size:1.6rem;font-family:Georgia,"Times New Roman",Times,serif;color:#282828;background-color:transparent; }
h2 { margin-bottom : .75em; font-weight : bold; font-size : 36px; }
div { margin-bottom : 1.5em; padding-bottom : 1.5em; border-bottom : 1px solid #ccc;
}
p { margin-bottom : 22px; line-height : 1.5; }
h3 { margin-bottom : 22px; font-weight : bold; }
p.caption { display : inline-block; padding : 6px; font-size : 12px; text-transform : uppercase; background-color : #ccc; }
article { overflow : hidden; }
span.font-name { display : block; font-size : 14px; color : #ccc; padding-bottom : 0.25em; }
@media only screen and (min-width: 480px) {
article { float : left; width : 100%; }
.many article div, .many article h2 { margin-left : 10%; margin-right : 10%; }
}
</style>
</head>
<body>
<script>
// Get user fonts or default to Georgia
//var fonts = getParameterByName("font") ? getParameterByName("font") : 'Impact';
var fonts = getUrlVars()["font"] ? getUrlVars()["font"] : 'Georgia';
fonts = fonts.replace(/(^,)|(,$)/g, "");
fonts = unescape(fonts);
fonts = fonts.split(",");
var count = fonts.length;
// Define font sizes
var normal = ['12','14','16'];
var heading = ['16','18','21','24','36','48'];
var small = ['10','11','12'];
// Work out the width
var width = Math.round((100 / count)*1000)/1000;
// See if Typekit is needed
var typekit = getParameterByName("typekit") ? getParameterByName("typekit") : null;
if (typekit != null) {
var typekitlink = document.createElement("script");
typekitlink.setAttribute("src", "http://use.typekit.com/"+typekit+".js");
document.getElementsByTagName("head")[0].appendChild(typekitlink);
var typekitlink2 = document.createElement("script");
typekitlink2.innerHTML = 'try{Typekit.load();}catch(e){}';
document.getElementsByTagName("head")[0].appendChild(typekitlink2);
}
// See if you'd rather use Google Web Fonts
var google = getParameterByName("google") ? getParameterByName("google") : null;
if (google != null) {
google = google.replace(" ", "+");
var googlelink = document.createElement("link");
googlelink.setAttribute("rel", "stylesheet");
googlelink.setAttribute("href", "//fonts.googleapis.com/css?family="+google);
document.getElementsByTagName("head")[0].appendChild(googlelink);
}
// Get custom sizes
var sizes = getParameterByName("sizes") ? getParameterByName("sizes") : null;
if (sizes != null)
var custom_sizes = sizes.split(",");
// Build page
var page = '';
for (var font in fonts) {
page += '<article id="'+fonts[font].replace(/\s/g, "").toLowerCase()+'" style="width:'+width+'%; font-family:\''+fonts[font]+'\';">';
if (sizes != null) {
page += '<h2><span class="font-name">'+fonts[font]+'</span> Custom size reference</h2>';
for (var size in custom_sizes) {
page += '<div><p style="font-size:'+custom_sizes[size]+'px">When a new medium borrows from an existing one, some of what it borrows makes sense, but much of the borrowing is thoughtless, “ritual”, and often constrains the new medium. Over time, the new medium develops its own conventions, throwing off existing conventions that don’t make sense.</p><p class="caption">'+custom_sizes[size]+'px</p></div>';
}
}
page += '<h2><span class="font-name">'+fonts[font]+'</span> Type readability reference</h2>';
for (var size in normal) {
page += '<div><p style="font-size:'+normal[size]+'px">When a new medium borrows from an existing one, some of what it borrows makes sense, but much of the borrowing is thoughtless, “ritual”, and often constrains the new medium. Over time, the new medium develops its own conventions, throwing off existing conventions that don’t make sense.</p><p class="caption">'+normal[size]+'px</p></div>';
}
page += '<h2><span class="font-name">'+fonts[font]+'</span> Heading word wrap reference</h2>';
for (var size in heading) {
page += '<div><h3 style="font-size:'+heading[size]+'px">When a new medium borrows from an existing one</h3><p class="caption">'+heading[size]+'px</p></div>';
}
page += '<h2><span class="font-name">'+fonts[font]+'</span> Small type size reference</h2>';
for (var size in small) {
page += '<div><p style="font-size:'+small[size]+'px">Small type size reference</p><p class="caption">'+small[size]+'px</p></div>';
}
page += '</article>';
}
document.body.innerHTML = page;
if (count > 0)
document.getElementsByTagName('body')[0].className += 'many';
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.search);
if(results == null)
return null;
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
function getUrlVars()
{
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
</script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
/**
* JavaScript code to detect available availability of a
* particular font in a browser using JavaScript and CSS.
*
* Author : Lalit Patel
* Website: http://www.lalit.org/lab/jsoncookies
* License: Apache Software License 2.0
* http://www.apache.org/licenses/LICENSE-2.0
* Version: 0.15 (21 Sep 2009)
* Changed comparision font to default from sans-default-default,
* as in FF3.0 font of child element didn't fallback
* to parent element if the font is missing.
* Version: 0.2 (04 Mar 2012)
* Comparing font against all the 3 generic font families ie,
* 'monospace', 'sans-serif' and 'sans'. If it doesn't match all 3
* then that font is 100% not available in the system
*/
/**
* Usage: d = new Detector();
* d.detect('font name');
*/
var Detector = function(){
// a font will be compared against all the three default fonts.
// and if it doesn't match all 3 then that font is not available.
var baseFonts = ['monospace','sans-serif','sans'];
//we use m or w because these two characters take up the maximum width.
// And we use a LLi so that the same matching fonts can get separated
var testString = "mmmmmmmmmmlli";
//we test using 72px font size, we may use any size. I guess larger the better.
var testSize = '72px';
var h = document.getElementsByTagName("body")[0];
// create a SPAN in the document to get the width of the text we use to test
var s = document.createElement("span");
s.style.fontSize = testSize;
s.innerHTML = testString;
var defaultWidth = {};
var defaultHeight = {};
for(var index in baseFonts) {
//get the default width for the three base fonts
s.style.fontFamily = baseFonts[index];
h.appendChild(s);
defaultWidth[baseFonts[index]] = s.offsetWidth; //width for the default font
defaultHeight[baseFonts[index]] = s.offsetHeight; //height for the defualt font
h.removeChild(s);
}
function detect(font) {
var detected = false;
for(var index in baseFonts) {
s.style.fontFamily = font + ',' + baseFonts[index]; // name of the font along with the base font for fallback.
h.appendChild(s);
var matched = (s.offsetWidth != defaultWidth[baseFonts[index]] || s.offsetHeight != defaultHeight[baseFonts[index]]);
h.removeChild(s);
detected = detected || matched;
}
return detected;
}
this.detect = detect;
};
var detective = new Detector();
for (var font in fonts) {
var colour,title;
if (detective.detect(fonts[font]) === true) {
colour = '#6fbf4d';
title = "Your font should be displayed!";
} else {
colour = '#e06666';
title = "Dammit, your font is missing.";
}
var box = '<span style="display:inline-block; width:9px; height:9px; margin-right:6px; background-color:'+colour+';" title="'+title+'"></span>';
var element = $("#"+fonts[font].replace(/\s/g, "").toLowerCase()+" h2 span");
element.prepend(box);
}
</script>
</body>
</html>