forked from av01d/fontselect-jquery-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
249 lines (226 loc) · 6.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
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>jQuery Fontselect 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="jquery.fontselect.css">
<style>
body {
background-color: #fff;
color: #000;
font-family: "Lato", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}
button {
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;
}
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>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.8/highlight.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script src="jquery.fontselect.js"></script>
<script>
function applyFont(font) {
console.log('You selected font: ' + font);
// Replace + signs with spaces for css
font = font.replace(/\+/g, ' ');
// Split font into family and weight
font = font.split(':');
var fontFamily = font[0];
var fontWeight = font[1] || 400;
// Set selected font on paragraphs
$('p').css({fontFamily:"'"+fontFamily+"'", fontWeight:fontWeight});
}
$(function() {
// Highlight code samples:
hljs.configure({
tabReplace: ' ', // 3 spaces
});
$('pre code').each(function() {
hljs.highlightBlock(this);
});
});
</script>
</head>
<body>
<h1>jQuery Fontselect Plugin Example</h1>
<!-- Example 1 -->
<h2>Example 1: Fully default</h2>
<p>Default configuration. Dropdown shows a list of default system fonts, as well as
an extensive list of Google fonts.</p>
<div class="example">
<pre><code class="html">
<input id="font1" type="text">
<script>
$('#font1')
.fontselect()
.on('change', function() {
applyFont(this.value);
});
</script>
</code></pre>
<div>
<input id="font1" type="text">
<br>
<button type="button" onclick="$('#font1').trigger('setFont','Geo').trigger('change')">Select <i>Geo</i> font</button>
<button type="button" onclick="$('#font1').trigger('setFont',['Orbitron',900]).trigger('change')">Select <i>Oribtron 900</i> font</button>
<script>
$('#font1')
.fontselect()
.on('change', function() {
applyFont(this.value);
});
</script>
</div>
</div>
<!-- /Example 1 -->
<!-- Example 2 -->
<h2>Example 2: Default system fonts, custom Google fonts, no search box</h2>
<p>The dropdown shows the default list of system fonts. The list of Google fonts the user can choose from is customized. The search box is disabled and a placeholder text is set.</p>
<div class="example">
<pre><code class="html">
<input id="font2" type="text">
<script>
$('#font2').fontselect({
googleFonts: [
'Pacifico', 'Press+Start+2P',
'ZCOOL+KuaiLe', 'Gloria+Hallelujah',
'Changa:200', 'Changa:300',
'Changa:400', 'Changa:500'
],
placeholder: 'Pick a font from the list',
searchable: false
})
.on('change', function() {
applyFont(this.value);
});
</script>
</code></pre>
<div>
<input id="font2" type="text">
<script>
$('#font2').fontselect({
googleFonts: [
'Pacifico', 'Press+Start+2P',
'ZCOOL+KuaiLe', 'Gloria+Hallelujah',
'Changa:200', 'Changa:300',
'Changa:400', 'Changa:500'
],
placeholder: 'Pick a font from the list',
searchable: false
})
.on('change', function() {
applyFont(this.value);
});
</script>
</div>
</div>
<!-- Example 2 -->
<!-- Example 3 -->
<h2>Example 3: No system fonts, default Google fonts</h2>
<p>The dropdown only shows (the default list of) Google fonts. The search box is enabled, but has an overridden placeholder text. The lookahead is increased to 4.</p>
<div class="example">
<pre><code class="html">
<input id="font3" type="text" value="Caudex">
<script>
$('#font3').fontselect({
systemFonts: false,
placeholderSearch: 'Type to search...',
lookahead: 4
})
.on('change', function() {
applyFont(this.value);
});
</script>
</code></pre>
<div>
<input id="font3" type="text" value="Caudex">
<script>
$('#font3').fontselect({
systemFonts: false,
placeholderSearch: 'Type to search...',
lookahead: 4
})
.on('change', function() {
applyFont(this.value);
});
</script>
</div>
</div>
<!-- /Example 3 -->
<!-- Example 4 -->
<h2>Example 4: Custom system fonts, local .woff fonts, some Google fonts</h2>
<p>The dropdown shows just 3 system fonts, as well as a few custom (local) fonts. There are a few Google fonts to choose from as well.
<br>
The local font files have to be in Woff format (for best compatibility with as many
browsers as possible), 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>
In this specific example, there are 3 files in the <tt>htdocs/fonts</tt> folder:
</p>
<pre>
Action Man.woff
Bauer.woff
Bubble.woff
</pre>
<p>Make sure the font files are named the same as the font names you provide in the
<tt>localFonts</tt> array.
</p>
<div class="example">
<pre><code class="html">
<input id="font4" type="text" value="Bauer">
<script>
$('#font4').fontselect({
systemFonts: ['Arial','Times+New+Roman', 'Verdana'],
localFonts: ['Action+Man', 'Bauer', 'Bubble'],
googleFonts: ['Piedra', 'Questrial', 'Ribeye'],
localFontsUrl: 'fonts/' // End with a slash!
})
.on('change', function() {
applyFont(this.value);
});
</script>
</code></pre>
<div>
<input id="font4" type="text" value="Bauer">
<script>
$('#font4').fontselect({
systemFonts: ['Arial','Times+New+Roman', 'Verdana'],
localFonts: ['Action Man', 'Bauer', 'Bubble'],
googleFonts: ['Piedra', 'Questrial', 'Ribeye'],
localFontsUrl: 'fonts/' // End with a slash!
})
.on('change', function() {
applyFont(this.value);
});
</script>
</div>
</div>
<!-- /Example 4 -->
</body>
</html>