-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathindex.html
456 lines (413 loc) · 12.4 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
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>jQuery Fontpicker Plugin Example</title>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.8/styles/github.min.css">
<link rel="stylesheet" type="text/css" href="dist/jquery.fontpicker.css">
<style>
body {
background-color: #fff;
color: #000;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}
p {
line-height: 1.4em;
}
a {
color: #39c;
text-decoration:none;
}
a:hover {
color: #069;
text-decoration: underline;
}
.btn {
background-color: #4caf50;
color: #fff;
padding: 5px 10px;
text-align: center;
display: inline-block;
font-size: 16px;
border-radius: 5px;
border: 1px solid #080;
margin: 2px 0;
cursor: pointer;
}
.btn-link {
font-weight: 400;
color: #00bc8c;
text-decoration: none;
border: none;
padding: 0;
background: none;
color: #00f;
font-size: 14px;
}
tt {
background-color: #eff0f1;
padding: 4px;
}
.example > div {
margin-top: 15px;
}
@media (min-width: 768px) {
.example {
display: flex;
}
.example > div, .example > pre {
flex: 1;
margin: 0 10px 0 0;
}
}
</style>
<!-- For Internet Explorer 11: include intersection observer polyfill
<script src="https://cdn.jsdelivr.net/npm/intersection-observer/intersection-observer.js"></script>
-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.8/highlight.min.js"></script>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="dist/jquery.fontpicker.js"></script>
<script>
function applyFont(element, fontSpec) {
if (!fontSpec) {
// Font was cleared
console.log('You cleared font');
$(element).css({
fontFamily: 'inherit',
fontWeight: 'normal',
fontStyle: 'normal'
});
return;
}
console.log('You selected font: ' + fontSpec);
// Split font into family and weight/style
var tmp = fontSpec.split(':'),
family = tmp[0],
variant = tmp[1] || '400',
weight = parseInt(variant,10),
italic = /i$/.test(variant);
// Apply selected font to element
$(element).css({
fontFamily: "'" + family + "'",
fontWeight: weight,
fontStyle: italic ? 'italic' : 'normal'
});
}
$(function() {
// Highlight code samples:
hljs.configure({
tabReplace: ' ', // 3 spaces
});
$('pre code').each(function() {
hljs.highlightBlock(this);
});
});
</script>
</head>
<body>
<h1 style="margin:0">jQuery Fontpicker Plugin Example</h1>
<p>
A component to quickly choose fonts from Google Web Fonts, custom fonts you (the web developer) provide, as well as system fonts.<br>
<svg style="vertical-align: bottom" version="1.1" width="20" height="20" viewBox="0 0 16 16" class="octicon octicon-mark-github" aria-hidden="true"><path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"></path></svg>
<a href="https://github.com/av01d/fontpicker-jquery-plugin">View project on GitHub</a>.
</p>
<!-- Example 1 -->
<h2>Example 1: Fully default</h2>
<p id="sample1">
Default configuration. Dropdown shows a list of default system fonts, as well as all available Google fonts.
Users can select both a font-family <i>and</i> a font-variant (font weight- and style).
</p>
<div class="example">
<pre><code class="html">
<input id="font1" type="text">
<script>
$('#font1')
.fontpicker()
.on('change', function() {
applyFont('#sample1', this.value);
});
</script>
</code></pre>
<div>
<input id="font1" type="text">
<br>
<button class="btn" type="button" onclick="$('#font1').val('Geo:400').trigger('change')">Select <i>Geo 400</i> font</button>
<button class="btn" type="button" onclick="$('#font1').val('Open Sans:800').trigger('change')">Select <i>Opens Sans 800</i> font</button>
<br>
<button class="btn" type="button" onclick="$('#font1').val('Tahoma').trigger('change')">Select <i>Tahoma</i> font</button>
<button class="btn" type="button" onclick="$('#font1').val('').trigger('change')">Clear</button>
<br>
API: <button class="btn btn-link" onclick="$('#font1').fontpicker('show')">Show</button> -
<button class="btn btn-link" onclick="$('#font1').fontpicker('destroy')">Destroy</button>
<script>
$('#font1')
.fontpicker()
.on('change', function() {
applyFont('#sample1', this.value);
});
</script>
</div>
</div>
<!-- /Example 1 -->
<!-- Example 2 -->
<h2>Example 2: Default local fonts, custom Google fonts, disabled variant-selection</h2>
<p id="sample2">
The dropdown shows the default list of local fonts. The list of Google fonts the user can choose from is customized.
Users can only select a font-family, font-variant selection is disabled (<tt>variants: false</tt>).
<br>
This Fontpicker will not remember last picked fonts (<tt>nrRecents: 0</tt>).
<br>
This Fontpicker allows the user to clear/deselect a chosen font (<tt>showClear: true</tt>).
</p>
<div class="example">
<pre><code class="html">
<input id="font2" type="text" value="Indie Flower">
<script>
$('#font2').fontpicker({
variants: false,
nrRecents: 0,
showClear: true,
googleFonts: [
'Abel', 'Advent Pro', 'Changa', 'Eczar', 'Gloria Hallelujah',
'Indie Flower', 'Press Start 2P', 'Slackey', 'Yeon Sung'
],
localFonts: false
})
.on('change', function() {
applyFont('#sample2', this.value);
});
</script>
</code></pre>
<div>
<input id="font2" type="text" value="Indie Flower">
<script>
$('#font2').fontpicker({
variants: false,
nrRecents: 0,
showClear: true,
googleFonts: [
'Abel', 'Advent Pro', 'Changa', 'Eczar', 'Gloria Hallelujah',
'Indie Flower', 'Press Start 2P', 'Slackey', 'Yeon Sung'
],
localFonts: false
})
.on('change', function() {
applyFont('#sample2', this.value);
});
</script>
</div>
</div>
<!-- /Example 2 -->
<!-- Example 3 -->
<h2>Example 3: Custom local fonts, no Google fonts</h2>
<p id="sample3">
The dropdown shows a list of system fonts (Arial, Georgia, Times New Roman and Verdana), as well as three custom fonts (Action Man, Bauer, Bubble).<br>
Google fonts are disabled (<tt>googleFonts: false</tt>).<br>
The local font files have to be in TTF, Woff, Woff2 or OTF format, and they should all be put in a single folder, under the
document root folder of your site. Something like <tt>/fonts</tt> makes sense. Provide the path to this folder as the <tt>localFontsUrl</tt> configuration parameter.<br>
All fonts should be in the same format (woff, woff2, ttf, otf). Define your format via the <tt>localFontsType</tt> parameter.
<br>
In this example, there are 3 files in the <tt>htdocs/fonts</tt> folder: <tt>Action Man.woff, Bauer.woff, Bubble.woff</tt>.
<br>
Make sure the font files are named the same as the font names you provide in the <tt>localFonts</tt> object.
</p>
<div class="example">
<pre><code class="html">
<input id="font3" type="text">
<script>
var localFonts = {
"Arial": {
"category": "sans-serif",
"variants": "400,400i,600,600i"
},
"Georgia": {
"category": "serif",
"variants": "400,400i,600,600i"
},
"Times New Roman": {
"category": "serif",
"variants": "400,400i,600,600i"
},
"Verdana": {
"category": "sans-serif",
"variants": "400,400i,600,600i",
},
"Action Man": {},
"Bauer": {
"category": "display",
"variants": "400,400i,600,600i",
"subsets": "latin-ext,latin"
},
"Bubble": {
"category": "display",
"variants": "400,400i,600,600i",
"subsets": "latin-ext,latin"
}
};
$('#font3').fontpicker({
localFontsUrl: 'fonts/', // End with a slash!
localFonts: localFonts,
localFontsType: 'woff', // Either 'ttf', 'woff', 'woff2' or 'otf'
googleFonts: false
})
.on('change', function() {
applyFont('#sample3', this.value);
});
</script>
</code></pre>
<div>
<input id="font3" type="text">
<script>
var localFonts = {
"Arial": {
"category": "sans-serif",
"variants": "400,400i,600,600i"
},
"Georgia": {
"category": "serif",
"variants": "400,400i,600,600i"
},
"Times New Roman": {
"category": "serif",
"variants": "400,400i,600,600i"
},
"Verdana": {
"category": "sans-serif",
"variants": "400,400i,600,600i",
},
"Action Man": {},
"Bauer": {
"category": "display",
"variants": "400,400i,600,600i",
"subsets": "latin-ext,latin"
},
"Bubble": {
"category": "display",
"variants": "400,400i,600,600i",
"subsets": "latin-ext,latin"
}
};
$('#font3').fontpicker({
debug: true,
localFontsUrl: 'fonts/', // End with a slash!
localFontsType: 'woff',
localFonts: localFonts,
googleFonts: false,
})
.on('change', function() {
applyFont('#sample3', this.value);
});
</script>
</div>
</div>
<!-- /Example 3 -->
<!-- Example 4 -->
<h2>Example 4: Some local fonts, custom Google fonts, onSelect callback</h2>
<p id="sample4">
The dropdown shows a mix of local, custom and Google fonts.
Instead of <tt>on('change', fn)</tt>, the <tt>onSelect</tt> callback is used to be
notified about the font the user picked. The <tt>onSelect</tt> option is called
with a single argument: an object containing <tt>fontType</tt> (<tt>local</tt> or <tt>google</tt>), <tt>fontFamily</tt>,
<tt>fontStyle</tt>, <tt>fontWeight</tt> and <tt>fontSpec</tt> members.<br>
<tt>obj.fontSpec</tt> contains the same value that <tt>on('change', fn)</tt>
would be called with.
</p>
<div class="example">
<pre><code class="html">
<input id="font4" type="text" value="Cookie">
<script>
var localFonts = {
"Arial": {
"category": "sans-serif",
"variants": "400,400i,600,600i"
},
"Georgia": {
"category": "serif",
"variants": "400,400i,600,600i"
},
"Times New Roman": {
"category": "serif",
"variants": "400,400i,600,600i"
},
"Verdana": {
"category": "sans-serif",
"variants": "400,400i,600,600i",
},
"Action Man": {},
"Bauer": {
"category": "display",
"variants": "400,400i,600,600i",
"subsets": "latin-ext,latin"
},
"Bubble": {
"category": "display",
"variants": "400,400i,600,600i",
"subsets": "latin-ext,latin"
}
};
<script>
$('#font4').fontpicker({
localFontsUrl: 'fonts/',
localFonts: localFonts,
googleFonts: [
'Mali', 'Aladin', 'Alex Brush', 'Amita', 'Annie Use Your Telescope', 'Architects Daughter',
'Bad Script', 'Bilbo', 'Bonbon', 'Caveat', 'Chilanka', 'Cookie', 'Crafty Girls'
],
onSelect: function(obj) {
console.log('onSelect', obj);
applyFont('#sample4', obj.fontSpec);
}
});
</script>
</code></pre>
<div>
<input id="font4" type="text" value="Cookie">
<script>
var localFonts = {
"Arial": {
"category": "sans-serif",
"variants": "400,400i,600,600i"
},
"Georgia": {
"category": "serif",
"variants": "400,400i,600,600i"
},
"Times New Roman": {
"category": "serif",
"variants": "400,400i,600,600i"
},
"Verdana": {
"category": "sans-serif",
"variants": "400,400i,600,600i",
},
"Action Man": {},
"Bauer": {
"category": "display",
"variants": "400,400i,600,600i",
"subsets": "latin-ext,latin"
},
"Bubble": {
"category": "display",
"variants": "400,400i,600,600i",
"subsets": "latin-ext,latin"
}
};
$('#font4').fontpicker({
localFontsUrl: 'fonts/',
localFonts: localFonts,
googleFonts: [
'Mali', 'Aladin', 'Alex Brush', 'Amita', 'Annie Use Your Telescope', 'Architects Daughter',
'Bad Script', 'Bilbo', 'Bonbon', 'Caveat', 'Chilanka', 'Cookie', 'Crafty Girls'
],
onSelect: function(obj) {
console.log('onSelect', obj);
applyFont('#sample4', obj.fontSpec);
}
});
</script>
</div>
</div>
<!-- /Example 4 -->
</body>
</html>